Call rendered data field in CreatedRow

Call rendered data field in CreatedRow

mihalispmihalisp 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

Answers

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736

    You can use the row parameter to get the tr element. I've used columns.className to add a class to the rendered column I want to check and in createdRow used var 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 the data parameter.

    Kevin

  • mihalispmihalisp Posts: 127Questions: 22Answers: 0

    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.

       if ($(row).find('.status').text()  < 0 )  {  
    
        $(row).find('.status').css('color', 'red');
        }
    
  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736
    Answer ✓

    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

  • mihalispmihalisp Posts: 127Questions: 22Answers: 0

    I use

     if ($(row).find('.text-center .status').text()  < 0 )  { 
    
     $(row).find('.text-center .status').css('color', 'red');
      }
    

    but id does not work.

    How should the if ($(row).find(' ') be written?

  • mihalispmihalisp Posts: 127Questions: 22Answers: 0

    There must be no space between the 2 classes in order to work.

      $(row).find('.text-center.status').css('color', 'red');
    

    Thank you.

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736

    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

This discussion has been closed.