State Persistence
A state in SurveyJS Dashboard is an object containing visualizer settings that a user has changed while working with the dashboard. These settings include the selected locale, chart types, chart layout, sorting, filtering, and others. You can save the state and restore it after users reload the page, allowing them to resume working with the dashboard from where they left off. In this demo, the state is saved to and restored from localStorage
. To test the state persistence functionality, change chart types, select different sort orders, or change the layout using drag and drop, and then reload the page. You should see your customizations persisted.
To save the state, handle the onStateChanged
event. A handling function contains the state object as the second parameter. Serialize this object to a JSON string and save this string to a desired storage.
To restore the state after a page reload, obtain the state as a JSON string from your storage, deserialize this string to a JSON object, and assign this object to the visualizer's state
property or pass it to the setState()
method.