DataTable.tables()
Get all DataTables on the page.
Description
It can be useful to be able to get a list of the existing DataTables on a page, particularly in situations where the table has scrolling enabled and needs to have its column widths adjusted when it is made visible. This method provides that ability.
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
tables( [ visible ] )
Get all DataTable tables that have been initialised - optionally you can select to get only currently visible tables and / or retrieve the tables as API instances.
Parameters:
Name | Type | Optional | |
---|---|---|---|
1 | visible | Yes - default:false | |
As a boolean value this options is used to indicate if you want all tables on the page should be returned ( Since 1.10.8 this option can also be given as an object which has the following optional parameters:
|
Returns:
DataTables.Api
DataTable API instance containing all matching DataTables
Examples
Non-jQuery: Adjust the column widths of all visible tables:
DataTable.tables({ visible: true, api: true }).columns.adjust();
Adjust the column widths of all visible tables:
$.fn.dataTable.tables({ visible: true, api: true }).columns.adjust();
Adjust column widths when a table is made visible in a Bootstrap tab:
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
$.fn.dataTable.tables({ visible: true, api: true }).columns.adjust();
});