if you want to style a specific cell based on a column you have to use columnDefs with render option as a callback with a target which refers to the column you want to control the cells in (you can take look here also).
so the code should look like that:
var dataSet = [
["Tiger Nixon", 1, "Edinburgh", "5421", "2011/04/25", "$320,800"],
["Garrett Winters", 12, "Tokyo", "8422", "2011/07/25", "$170,750"],
["Ashton Cox", 4, "San Francisco", "1562", "2009/01/12", "$86,000"],
["Cedric Kelly", 5, "Edinburgh", "6224", "2012/03/29", "$433,060"],
["Airi Satou", 23, "Tokyo", "5407", "2008/11/28", "$162,700"],
["Brielle Williamson", 54, "New York", "4804", "2012/12/02", "$372,000"],
["Herrod Chandler", 2, "San Francisco", "9608", "2012/08/06", "$137,500"]
];
var columnDefs = [{
title: "Name"
}, {
title: "Position"
}, {
title: "Office"
}, {
title: "Extn."
}, {
title: "Start date"
}, {
title: "Salary"
}];
var myTable;
myTable = $('#example').DataTable({
data: dataSet,
columns: columnDefs,
columnDefs: [{
targets: 1, // this means controlling cells in column 1
render: function(data, type, row, meta) {
if (data > 10) { // here is your condition
return '<div class="red-color">' + data + '</div>';
} else {
return data;
}
}
}]
});
and here is a working snippet
class
attribute or you could use therowDrawCallback
to achieve the same – Koonce