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

How to disable persistence from JavaScript?

How can I disable persistence in grid (or other control) from JavaScript?
I have a button with onclick event, in which I want to disable persistence and refresh page.
My current code:
function btnClick()
{
window.localStorage.setItem("gridMyGrid","");
location.rel='nofollow' href = "/Card/List";
}
I clear localstorage for grid control, but after page reload localstorage is set again (because grid control set persistence data in unload event).
So maybe I need to disable persistence in grid control before page reload. But how?
I tried:
var ej2Obj = document.getElementById('MyGrid').ej2_instances[0];
ej2Obj.persistence = false;
(also ej2Obj.enablePersistence = false;)
but it didn't work.

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 9, 2019 12:28 PM UTC

Hi Adgr, 
 
Based on your query, we can understand that you wish to clear the Grid’s persisted data from local storage while refreshing the page through button click event. You can achieve this requirement by destroying the grid after disabling the enablePersistence property and clearing the local storage data. This is demonstrated in the below code snippet, 
 
// Button click function 
function OnClick() { 
            var gridObj = document.getElementById("Grid").ej2_instances[0]; 
            gridObj.enablePersistence = false; 
            window.localStorage.setItem("gridGrid", ""); 
            gridObj.destroy(); 
            location.reload(); 
} 
 
We have prepared a sample based on this for your reference. You can find it below, 
 
 
Regards,  
Seeni Sakthi Kumar S 



SS Steve Skok June 16, 2021 09:12 AM UTC

By default persistence disabled. That's why you write:

    AngularFireModule.initializeApp(credentials),
    AngularFirestoreModule,

you get disabled persistence.

To enable persistence you must write:

    AngularFireModule.initializeApp(credentials),
    AngularFirestoreModule.enablePersistence(),

That's why you nothing to do for disabled persistence in your case.



RR Rajapandi Ravi Syncfusion Team June 17, 2021 12:11 PM UTC

Hi Steve, 

Thanks for the update 

By default, Grid’s state maintained in the browser’s localStorage even if the browser is refreshed or if you move to the next page within the browser. State persistence stores grid’s model object in the local storage when the enablePersistence is defined as true. Please refer the below documentation for more information. 


We are not able to understand your requirement. So please share the below details that would be helpful for us to provide better solution. 

1)      Please share your exact requirement with detailed description. 

Regards, 
Rajapandi R

Loader.
Live Chat Icon For mobile
Up arrow icon