stateRestore.ajax
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:
Name Type Optional 1 data
No The relevant data that would be passed over ajax. The object contains 2 properties.
action
string
The type of action that is taking place to cause the ajax call. One ofload
,rename
,remove
orsave
.stateRestore
object
This object contains a property for each state that is to be affected by the call. The value when doing a save or a remove is the state object that it should store. When renaming this is slightly different and the value is the new name that should overwrite the value for the corresponding key. This property is not present when states are being loaded.
2 callback
No This callback can perform two different purposes depending on the action that is being performed.
In the first instance when predefined states are being loaded into StateRestore via the ajax function. In this case the
data.action
property will be set toload
. It takes a single argument that should have the same structure asstateRestore.preDefined
.For all other possible actions this callback must be run whenever the action has succesfully been performed. In this case it takes no extra 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'
}
}
]
});