I have DataTablein which values dynamically inserted. Based on each cell value, I need to change it background-colorand add another one CSS. I have a solution here JSFiddle
Although it seems slow with big data, is there any other way to achieve this? so that
-> The styling does not disappear on sorting the column
-> It a little faster than it is now.
the code:
var t = $('#example').DataTable( {
"iDisplayLength": 10,
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"aaSorting": [[1, 'asc']],
"scrollX": true,
"scrollCollapse": true,
"fixedColumns": {"leftColumns": 2},
"sScrollXInner": "150%",
"fixedHeader": true,
"rowCallback": function (row, data) {
for (var p = 2; p < data.length; p++) {
if(data[p] == "red"){
$('td:eq('+p+')', row).addClass('highlight1');
}
}
if ($.inArray(data.DT_RowId, selected) !== -1) {
$(row).addClass('selected');
}
},
} );
var selectedSPFName = $("#spfspan").text();
$.each(md, function(i, x){
var thisRow = [];
thisRow.push('<u><a target="_blank" href="' + x.Data[0].Link + '">' + x.Data[0].Value + '</a></u>');
for(var k=1;k<x.Data.length;k++){
thisRow.push(x.Data[k].Value);
}
t.row.add(thisRow).draw();
});
Any suggestions on this are greatly appreciated! Thank!
source
share