{hero}

stateRestore.ajax

Since: StateRestore 1.0.0

Setup the loading and saving of states over ajax.
Please note - this property requires the StateRestore extension for DataTables.

Description

This option allows StateRestore to load and save states over ajax. If the value provided for this option is a string, StateRestore will use it as the destination url for requests via ajax.

Setting the value to a function allows users to customise the behaviour when loading states into StateRestore, renaming, removing or saving states. There are no restrictions on the behaviour of the function - you can do whatever you please when this is called.

As default the value is false, meaning that the states will be saved in the local session storage. Setting the value of this option to true has no effect.

Take a look at this example to see this in action.

Types

boolean

Description:

false if ajax is not to be used. If ajax is to be used then this should be set to a string so that StateRestore can send requests to the appropriate location.

string

Description:

This option should be set to a string when StateRestore is to attempt to use ajax to load and save states. This string should be a url to tell StateRestore where it should make requests.

function

Description:

This function is called whenever

  • States are loaded into StateRestore
  • A state is renamed
  • A state is removed
  • A state is saved

It takes two parameters. The first is data that contains all of the data necessary to process the action. The second is a call back function that should be called when loading states via the ajax function. Being able to set this option as a function allows users greater flexibility in how they want to store their states.

Parameters:
Returns:

Default

  • Value: false

The default value for the stateRestore.ajax option is false meaning that as standard the creation and saving of states will be done using the local session storage.

Example

Set ajax url for StateRestore to send requests to:

$('#example').DataTable({
	dom: 'Blfrtip',
	ajax: {
		url: "../data/2500States.txt",
		dataSrc: 'data'
	},
	buttons:[
		'createState',
		{
			extend: 'savedStates',
			config: {
				ajax: '../stateControllers/stateRestore.php'
			}
		}
	]
});