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

Save filter settings

I have a requirement where i would like to store user's filter setting preferences. for example on a page we have multiple grids. We want to store what filters users have applied on each grid. so next time when user will visit the page. it will show them data based on what filters they have applied on their previous visit.

Will it be possible to spin an example. where i can capture filter events and store applied filter settings from code, then probably i can save that and use it for each user on their visit. i am also open for storing filters in cookies.


PS: Please use Excel like filter while preparing example. 


3 Replies

JC Joseph Christ Nithin Issack Syncfusion Team January 28, 2023 05:12 AM UTC

Hi Parth,


   Greetings from Syncfusion support.


   Based on your query, you want to save the filter settings of the grid and use later when you reload the page. Your requirement can be achieved by using the state persistence, we have discussed the same in the below documentation. Please refer the below documentation for more details.


Documentation: https://ej2.syncfusion.com/angular/documentation/grid/state-persistence/state-persistence


Regards,

Joseph I.



PD PDev January 30, 2023 07:08 AM UTC

This will not work in case of browser has been changed or login from other machine it self... 



JC Joseph Christ Nithin Issack Syncfusion Team February 1, 2023 06:15 PM UTC

Parth,


  Based on your query, you want to save the state of the grid (after they have sorted, filtered, etc), when the next time you visit the app the grid is saved in the same state as you left it. Your requirement can be achieved by storing the settings globally or in your server along with the user name before your session in your app ends and you can fetch the stored data and restore either the entire saved settings when you visit the app again using the same user name.


 You can use the `grid.getPersistData()` method to get the persisted data. And you can use the `grid.setProperties()`  method to restore the settings to the grid.


Please refer the below code snippet.


 

public onStore() {

   this.persistData = JSON.parse(this.gridObj.getPersistData());

}

 

public onRestore() {

    // Restores the entire stored settings to the Grid

    this.gridObj.setProperties(this.persistData);

}

 


Api Link: https://ej2.syncfusion.com/angular/documentation/api/grid/#getpersistdata



Loader.
Live Chat Icon For mobile
Up arrow icon