{hero}

DataTable.tables()

Since: DataTables 1.11

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

function tables( [ visible ] )

Description:

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:
Returns:

Array or DataTables 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();
});