We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

EnablePersistence saving event handlers

I have a grid that is setup in a RAZOR view and I want to save it's state to keep filtering intact after leaving the page. However, I noticed and interesting issue that my event handlers are being persisted so if myself or a client have used the grid before and a change is made to the event handlers the grid will fail to work as expected. I need a way to enable persistence but exclude event handlers from this persistence. As well I need a solution that can work on any grid instance as I have many grids that I want to enable persistence on.

5 Replies

AS Alan Sangeeth S Syncfusion Team July 3, 2017 10:58 AM UTC

Hi Andrew, 

In Grid control, by default we have not included some properties while maintaining Grid State. To exclude other properties from maintaining its state use ignoreOnPersist Grid method. Please refer to the following code example. 

var gridObj = $("#Grid").ejGrid("instance");//get the gridObject 
gridObj.ignoreOnPersist(["actionBegin", "actionComplete"]);// set the properties that are to be prevented from being persisted 

Please refer to the following documentation links for further reference. 

Alan Sangeeth S 

AN Andrew July 5, 2017 01:42 PM UTC

Thanks Alan!

Is there a way to set those as defaults? My concern with that is if I set that after the page has loaded and the grid setup via the unobtrusive JavaScrip it will have already loaded the previous event handlers. Ideally I'd like a way to either set this via RAZOR or set the default values for this.

RS Renjith Singh Rajendran Syncfusion Team July 6, 2017 12:53 PM UTC

Hi Andrew, 

We have achieved state maintenance in grid using browser local storage. When loading the grid sample at first time, there will be no event handlers in local storage and so the persistence functionality will not override the events in the grid for the very first time. So at that time in Grid “load” event, we have added the grid events to ignoreOnPersist list.  
Hence after refreshing the page also,  the events will not overridden from the local storage since it has been ignored.  
Renjith Singh Rajendran. 

AN Andrew July 15, 2017 03:21 PM UTC

I ended up finding a solution after a lot of trial and error and by inspecting the Grid object in a debugger. As mentioned I have many grids and I didn't want to have to add a method on document load for every single one of them. I found I could modify the prototype for the Grid and add what I needed to the _ignoreOnPersist array. Doing it this way, every grid that gets created ignores the correct items by default. I don't have the code in front of me but it should be:

ej.Grid.prototype._ignoreOnPersist = ej.Grid.prototype._ignoreOnPersist.concat([/*Items that need to be ignored by default*/]);

TS Thavasianand Sankaranarayanan Syncfusion Team July 17, 2017 12:58 PM UTC

Hi Andrew, 

Thanks for your update. 

You can proceed with your solution. 

If you need further assistance on this, then please get back to us.  

Thavasianand S. 

Live Chat Icon For mobile
Up arrow icon