Quantcast
Channel: XPages – Xcellerant
Viewing all articles
Browse latest Browse all 216

Gridx in XPages – 21: Maintaining Grid State Between Sessions

$
0
0

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.

Gridx Series

Gridx in XPages — Entire Series

Persist

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
  • Filtering
  • Reordered Columns
  • Hidden Columns

1. Require Module

The first thing you need to do is include the Persist module in the require statement.

"gridx/modules/Persist"

2. Include Module in Grid

To make it available to the grid, add it to the grid’s modules list.

modules: [  
  Resizer,
  NestedSort,
  Filter,
  FilterBar,
  QuickFilter,
  VirtualVScroller,
  Persist
]

That’s it — it just works!

Restoring to Original State

If you want to restore the grid to its original state, you can do so, but setting the enabled property to false via client-side JavaScript.

grid.persist.enabled=false;

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.



Viewing all articles
Browse latest Browse all 216

Trending Articles