{hero}

stateRestore.saveState

Since: StateRestore 1.0.0

Enable/Disable saving for various datatables elements.
Please note - this property requires the StateRestore extension for DataTables.

Description

This option determines what StateRestore will save. The option is an object containing boolean values, one for each element that could be saved. These are as follows.

columns.search

This option allows for the saving of the search applied to individual columns to be enabled or disabled.

As default the value is true, meaning that the column searches will be saved. If this option is set to false, then column searches will not be saved.

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

columns.visible

This option allows for the saving of the visibility of the columns to be enabled or disabled.

As default the value is true, meaning that the column visibilities will be saved. If this option is set to false, then column visibilites will not be saved.

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

length

This option allows for the saving of the page length to be enabled or disabled.

As default the value is true, meaning that the page length will be saved. If this option is set to false, then the page length saving will be disabled.

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

Note: When using this option and saving states with paging, StateRestore will display the first row that was displayed at when the state was saved at the start of the table. This could for example result in a table with page length of 50, but starting on record 31. Without knowing the page length it is not possible for DataTables to calculate any other start position.

order

This option allows for the saving of the tables column sorting to be enabled or disabled.

As default the value is true, meaning that the column sorting will be saved. If this option is set to false, then column sorting saving will be disabled.

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

paging

This option allows for the saving of the paging to be enabled or disabled.

As default the value is true, meaning that the paging will be saved. If this option is set to false, then the paging saving will be disabled.

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

scroller

This option allows for the saving of the scroller position to be enabled or disabled. This option is only applicable when both the stateRestore and scroller extensions are in use.

As default the value is true, meaning that the scroller position will be saved. If this option is set to false, then the scroller position saving will be disabled.

search

This option allows for the saving of the search to be enabled or disabled.

As default the value is true, meaning that the search will be saved. If this option is set to false, then the search saving will be disabled.

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

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

searchBuilder

This option allows for the saving of the searchBuilder state to be enabled or disabled. This option is only applicable when both the stateRestore and searchBuilder extensions are in use.

As default the value is true, meaning that the searchBuilder state will be saved. If this option is set to false, then the searchBuilder state saving will be disabled.

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

searchPanes

This option allows for the saving of the searchPanes state to be enabled or disabled. This option is only applicable when both the stateRestore and searchPanes extensions are in use.

As default the value is true, meaning that the searchPanes state will be saved. If this option is set to false, then the searchPanes state saving will be disabled.

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

select

This option allows for the saving of the select state to be enabled or disabled. This option is only applicable when both the stateRestore and select extensions are in use.

As default the value is true, meaning that the select state will be saved. If this option is set to false, then the select state saving will be disabled.

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

Type

object

Description:

This initialisation option is an object that includes a variety of boolean values that enable or disable the saving of different elements of datatables

Default

  • Value: object

The default value for the stateRestore.saveState option is an object as follows. This will save everything that can possibly be saved when using datatables.

{
    columns: {
        search: true,
        visible: true
    },
    length: true,
    order: true,
    paging: true,
    scroller: true,
    search: true,
    searchBuilder: true,
    searchPanes: true,
    select: true
}

Examples

Disable paging saving:

$('#example').DataTable({
    dom: 'Blfrtip',
    buttons:[
        'createState',
        {
            extend: 'savedStates',
            config: {
                saveState: {
                    paging: false
                }
            }
        },
        'colvis'
    ]
});

Disable column visibility saving:

$('#example').DataTable({
    dom: 'Blfrtip',
    buttons:[
        'createState',
        {
            extend: 'savedStates',
            config: {
                saveState: {
                    columns: {
                        visible: false
                    }
                }
            }
        },
        'colvis'
    ]
});

Related

The following options are directly related and may also be useful in your application development.