(conditional cell formatting) add class to cell (td) from within render function
(conditional cell formatting) add class to cell (td) from within render function
xtech_dev
Posts: 25Questions: 11Answers: 0
I would like to achieve conditional formatting based on cell value. Is it possible to add class to td element from inside of render function?
I have tried but it seems to not have any effect.
function (data, type, row, meta) {
if (type == "display") {
var $table = $(meta.settings.oInstance.api().table().node());
var $td = $table.find('tr:eq(' + meta.row + ') > td:eq(' + meta.col + ')');
$td.addClass('bkg-red');
}
}
I have seen solution with rowCallback option (https://datatables.net/forums/discussion/comment/110916/#Comment_110916) but i would prefer to keep render logic in "one place".
Any ideas?
It Man.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
My understanding is
columns.render
is meant to manipulate the data in the table and is not meant for manipulating the HTML. So there are no provisions provided for HTML manipulation incolumns.render
.createdRow
andcolumns.createdCell
are built for this functionality. And as you mentionedrowCallback
can also be used.Kevin