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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Save grid configuration or state

Thread ID:

Created:

Updated:

Platform:

Replies:

141106 Nov 23,2018 05:03 PM UTC Feb 26,2021 07:35 AM UTC Angular - EJ 2 7
loading
Tags: Grid
Gleny Rodriguez
Asked On November 23, 2018 05:03 PM UTC

Hello, Basically and Trying to archive this using the JS2 with angular.

I would like to provide to my user the possibility to save several sets of grid configurations (column visibility, column size, groupings, filters, sorting etc)
So, basically the user can arrange the grid in a way he likes and then save this configuration.

For example

Configuration set A : Three grid columns visible
Configuration set B: Two grid columns visible
Configuration set C: All grid columns visible
Configuration set D: All grid columns visible with different column size
Configuration set E: All grid columns visible with  Filters, Sorts and Grouping

Could you help me with this requirement?

This is the same approach from thread Ref# 121200

Thanks.

Madhu Sudhanan P [Syncfusion]
Replied On November 28, 2018 09:38 AM UTC

Hi Gleny, 

Thanks for contacting Syncfusion support. 

Query: Save state 

You can get the grid state using the getPersistData method of the grid as follows. 


export class FilterComponent implements OnInit { 
  ... 
 
  @ViewChild('grid') 
  public grid: GridComponent; 
 
 ... 
 
  public onChange(e: ChangeEventArgs): void { 
      let data: string = this.grid.getPersistData(); //get persist data 
  } 
} 


Query: Apply state 

You can apply the state to the grid using the setProperties method as follows. 

export class FilterComponent implements OnInit { 
  ... 
 
  @ViewChild('grid') 
  public grid: GridComponent; 
 
 ... 
 
  public setState(): void { 
    let persistedData: Object; //Grid state saved in server. 
      ..... 
      this.grid.setProperties(persistedData); //get persist data 
      this.grid.refresh(); 
  } 
} 


Regards, 
Madhu Sudhanan P 


Gleny Rodriguez
Replied On December 3, 2018 04:12 PM UTC

Awesome!, It works great!

Thanks, Madhu.



Madhu Sudhanan P [Syncfusion]
Replied On December 3, 2018 04:31 PM UTC

Hi Gleny, 
We are glad that the requirement has been achieved. 
Regards, 
Madhu 


marc antoine pelletier
Replied On February 23, 2021 08:54 PM UTC

Hi ! 

im new in the Angular product.
I don't see the setProperties method in the current API of the product.

is it possible the method has been removed ?

also, I can get all the properties from the grid with getPersistData()
how I can apply this setting using current version of the grid ? is there a method ?

thank you very much !

Balaji Sekar [Syncfusion]
Replied On February 24, 2021 07:36 AM UTC

Hi Gleny, 
 
Greetings from the Syncfusion support. 
 
In Grid, setProperties as internal method so we do not explore in our API documentation and you can apply the Grid properties using this method. 
 
We checked your query with provided the information and we are unable to reproduced the reported problem. We have created a sample with your requirement as given below. 
 
 
If still facing same problem, please share the below details to us that will help to validate further. 
  1. Replicate the facing issue in above sample.
  2. Video demonstration of the problem.
  3. Ensure the Syncfusion package version.
 
Regards, 
Balaji Sekar 


marc antoine pelletier
Replied On February 25, 2021 07:49 PM UTC

It appears to be working well. 
I have one issue tough, the Header Text isn't save using the method getPersistData.
so when I copy the setting to the new grid, there is either the 'Field' that is used as Header label.
but when I use a template column (the origin column use a headerText) there is no Header Text

Source:

Target: 


But the Header is definetly defined:
<e-column headerText='Penetration'>
            <ng-template #template let-data>
                <genius-progress-tracker [progressValue]="data.Freight">
                </genius-progress-tracker>
            </ng-template>
        </e-column>
Any thoughts ?

I could use a workaround with Field="Penetration" but then again on regular columns (no template)
I only see the fieldID instead of custom texts I may have input as HeaderText...




Balaji Sekar [Syncfusion]
Replied On February 26, 2021 07:35 AM UTC

Hi Gleny, 

We have analyzed your query with provided the information and found that you need to restore the Grid header text. By default we have ignore column.headerText property while get the Grid’s properties using getPersistData method. So, we suggest you to get the Grid column’s headerText store in localStorage then restore in the Grid properties using the setProperties method.  
 
Please refer the below code example and sample for more information 
[app.component.ts] 
storeFn(args) { 
    var persistData = this.gridObj.getPersistData(); 
    var data = JSON.stringify(persistData); 
    window.localStorage.setItem("gridPersistData", data); 
    this.columns = Object.assign([], this.gridObj.columns); 
    var colValues = []; 
    // header text property of the columns are stored separately in window local storage 
    this.columns.forEach(col => colValues.push({ headerText: col.headerText })); 
    window.localStorage.setItem("gridCol", JSON.stringify(colValues)); 
  } 
  resetFn(args) { 
    var getPersistedData = JSON.parse( 
      window.localStorage.getItem("gridPersistData") 
    ); 
    var persistData = JSON.parse(getPersistedData); 
    var colsData = JSON.parse(window.localStorage.getItem("gridCol")); 
    if (persistData) { 
      var i = 0; 
      // Header text properties of the stored data is restored to the persisted column object 
      while (< persistData.columns.length) { 
        persistData.columns[i].headerText = colsData[i].headerText; 
        i++; 
      } 
      console.log("setting grid: ", persistData, this.columns); 
      this.gridObj.setProperties(persistData); 
    } 
  } 


Please get back to us, if you need further assistance. 

Regards, 
Balaji Sekar 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon