Columns Headertext when loading persistence back to the grid
|
var savedProperties;
document.getElementById('save').addEventListener('click', function (args) {
// Persist data is stored in a global variable
savedProperties = JSON.parse(this.$refs.grid.ej2Instances.getPersistData());
});
document.getElementById('restore').addEventListener('click', function (args) {
// Stored persist data is restored to the grid
this.$refs.grid.ej2Instances.setProperties(savedProperties);
}); |
|
var savedProperties;
var savedColumns;
document.getElementById('save').addEventListener('click', function (args) {
// Persist data and column model are stored in global variable
savedProperties = JSON.parse(this.$refs.grid.ej2Instances.getPersistData());
savedColumns = Object.assign([],this.$refs.grid.ej2Instances.columns);
});
document.getElementById('restore').addEventListener('click', function (args) {
// Stored persist data and column model are restored to the grid
this.$refs.grid.ej2Instances.setProperties(savedProperties);
var restoreCols = Object.assign([], savedColumns);
this.$refs.grid.ej2Instances.columns = restoreCols;
}); |
at VueComponent.rowSelected (VM2546 mycodepage.vue:448)
at Observer.notify (observer.js?811a:99)
at Grid.Base.trigger (base.js?3923:181)
at VueComponent.GridComponent.trigger (grid.component.js?c041:85)
at Selection.onActionComplete (selection.js?afc0:100)
at Selection.selectRowCallBack (selection.js?afc0:295)
at Selection.clearRowSelection (selection.js?afc0:760)
at Selection.clearRow (selection.js?afc0:537)
at Observer.eval (selection.js?afc0:254)
at Observer.notify (observer.js?811a:102)
- Delete package.lock.json file from your application.
- Remove the @syncfusion package folder from the node_modules.
- Use same version for all components in package.json file.
- Then install the new packages.
- allowEditing: true
- allowFiltering: true
- allowGrouping: true
- allowReordering: true
- allowResizing: true
- allowSearching: true
- allowSorting: true
- autoFit: false
- disableHtmlEncode: true
- enableGroupByFormat: false
- field: "field1"
- foreignKeyField: "field1"
- index: 9
- showColumnMenu: true
- showInColumnChooser: true
- sortDirection: "Descending"
- textAlign: "center"
- type: "string"
- uid: "grid-column9"
- visible: true
- Please share the package.json file of your angular application and the one that is present inside the node_modules/@syncfusion/ej2-grids folder of the angular application.
- Can you please check with the sample provided above and let us know if it achieves your requirement.
- Since you have enabled persistence in the Grid we suspect the old grid settings from cached memory are getting restored causing the reported problem. As the persist settings are manually restored here we suggest you to remove the enablePersistence property set in the Grid, clear the local browser cache and then run your application to see if the problem is resolved.
- Grid code file.
- If possible provide us a simple sample to replicate problem or try reproducing it in the above provided sample.
|
var colValues;
document.getElementById("save").addEventListener("click", args => {
.
.
colObject = Object.assign([], grid.columns);
colObject.filter((col) => colValues.push({ "template": col.template, "headerText": col.headerText }))
savedColumns = JSON.stringify(colObject);
});
document.getElementById("restore").addEventListener("click", args => {
var columnObj = JSON.parse(savedColumns);
var i = 0;
while (i < columnObj.length) {
columnObj[i].template = colValues[i].template;
columnObj[i].headerText = colValues[i].headerText;
i++;
}
grid.setProperties(savedProperties);
grid.columns = columnObj;
}); |
I want to make sure I understand the concept:
1. The user goes to the windows with the grid. The first thing I do is store the columns' headerText, template and ValueAccessor in the localstorage as json.
colObject = Object.assign([], grid.columns);
colObject.filter((col) => colValues.push({ "template": col.template, "headerText": col.headerText }))
colValues should be stored as json into the localstorage
2. The user reorder the columns, sort column X and save this view (name: test) . I should save the persistData() (which is a string) to the db.
3. The user logs out and after a day he logs in.
4. The user go to the window with the grid. When that happens, point 1 above happens again, meaning updating localstorage with the 3 properties of all columns.
5. The user is selecting to show view "test". I take the persistData I stored previously and do .setProperties(...). This will change the grid columns (order/sort) but without headerText, template and valueaccessor.
6. I then should take the json from localStorage (point1) and update the columns:
var i = 0;
while (i < columnObj.length) {
columnObj[i].template = colValues[i].template;
columnObj[i].headerText = colValues[i].headerText;
i++;
}
question 1: Because getPersistData already contains the columns object, in the right order/sort, there is no need to store also the column, right?
question 2: Because the user enters the window with the default view but he can save as many views as he wants, the order of the columns may be different between the views and the columns order from point 1 (localstorage). How can I make sure that the correct column gets the correct template/headerText/ValueAccessor? Maybe based on the field name of the column?
question 3: If later on I will add a new column to the grid that was not saved in getPersistData, how will the grid behave after .setProperties(...) of an object without this new column?
Thanks
|
colObject.filter((col) => colValues.push({ "template": col.template, "headerText": col.headerText, "field": col.field, "valAcc": col.valueAccessor })) |
|
var initialAdd = true;
// Add new columns button click
document.getElementById('add').addEventListener('click', function(args) {
if (initialAdd) {
// New column is added to the Grid
grid.columns.push({ field: 'CustomerID', headerText: 'Customer ID' });
grid.refreshColumns();
initialAdd = false;
}
});
// Merge columns button click
document.getElementById('merge').addEventListener('click', function(args) {
// Initially persisted data
var persistData1 = JSON.parse(persistData);
// Grid column object is converted to array of column object
gridColumns = Object.entries(gridColumns).map(e => e[1]);
persistData1.columns[3].headerText = "Amount";
// Grid column object is extended with persisted columns
var newData = ej.base.extend(gridColumns, persistData1.columns);
// The extended data is assigned to the Grid columns
grid.setProperties({ columns: JSON.parse(JSON.stringify(newData)) })
}); |


style="height: 60px" looks like a hardcoded thing, maybe searching for it in your code can give a hint on when it is added... Just a thought.
- The column model not getting properly generated on restoring the column object which replaces the property values dynamically to the Grid.
- The stored or restored column object might be containing reference to older values which might cause problems in column generation in the Grid.
|
saveBtnClick: function() {
// Persist data and column model are stored in global variable
this.savedProperties = [];
this.savedColumns = [];
this.savedProperties = Object.assign([], JSON.parse(this.$refs.grid.ej2Instances.getPersistData()));
this.savedColumns = Object.assign([], this.$refs.grid.ej2Instances.columns);
},
restoreBtnClick: function() {
// Stored persist data and column model are restored to the grid
this.$refs.grid.ej2Instances.setProperties(this.savedProperties);
this.$refs.grid.ej2Instances.columns = Object.assign([], this.savedColumns);
} |

- Let us know the actions that you are performing in the Grid which is causing your reported problem case.
- Video demonstration of the problem to understand it better.
- Have you bound local or remote data to the Grid?
- Grid code file.
- Syncfusion package version used.
- If possible share us a simple sample to replicate the problem.
Amos with this methodology do you have any issues with capturing the default view and columns if the user is directly navigating to a saved version of the grid first and switching to the default view after?
- 32 Replies
- 3 Participants
-
AM Amos
- May 18, 2020 08:48 AM UTC
- Oct 22, 2021 12:11 AM UTC