text color in column
text color in column

Hi,
I trying to change a color of text in one column if certain conditions are met. In the column the data type are Number, then if greater than 0 color green and if smaller than 0 color red.
To do this usually I set class in the <td class="changeColor"></td> and with Jquery / Lodash
$('.changeColor').each(function(){
if($(this).text() > 0){
$(this).css('color', 'green);
}else if($(this).text() < 0){
$(this).css('color', 'red');
}
})
In my datatable I have 50 entries, but this code only select 30 items.
Any suggestion?
Thanks
Replies
The recommended way with Datatables would be to use
createdRow
orrowCallback
orcolumns.createdCell
to do this. Depends on your requirements but it looks likecolumns.createdCell
might be the way to go since you are only looking at the values in the column you are setting the text color in.Kevin
As Kevin said,
createdRow
is the way to go, see here.