Changing row color with ajax data

Changing row color with ajax data

MisterS89MisterS89 Posts: 4Questions: 2Answers: 0

Hi,

When the value of column 'status' equals 'Aanwezig', i want to color de row green, otherwise red.
Code works but as soon i replace html data with ajax it fails.

Based on these posts:
https://datatables.net/forums/discussion/36595/change-the-row-color-based-on-column-data
https://datatables.net/forums/discussion/62460/changing-row-color-at-rendering-time-based-on-column-values

Example:
http://live.datatables.net/cesevuhe/1/edit?html,css,js,console,output

Can anyone help? :)

Thx!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    Your dat structure is objects not arrays. Use data.status instead of data[2], for example:

        rowCallback: function (data) {
          if (data.status === 'Afwezig') {
            $(row).addClass('green');
          }
          else {
            $(row).addClass('red');                            
          }                               
        }    
    

    Kevin

  • MisterS89MisterS89 Posts: 4Questions: 2Answers: 0

    Wow thanks kthorngren!
    Totally missed that, works as expected now.

Sign In or Register to comment.