Sunday, March 30, 2014

Preserving Grid State in KendoUI

Continuing from the last post about preserving tab state, next up is automatic, universal grid state preservation. The state could be stored to the session, but then code has to be added server side for each Ajax endpoint. That's not possible of the grid is polling a third party service as well. It's better to handle it all client side with local storage.

The script will wrap around the grid constructor and setup events to capture the state. It also checks if you wish to use local or session storage in the browser. Local storage persists across browser closes while session won't. Both are useful for different situations.

Currently, only a limited state is captured:
  • Page
  • Page size
  • Sorts
  • Filters
  • Grouping
Other options like visible columns are not stored.

The jquery extension for local storage is just a slightly modified version of Marcus Westin's store.js. Modified to attach to jquery and allow selection between local and session storage.

No comments:

Post a Comment