Search code examples
jquerycssdatatablesserver-side

How can I put styles on data list after server-side processing?


I want to put a style on a particular data after server-side processing on datatables. I use the wrap() to do that but it doesn't work.

"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
        if (aData[4] == 'service stopped'){
          console.log('here');
          $(aData[4]).wrap('<span class="badge-sm badge-danger"></span>');
        }
      },

This gave me 3 'here' which is right but the '' doesn't show.


Solution

  • So only way to pass from

    aData[4] == 'service stopped'
    

    is if aData[4] is a string literal of 'service stopped'. So

    $(aData[4]).wrap
    

    should likely be

    $('td:eq(4)', nRow).wrap
    

    as instead of a string it is wrapping row n on 4th column.