created row callback could not highlight particular cell value

created row callback could not highlight particular cell value

anant30anant30 Posts: 7Questions: 4Answers: 0
edited August 2018 in Extensions

I am trying to highlight the cell values which are 'null'.
So when i run following code snippet, instead of highlighting null, it highlights the whole column which are not null.

 "createdRow": function (row, data, index) {
                if (data[7] = 'null') {
                    $('td', row).eq(7).addClass('highlight');
                }
            } 

not sure why this is happening. can you help me find a solution?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,735

    I suspect the problem is here:
    if (data[7] = 'null')

    Using one = is an assignment not a comparison. I seem to make this mistake quite often too :smile:

    An you probably don't want null in quotes. Maybe something like this:
    if (data[7] === null)

    If this doesn't help then please post a test case with a sample of your data and createdRow code.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • anant30anant30 Posts: 7Questions: 4Answers: 0

    Oh ya, thanks Kevin!
    and I tried if (data[7] === null) though it still highlighted the whole column.

    But the following worked!

    "createdRow": function (row, data, index) {
                    if (data.service_time === null) {
                        $('td', row).addClass('highlight'); //highlighted whole row
                    }
    
  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin
    Answer ✓

    Yes, the data parameter passed in is the original data source, so if you are using objects, then you would need to get the data from as an object, not an array.

    Allan

This discussion has been closed.