tables()

Since: DataTables 1.10

Select tables based on a selector from the API's context.

Description

The DataTables API can operate on multiple tables at a single time - the tables in the "context". As a quick example $('.dataTable').DataTable().search('Fred').draw(); will filter all tables which were found by the class dataTable.

The context of an API instance defines which DataTable tables the API will operate on and this method provides one way to control what tables are in that context.

This ability to operate on multiple tables can be particularly useful if you have many tables on a single page, but you might also wish to reduce the table's in the API's context to operate on just one, or some other subset of the tables.

If you are working with single table API instances only, then this method will be of limited use to you! It is really only appropriate when working with multiple tables. Additionally, please note that there is no option that this selector can perform over using jQuery directly on the DOM to select tables. It is mainly provided for convenience and completeness of the API.

Types

function tables()

Description:

Select all tables

Returns:

DataTables API instance with all tables in the current context.

function tables( selector )

Description:

Select tables based on the given selector

Parameters:
Returns:

DataTables API instance with selected tables in its context.

Examples

Apply an order to the second and third table in the API's context:

var tables = $('.dataTable').DataTable();

tables.tables( [1, 2] ).order( [ 3, 'asc' ] ).draw();

Find all tables which have a class admin from an API instance and apply a global search to them.:

var tables = $('.dataTable').DataTable();

tables.table('.admin').search( 'Important' ).draw();

// Note that:
//   $('.dataTable.admin').DataTable().search('Important').draw();
// would also have achieved the same effect

Related

The following options are directly related and may also be useful in your application development.