Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

397
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda