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:

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);
		});
});