DataTable.isDataTable()
Check is a table node is a DataTable or not.
Description
This method provides the ability to check if a table
node is already a DataTable or not. This can be useful to ensure that you don't re-initialise a table that is already a DataTable.
Please note that this is a static function and is accessed through the DataTable
or $.fn.dataTable
object, not an API instance. It can be accessed at any time, even before any DataTables have been created on the page.
Prior to DataTables 1.11 this method could be accessed through the $.fn.dataTable
object only. As of 1.11, either DataTable
or $.fn.dataTable
can be used.
Type
function isDataTable( table )
- Description:
Check if a
table
node is a DataTable table already or not.- Parameters:
Name Type Optional 1 table
No The table to check. This can be given as one of:
- A DOM element
- A jQuery selector
- A jQuery object containing the node to check
- A DataTables API instance.
Note that only the first node is checked if the jQuery selector or object match multiple nodes.
- Returns:
true
the given table is a DataTable,false
otherwise
Examples
Non-jQuery: Check if #example
is a DataTable or not. If not, initialise:
if (!DataTable.isDataTable('#example')) {
new DataTable('#example');
}
jQuery: Check if #example
is a DataTable or not. If not, initialise:
if (!$.fn.DataTable.isDataTable('#example')) {
new DataTable('#myTable');
}