简体   繁体   中英

How to change whole Datatable background color using jQuery not depending on any column or row value

Simple but I am not being able to change this table background color. I am binding datatable using jQuery ajax call. Any help will be good.

$.ajax({
                type: "POST",
                datatype: "json",
                data: { Alert: true },
                url: '/GunTracking/GetGunAlertsList',
                success: function (data) {
                    debugger;
                    var table = $('#GunTracking-detail-datatable').DataTable();
                    table.clear().draw();
                    for (var i = 0; i < data.length; i++) {
                        var id = data[i].GunId;                         
                        var remarks = '<button type="button" title="Remarks" class="btn btn-xs  btn-default" data-toggle="modal" data-target="#gun-tracking-remark-popup"  onclick="javascript: OpenRemarks ('+id +')" ><i class="fa fa-info-circle"></i></button>';
                        var rowNode = table.row.add([
                            //data[i].GunId,
                            data[i].BranchName,
                            data[i].GunSerialNo,
                            data[i].GunTypeName,
                            data[i].ModelNo,
                            data[i].CarriedBy,
                            data[i].Bullets,
                            data[i].Purpose,
                            data[i].IssueDate,
                            data[i].IssueTime,
                            data[i].TotalEstimatedTime,
                            remarks,
                        ]);
                    }                        
                    table.draw();
                }
            });

I'm guessing something like this CSS should do the trick:

#GunTracking-detail-datatable{
    background-color:#eee;
}

If you really want to go to town and alter the whole of the stuff DataTables gives you'd need to have something like this:

#GunTracking-detail-datatable_wrapper{
    background-color:#eee;
}

Hope that helps, example here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM