This page covers a non-latest version of Handsontable.
# Saving data
# Overview
Persistent state storage is particularly useful when running multiple instances of Handsontable on one page as it allows data separation per each instance.
# Saving changes using a callback
Use the afterChange
callback to track changes made in the data grid. In the example below, Ajax is used to load and save the data. Note that this is just a mockup, and nothing is actually saved. You need to implement the server-side part by yourself.
# Saving data locally
You can save any type of data in local storage to preserve the table state after page reloads. The persistentState
option must be set to true
to enable the data storage mechanism. You can set it either during the Handsontable initialization or using the updateSettings()
method.
When the persistentState
option is enabled, the PersistentState
plugin exposes hooks listed below:
# PersistentState
vs localStorage
The main benefit of using the PersistentState
plugin hooks rather than the regular localStorage
API is that it ensures separation of data stored by multiple Handsontable instances. For example, if you have two or more instances of Handsontable on one page, data saved by one instance will be inaccessible to the second instance. Those two instances can store data under the same key, and no data would be overwritten.
For the data separation to work properly, make sure that each instance of Handsontable has a unique id
.
# Related API reference
- Configuration options:
- Core methods:
- Hooks:
- Plugins: