How can I add class for in DataTables?

0
344

Using createdRow option is the correct way to do it.

For example:

$('#example').DataTable({
  'createdRow': function( row, data, dataIndex ) {
      $(row).addClass( 'bill-row' );
  }
});

However you’re retrieving rows incorrectly. Using $(".bill-row") will return rows on the current page only.

As an alternative use $() API method instead.

For example:

var row = $('#example').DataTable().$('.bill-row');

OR

I like the rowCallback option:

table = $('#resultTable').DataTable({
    aaSorting: [],
    ajax: {...},
    columnDefs: [...],
    rowCallback: function (row, data) {
        if (data.IsDeleted) {
            $(row).addClass('redRow');
        }
    }
});

LEAVE A REPLY

Please enter your comment!
Please enter your name here