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!
isDataTable() could be used, but this only works for table selectors, not for variables containing an initialized DataTable. This function is returning false for such variables: var table = $("#table"). DataTable(); // Valid initialized DataTable console.
isDataTable() method provides the ability to check if a table node is already a DataTable or not. It can be accessed at any time, even before any DataTable has been created on the page. isDataTable() is a function of $. fn.
fn. dataTable. ext.search . This is an array of functions (push your own onto it) which will will be run at table draw time to see if a particular row should be included or not. This example shows a search being performed on the age column in the data, based upon two inputs.
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
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') )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With