Persistence issue with filters on grid

Am using version 19.2.51.

I persist the grid data like this: 

     let persistGridData = this.$refs.reportGrid.ej2Instances.getPersistData();          

     window.localStorage.setItem("GridData", persistGridData);


And I assign it back to the grid like this:

 let savedPersistGridData = window.localStorage.getItem("GridData"); 

 if (savedPersistGridData) {
     grid.ej2Instances.setProperties(JSON.parse(savedPersistGridData)); 
 }


Now that second bit of code is called multiple times. Each time the user asks for some new data, the grid dataSource is set to the new items and then this code is called to make sure the autogenerated columns match what the user had re-arranged previously. All works wonderfully. 

Except...

when I set a filter on a column. The filter is applied on the grid and I persist the grid details. If I refresh the page and call the setProperties on the first set of data, it is displayed with the filter applied as required. However, if I ask for new data and call setProperties again then I get an error:


vue.js:1897 TypeError: Cannot read property 'querySelector' of undefined    
at e.addFilteredClass (ej2-vue.min.js:1)    
at e.refreshFilterIcon (ej2-vue.min.js:1)    
at e.updateFilter (ej2-vue.min.js:1)    
at e.onPropertyChanged (ej2-vue.min.js:1)    
at e.notify (ej2-vue.min.js:1)    
at t.notify (ej2-vue.min.js:1)    
at t.extendedPropertyChange (ej2-vue.min.js:1)    
at t.onPropertyChanged (ej2-vue.min.js:1)    
at t.e.dataBind (ej2-vue.min.js:1)    
at t.dataBind (ej2-vue.min.js:1)


This only occurs if i have a filter property set. 

Regards

Je






1 Reply

SK Sujith Kumar Rajkumar Syncfusion Team August 6, 2021 06:41 AM UTC

Hi Jeff, 
 
Greetings from Syncfusion support. 
 
We checked the reported problem but unfortunately were unable to reproduce it from our end as the persisted filter settings was restored properly using the setProperties method. You can check the below sample for reference, 
 
 
From this information – “However, if I ask for new data and call setProperties again then I get an error:”, we suspect that you are fetching a new set of data with column fields that are not present in the previous Grid settings with which the filter persistence is stored. If so, since the previous filter column is not present the Grid is trying to apply the filter for the unavailable column(in the new set of data) and because of the reported error is getting thrown. For e.g., Consider a previous filter is applied for ‘ShipCountry’ column based on which the filter settings is stored in the persisted data and a new set of data that is assigned to the Grid does not have ‘ShipCountry’ column, then the Grid will throw error when trying to restore filter settings for a column that is not present in the Grid. This is its default behavior. 
 
So we suggest you to resolve this problem by ensuring if the previously persisted column field is presently in the new data before restoring the persisted filter settings. 
 
Let us know if you have any concerns. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon