I am adding child rows dynamically to datatables to show data fetched dynamically. Here is the code for that:
var oTable = $('#myTable5').DataTable();
var tr = $('#'+id).closest('tr');
var row = oTable.row( tr );
console.log(row);
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child( format(dataSet) ).show();
tr.addClass('shown');
}
But for the life of me I cannot figure out how to add a background color to this child row!! I have tried a lot of things and nothing has worked. If you have successfully achieved this, please help. Posting on datatable forums yielded no working response.
TIA.
You can set background for child row as below. rowBackground
is a css class.
Working fiddle here
row.child("child row",'rowBackground').show();