Gridx in XPages – 21: Maintaining Grid State Between Sessions
Users often want to maintain the state of a data display so it can be automatically restored the next time they view that page. The Persist module of Gridx does just that. Simply by adding the module to the grid, settings are preserved between sessions. In this post, I’ll show how to add it and list several features that are persisted.
The Persist module stores information about the state of the grid when you leave the page. This way, the user returns to the grid the way they left it — even between sessions. (It uses a cookie to maintain the state and restore it.)
I tested it with the following features and found that it preserved them all:
- Sorting (single and nested)
- Column Widths
- Reordered Columns
- Hidden Columns
1. Require Module
The first thing you need to do is include the
Persist module in the require statement.
2. Include Module in Grid
To make it available to the grid, add it to the grid’s
modules: [ Resizer, NestedSort, Filter, FilterBar, QuickFilter, VirtualVScroller, Persist ]
That’s it — it just works!
Restoring to Original State
Then you need to reload the page. Nothing happens automatically, but when the grid is re-rendered, it will be back to its default layout.
Note: It can be done more efficiently by destroying and re-creating the grid rather than reloading the entire page.