Andrew
Andrew

Reputation: 622

How to add classes to each row in datatable jQuery

Hi all i work with datatables,

I want to add class to each table row element in each page.

But for some case is adding only for first page new class, but for other no, how i can to fix this?

My code:

$(document).ready(function () {
    var table = $('.table-style').DataTable();

    $('.dropdown').addClass("test")

    table.draw();

});

Upvotes: 0

Views: 563

Answers (1)

Yeasir Muhmmad Pervej
Yeasir Muhmmad Pervej

Reputation: 161

You need to add class after the datatable is drawn. This event will be called on pagination or when the page loads. So you can execute your js code or add class on each page. Here is a sample code.

$(document).ready( function() {
    $('.custom-style').dataTable( {
        "fnDrawCallback": function( oSettings ) {
            $('.dropout').addClass("test");
        }
    } );
} );

For more info see this https://legacy.datatables.net/ref#fnDrawCallback

Upvotes: 1

Related Questions