Call rendered data field in CreatedRow
Call rendered data field in CreatedRow
Hi,
i would like to check in CreatedRow if a rendered field is negative number or not so that i color red the font or the cell background.
How to refer to the data:null field ?
eg.
if(data.field1 > 0 ) { // works if field1 was not rendered
$(row).find('td:eq(11)').css('color', 'green');
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You can use the
rowparameter to get thetrelement. I've usedcolumns.classNameto add a class to the rendered column I want to check and increatedRowusedvar status = $(row).find('.status').text();to get the text of that particular cell. The rendered column is not part of the row data source which is why it isn't accessible using thedataparameter.Kevin
Thank you.
But what if i also have another class for that column?
eg.
"className": 'text-center', "targets": [8,9,10,11,12,13,14] }and"className": 'status', "targets": [8] }In this case only one class works.It does not 'center' the text in the column.
The second will likely overwrite the first. You can add multiple classNames in one string, like this:
"className": 'text-center status', "targets": [8,9,10,11,12,13,14] }. The same as you would add directly in HTML.Kevin
I use
but id does not work.
How should the
if ($(row).find(' ')be written?There must be no space between the 2 classes in order to work.
Thank you.
You should be able to use just
.status, like this:$(row).find('.status').css('color', 'red');Unless of course you want to limit the find to having both.
Kevin