{hero}

ready()

Since: DataTables 2.0

Determine if a DataTable is ready.

Description

There are times when you might want to know if a DataTables is in it's "ready" state - i.e. it has initialised, its control elements are on the page and the first data has been loaded and displayed. It can be useful to start working on the data at that point. DataTables has the init event and initComplete option that can be used for that, but they only fire once on a table and (without this method) there is no way to know if the table is ready or not.

This method can be used in two different ways; firstly to determine the ready state of a DataTable, and secondly to execute a function when the table becomes ready, or immediately if the table is already ready.

Types

function ready()

Description:

Determine the ready state of the table. Note that if your API instance contains context for more than one table, only the state of the first table will be returned.

Returns:

true if the table is ready, false otherwise.

function ready( fn )

Description:

Execute a function when the table becomes ready, or immediately if already ready.

Parameters:
Returns:

API instance for chaining.

Examples

Execute a function for a DOM loaded table - this will happen immediately since the table initialisation is synchronous.:

let table = new DataTable('#myTable');

table.ready(function () {
	// Actions to take when the table is ready
	// ...
});

Execute a function for an Ajax loaded table - this will happen after the data has been loaded, which happens asynchronously.:

let table = new DataTable('#myTable', {
	ajax: '/api/data'
});

table.ready(function () {
	// Actions to take when the table is ready
	// ...
});

Related

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