I have a DataTable
into which the values are dynamically inserted
. Based on each value of the cell, I need to change its background-color
and add some other CSS
. I do have a solution here JSFiddle
Although,it seems to be slow with large data,is there some other way of achieving this? so that,
-> The styling does not disappear on sorting the column
-> It's a little faster than it is now.
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');
}
},
} );
// $('.searchable').tablesearcher({ 'input': $in });
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 highly appreciated! Thank you!