This is a migrated thread and some comments may be shown as answers.

Automatic grid persistence and load example

4 Answers 217 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Debbie
Top achievements
Rank 1
Debbie asked on 03 Jul 2019, 08:54 PM

Hi does anyone have a working example of loading a previous saved state when the grid first loads, and saving the filters/sort/column order when they are changed?

this needs to be completely seamless to the user (no save/load buttons), and I would prefer not to save/load the entire grid state from getOptions, just the filters/sorts/columnorder/page

note: I've already looked through the examples here: https://www.telerik.com/support/code-library/preserve-grid-state-in-a-cookie and here: https://demos.telerik.com/kendo-ui/grid/persist-state

the current issue I am running into is if I save the current state in the databound event (calling get-options), I can never retrieve them on page load as the databound event fires (saving empty state) before I would be able to retrieve the state from an external method (ie. trying to load on document ready). 

the only workaround I can think of at this point is to load the settings from the databound event too, but flag it somehow so it only does so on first load.

 

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 04 Jul 2019, 08:30 AM
Hi Debbie,

I can see that you've made a pretty good research about this. And you are correct - generally, you can use the kendo.stringify(grid.getOptions()) logic to represent the grid settings as a string value and saving it in a custom storage:
http://demos.telerik.com/aspnet-mvc/grid/persist-state

In order to automate this functionality or execute your custom logic to preserve the settings, you can try to use the Events provided by the Kendo grid, for example dataBound. It will be raised after paging, sorting, etc.:
http://demos.telerik.com/aspnet-mvc/grid/events
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-dataBound

If dataBound is not suitable for your specific scenario, there is an alternative event you can use - and it is called change:
https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/events/change

An important point is that this is an event provided by the DataSource instance, not the Grid widget.
 
You can also make changes to the saved settings if you wish, similar to the approach demonstrated here:
https://docs.telerik.com/kendo-ui/knowledge-base/grid-persist-customized-filter

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Debbie
Top achievements
Rank 1
answered on 05 Jul 2019, 01:52 PM

Eyup -To re-iterate the question- do you have a working example for my scenario?

I had previously reviewed all the links you provided, none use this scenario.

also, per the documentation, the change event fires when the data is edited, not when filters/sorts/reorders happen.

 

0
Debbie
Top achievements
Rank 1
answered on 05 Jul 2019, 03:22 PM
edit- the datasource change does fire on sort filter etc. using this looks likeit will still cause the infinite loop issue with loading saved filters that I and others have experienced
0
Eyup
Telerik team
answered on 09 Jul 2019, 11:28 AM
Hi Debbie,

You can try to wrap the saving logic within a setTimeout function to put some time delay:
https://www.w3schools.com/jsref/met_win_settimeout.asp

This should prevent the endless loop and resolve the issue. 
If the issue remains, could you prepare a basic live dojo sample to demonstrate your specific grid configuration? Then, I will modify it to demonstrate the solution and send the updated sample link back to you.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Debbie
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Debbie
Top achievements
Rank 1
Share this question
or