initComplete for all datatables

initComplete for all datatables

itajackassitajackass Posts: 162Questions: 48Answers: 3

Is there a way to add a unique script to add a initComplete event FOR ALL TABLES FOR ALL PAGES?

I'd like to color the bFilter when is compiled.

This work perfectly in my "common-script-for-all-pages.js" on change event.

$("body").on("change", ".dataTables_filter input", function(e) {

if ( $(this).val() != "" ) {
    $(this).addClass("label-warning");
} else {
    $(this).removeClass("label-warning");
}

});

But if refresh page using F5, page reload, bfilter get the value inserted before (this is correct) but "label-warning" class is gone :(

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Yes, use the init event which bubbles up the document so you can do:

    $(document).on('init.dt', function () {
      ...
    } );
    

    This is what many of the extensions do.

    Allan

This discussion has been closed.