Call rendered data field in CreatedRow
Call rendered data field in CreatedRow
mihalisp
Posts: 127Questions: 22Answers: 0
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
row
parameter to get thetr
element. I've usedcolumns.className
to add a class to the rendered column I want to check and increatedRow
usedvar 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 thedata
parameter.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