Grid state persistence. Do not persist columns that are not bound to the dataset fields.

Hi!

I'm using the getPersistData method for storing grid configuration in the database.

Here is the column definition:


The last column is just for placing icons and I don't want to persist it.

For now, I'm using a little workaround, just filtering columns where the 'field' property is not undefined.

Is there any approach to prevent persisting columns that are not bound to the dataset fields using an in-built way?

Thanks!




3 Replies

MS Manivel Sellamuthu Syncfusion Team August 31, 2021 01:41 PM UTC

Hi Ivan, 

Greetings from Syncfusion support. 

By default in Grid, while using getPersistData method of  the Grid will return all the columns defined the in the grid. The templates will not be retained in the persisted columns. Could you please share the below details which will be helpful for to validate your requirement further. 

  1. Do you want to exclude the columns, that has not defined the field value
  2. Do you want to exclude the template columns from the persisted columns
  3. Share the complete Grid code
  4. Please explain more about your requirement

Regards, 
Manivel 



IK Ivan Kroshko replied to Manivel Sellamuthu September 16, 2021 12:54 PM UTC

Hi Manivel!
Thank you for your reply!

I think that it's enough to answer only the first question because it completely covers my requirement :)
What do you recommend in this case?

Thanks!



PG Praveenkumar Gajendiran Syncfusion Team September 17, 2021 11:06 AM UTC

Hi Ivan,  
  
Thanks for your update. 
  
As we already informed, that the persist data does not contain/store the properties like, column template, column formatter, headerText since these values can be mapped as id or method that is defined in the application level or even modified and hence cannot be maintained. 
  
So if you wish to restore all these column properties then you can achieve it by cloning the grid’s columns property using JavaScript Object’s assign method and storing this along with the persist data manually and while restoring the settings, this column object needs to be assigned to the grid’s columns property to restore the column settings as demonstrated in the below code snippet,  
  
//  Button click function for storing Grid settings  
btn1.element.onclick = function () { 
        savedProperties = Object.assign([], JSON.parse(grid.getPersistData())); 
        var gridColumnsState = Object.assign([], grid.getColumns()); 
        savedProperties.columns.forEach( col => {  
        let headerText = gridColumnsState.find((colColumnsState) => colColumnsState.field === col.field)['headerText']; 
        let filterType = Object.assign({}, gridColumnsState.find((colColumnsState) => colColumnsState.field === col.field)['filter']); 
        let colTemplate = gridColumnsState.find((colColumnsState) => colColumnsState.field === col.field)['template']; 
        col.headerText = headerText; 
        col.filter = filterType; 
        col.template = colTemplate; 
       //likewise you can restore required column properties as per your wants. 
      }) 
    } 
   
We need the following details to understand your scenario better at our end. So kindly share the following details.  
  1. Do you have the columns without field property in the Grid?
  2. If so, please share that  non field columns details and what are action do you like to perform in that columns?
Note: “By default in the EJ2 Grid, Grid’s columns action are preformed based on the column field property value”

Please get back to us with the requested details which will be helpful for us to validate the reported scenario at our end and provide the solution as early as possible 

Regards 
Praveenkumar G 


Loader.
Up arrow icon