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!
After you've called .dataTable() does it do anything to the table that makes it identifiable? i.e. does it add a new class "initialised" or something like that? If so, you could just loop through the items like so:
Apologies if this isn't what you mean. It's not clear in your question what "dataTable()" actually does.
I have used
callback()
function to do the same in my scenario. Thought of sharing this as an alternate approachLater in code..
First, add a special class name when you're initializing datatables:
And now you can tell them apart by class name:
I feel following is the right answer to this.
For example
By this way you
if(jQuery().<libname>)
should be able to check any library loaded or not.You can the fnIsDataTable function in jQuery datatable
You can find more information in api
Datatable has a method to check if an element has been initialized as a datatable or not - $.fn.DataTable.fnIsDataTable