Sorting with Background Color
Sorting with Background Color
Abhayman
Posts: 1Questions: 1Answers: 0
Hi,
I have JQuery to pull data into table and it works perfectly fine . I am even able to color code the last row. But the moment I sort it the color coding gets messed up.
$(function () {
$('#example2').DataTable({
"ajax": "../json/daily_status.json",
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
if ( iDisplayIndex == 9 ) {
$('td', nRow).each(function(){
$(this).html( '<td bgcolor="#BE81F7"><b>'+$(this).text()+'</b><td>' );
});
}
return nRow;
},
"scrollX": false,
"ordering": true,
"paging": false,
"info": false,
"searching": false,
dom: 'Bfrtip',
buttons: [
'excel'
]
}); });
Say my last row ( 1st column ) is Total . How can I retain color for row Total inspite of sorting ?
Any suggestions ?
Regards.
This discussion has been closed.
Answers
Background color is controlled by the CSS associated with the sorting styles. Look in the CSS file for .sorting_1 etc.
You can use the browser debugger to see the calculated styles and determine where the net background color is coming from.
Correction, the correct way to control this behaviour is to use the orderClasses option. This can prevent the sorting styles from being applied.
https://datatables.net/reference/option/orderClasses