stateRestore
Since: StateRestore 2.0.0
Triggered when a state has been added, removed or changed.
Please note - this property requires the StateRestore extension for DataTables.
Description
This event is triggered whenever one of the following occurs to a state within StateRestore.
- States are loaded
- A new state is added
- A state is updates.
- A state is removed
The event can be used to update any external control that you might have that shows the list of states manged by StateRestore. See this example for a running test case.
Type
function( e, action, state )
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | e | No | |
Event object | |||
| 2 | action | No | |
The action that has been performed. This can be one of | |||
| 3 | state | No | |
The state object that has been updated (only provided for | |||
Example
Display a list of states, with control buttons for each:
const Dom = DataTable.Dom;
const states = Dom.s('#states');
// Create the DataTable - regular StateRestore buttons are included to show the interaction
const table = new DataTable('#example', {
layout: {
topStart: {
buttons: ['stateCreate', 'statesList', 'pageLength']
}
},
stateRestore: true
});
// List of states - updates based on the `stateRestore` event
table.on('stateRestore', () => {
statesEl.empty();
table.stateRestore
.states()
.details()
.forEach(s => {
Dom.c('li')
.text(s.name)
.appendTo(statesEl);
});
});