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!
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') )
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.