state()

Since: DataTables 1.10.1

Get / set the state of the table.

Description

The "state" of a DataTable refers to properties that define its current display, such as pagination parameters, ordering and filtering. While you can use individual API methods to get and set properties (e.g. order()) this method provides a collected API that will give and take information about the table as a whole. Please note also that it does work without stateSave being enabled.

The state object has the properties and structure described by DataTable.State, noting also that plug-ins and extensions to DataTables can modify this structure by adding data as they require for their own state information.

If using this method as a setter, you will very likely want to call draw(), passing in false to the method, to ensure that the table is redrawn with the new state (and that the correct paging is shown).

Types

state()

Get the state of the DataTables

Returns:

DataTable.State: State saved object

state( set [, ignoreTime ] )

Since: 2.0.0

Set the state of the DataTables

Parameters:

Returns:

DataTable.Api: DataTables API instance

Examples

Get the saved page length from the state object:

alert('Saved page length is: ' + table.state().length);

Get the table state, change it and load it back:

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

state.start = 10;

table.state(state).draw(false);

Related

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