cell.node() undefined for some rows in rowCallback
cell.node() undefined for some rows in rowCallback
Hi guys,
I use the following function as a rowCallback to make negative numbers red:
function negativeRed( row, data, index ) {
this.api().cells(index, '.negative-red').every( function() {
console.log(this, this.data(), this.node());
if (this.data() < 0) {
$(this.node()).addClass('text-danger');
} else {
$(this.node()).removeClass('text-danger');
}
});
}
This works fine in small tables, but in larger tables (> 50 rows), this.node() is undefined for the first rows, so it does nothing. Is there anything I can do to solve this.
Thanks!
This question has an accepted answers - jump to answer
Answers
The problem is likely due to the
index
you are using for thecells()
API. The third parameter of therowCallback
is this:However I think you are trying to use is a
row-selector
of an integer which is expected to be the row index. The fifth parameter ofrowCallback
is the row index:Try using the fifth parameter.
You might be able to do something like this as a jQuery
cell-selector
:Kevin
You are absolutely right, worked like a charm. Thank you so much!