stateRestore.add()
Create a new state.
Please note - this property requires the StateRestore extension for DataTables.
Description
This method provides the ability to create a new state that is managed by the StateRestore extension.
stateRestore.add() takes just one argument (which is optional), the state name. A modal will be shown to the end user with options to customise the state (e.g. change the name, and properties saved if that is configured) before the state is then saved to storage.
When using local storage (i.e. stateRestore.ajax is not specified), then the state will be given a random id. This can be used as a selector for stateRestore.state() if you then wish to modify or otherwise manipulate the state via the API in future.
Type
stateRestore.add()
Creates a new state.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | identifier | Yes - default: | |
The string that is used to identify this state. This parameter is optional and if no value is given the next default name in the sequence will be used. | |||
Returns:
DataTable.Api:
Returns a DataTables API for chaining, with the object containing the state that has been extracted from the table in the result set.
Example
Add a new state:
const table = new DataTable('#myTable', {
layout: {
topStart: {
buttons: ['stateCreate', 'statesList']
}
}
});
// Button to add a state based on the current table state
document.querySelector('#createState', function () {
table.stateRestore.add();
});