Automatic grid persistence and load example

5 posts, 0 answers
  1. Debbie
    Debbie avatar
    8 posts
    Member since:
    Jun 2019

    Posted 03 Jul 2019 Link to this post

    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.

     

  2. Eyup
    Admin
    Eyup avatar
    4046 posts

    Posted 04 Jul 2019 Link to this post

    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.
  3. Debbie
    Debbie avatar
    8 posts
    Member since:
    Jun 2019

    Posted 05 Jul 2019 in reply to Eyup Link to this post

    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.

     

  4. Debbie
    Debbie avatar
    8 posts
    Member since:
    Jun 2019

    Posted 05 Jul 2019 in reply to Debbie Link to this post

    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
  5. Eyup
    Admin
    Eyup avatar
    4046 posts

    Posted 09 Jul 2019 Link to this post

    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.
Back to Top