Row color based on value

Row color based on value

TorkuatixTorkuatix Posts: 3Questions: 1Answers: 0
edited April 2020 in Free community support

Hi. I have this code, that is working fine. But when I uncomment rowCallback function I get no data in the table. Can anybody help? Thanks in advance.

$(document).ready(function(){

$('#add_button').click(function(){
    $('#user_form')[0].reset();
    $('.modal-title').html("<i class='fa fa-plus'></i> Add User");
    $('#action').val("Add");
    $('#btn_action').val("Add");

});

$('#user_data').DataTable({



    "processing": true,
    "serverSide": true,
    "order": [],
    "ajax":{
        url:"user_fetch.php",
        type:"POST"
    },


    /*"rowCallback": function( row, data, index ) {
      if (data.compania == "EIG") {
        $(row).css('color', 'red');
      }
    }*/



    "pageLength": 25
});

});

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,170Questions: 26Answers: 4,922
    edited April 2020 Answer ✓

    When the page doesn't seem to load properly you are probably getting a Javascript error. Take a look at your browser's console for errors.

    Kevin

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416
    Answer ✓

    The rowCallback looks perfectly normal. I use it in the same way and it works fine. Have you checked your console for errors?

    Is it really "data.compania" that you are retrieving or rather "data.yourTable.compania"?

  • TorkuatixTorkuatix Posts: 3Questions: 1Answers: 0

    Thanks for your help. Now it's showing data but not applying color.
    It was a missing comma (error in console)-> thanks kthorngren.

    rf1234, when you say: "yourTable", do you mean mysql table?

    Again, thanks in advance.

  • TorkuatixTorkuatix Posts: 3Questions: 1Answers: 0

    Now it's working with data[5]. Thank you both!!

This discussion has been closed.