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 and Update Grid state in localstorage with data fetched from an Rest API

We created a DTO to only save the Width, Visibility and the TextAlign in the format of an Array for each column.
But we're stuck trying to update the columns saved in local storage with the data fetched from the API

THE ARRAY WITH API DATA:
Captura de Tela 2023-04-13 às 10.56.59.png

THE DATA WE'RE BEING USING (grid.columns)
PRINT.png

SUMMARY: We're trying save and update the grid state with data fetched from the API, but we're only using textAlign, visible and width for that.

1 Reply 1 reply marked as answer

PS Pavithra Subramaniyam Syncfusion Team April 14, 2023 05:34 AM UTC

Hi Fernando Pestillo,


Thanks for contacting Syncfusion support.


From your query, we understood that you want to set the width, visibility and text align properties which are obtained from an API request to the Grid columns while it is rendering. If yes, you can achieve your requirement by setting the columns with the new properties using the “changeDataSource” method which provides an option to made changes to the Grid columns.


https://ej2.syncfusion.com/angular/documentation/api/grid/#changedatasource


public ColValueFromAPIobject[] = [

  ['30%'true'Center'],

  ['80%'true''],

  ['80%'true''],

  ['80%'true''],

  ['80%'true'Center'],

];

 

 

created(args) {

  if (this.isInitial) {

    this.isInitial = false;

    var newColumns = this.grid.columns;

    newColumns.filter((e: any, i: number) => {

      e.width = this.ColValueFromAPI[i][0];

      e.visible = this.ColValueFromAPI[i][1];

      e.textAlign = this.ColValueFromAPI[i][2];

    });

    this.grid.changeDataSource(null, newColumns);

  }

}

 


Sample: https://stackblitz.com/edit/angular-myg5at?file=src%2Fapp.component.ts


If this is not your requirement, please share the Grid code example and a video of explaining your current behavior and expected result which will be helpful for us to provide a better solution as early as possible.


Regards,

Pavithra S


Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon