Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

393
Views
jQuery datatables: test if datatables plugin is initialized

I want to check if a table element with say, id="datatable" is datatables-initialized. Something like this:

if ($('#datatable').dataTable().initialized) {
  alert("initialized!");
}
else {
      alert("not initialized!");
    }

How can I do that? Thanks!

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can the fnIsDataTable function in jQuery datatable

var ex = document.getElementById('example');
if ( ! $.fn.DataTable.fnIsDataTable( ex ) ) {
  $(ex).dataTable();
}

You can find more information in api

over 4 years ago · Santiago Trujillo Report

0

First, add a special class name when you're initializing datatables:

$('.datatable').not('.initialized').addClass('initialized').dataTable()

And now you can tell them apart by class name:

alert( $('#datatable').hasClass('initialized') )
over 4 years ago · Santiago Trujillo Report

0

I feel following is the right answer to this.

$(document).ready(function(){
    if (jQuery().dataTable) {
         // your code to do some detaul set ups 
    }
});

For example

$(document).ready(function(){
    if (jQuery().dataTable) {

            $.extend( $.fn.dataTable.defaults, {
                iDisplayLength : 200,
                aLengthMenu : [[100, 200, 300, -1], [100, 200, 300, "All"]],
            });
        }
});

By this way you if(jQuery().<libname>) should be able to check any library loaded or not.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!