Author Topic: About using saveState and loadState  (Read 1862 times)

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 155
    • View Profile
About using saveState and loadState
« on: December 28, 2024, 03:47:47 am »
Hi,

I?m trying to use saveState to save everything in colModel along with the following additional properties and load them from localStorage on grid initialization:

    numberCell.show
    rowBorders
    columnBorders
    stripeRows
    pageModel.type
    sortModel.type
    filterModel.type

For this purpose, I configured stateKeys as follows:


Code: [Select]
stateKeys: {
    numberCell: ['show'],
    rowBorders: 1,
    columnBorders: 1,
    stripeRows: 1,
    groupModel: ['on', 'header'],
    pageModel: ['type', 'rPP'],
    sortModel: ['type', 'sorter'],
    filterModel: ['type', 'header', 'menuIcon']
}


However, I couldn?t get these properties (like numberCell, pageModel.type, filterModel.type) to save with saveState or load correctly with loadState.

Am I missing something? How can I ensure these properties are properly saved and loaded?

Thanks in advance!


Jsfiddle: https://jsfiddle.net/pn92z1bt/3/



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6344
    • View Profile
Re: About using saveState and loadState
« Reply #1 on: December 30, 2024, 11:59:17 am »
Your jsfiddle is not set up properly, so couldn't check it.

Please ensure you are using latest version of pqgrid and kindly share a jsfiddle using https://jsfiddle.net/xokyt062/ if facing any issues.
« Last Edit: December 30, 2024, 12:03:32 pm by paramvir »

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 155
    • View Profile
Re: About using saveState and loadState
« Reply #2 on: January 03, 2025, 06:35:52 pm »
Hello Paramvir,

I updated the JSFiddle: https://jsfiddle.net/omerx/09qagv3z/ ,  but it doesn't work the same way as it does locally.

What I want to achieve: I would like to save all options (like those in the grid_parts demo) to localStorage using saveState and then reload them from there.

The idea is to create something like a merged version of the grid_parts  demo and the grid_state demo.

grid_parts  : https://paramquery.com/pro/demos/grid_parts
grid_state  : https://paramquery.com/pro/demos/grid_state

In addition to saving column layouts, I want to save and load other settings from localStorage. I would also like to include options for pageModel, sortModel, and filterModel. These options should allow users to toggle between local and remote settings, and the grid should restore them from localStorage when revisiting.

I've tried some implementations in JSFiddle but couldn't make it work. Any guidance would be greatly appreciated!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6344
    • View Profile
Re: About using saveState and loadState
« Reply #3 on: January 06, 2025, 01:48:37 pm »
This example shows how to save and load state ( pageModel, filterModel, sortModel, colModel, etc ) from localStorage

https://paramquery.com/pro/demos/grid_state

You can test it by making some changes and reloading the page.