Posted 15 October 2021, 6:00 pm EST - Updated 3 October 2022, 12:22 pm EST
Hello
I just got a license for Wijmo primarily because of the FlexGrid. I run it in a React app.
In order to format dates, I use cellTemplate and a custom formatter since I couldn’t get the inbuilt formatter to work with custom formats. Also, I use state persistence.
The problem is that every column persists their state correctly, except for the date columns, which show the unformatted date string when the persisted state is loaded. I understand that the cellTemplate doesn’t aplly in persistence through the columnLayout property, and I would like to know if there is any possible workaround.
Before persist (with cellTemplate)
Persisted state loaded
Code used for setting cellTemplate
// {Example} c = { dateFormat: "DD/MM/YYYY HH:mm:ss", field: "DATA_CADASTRO" }
// defaultFormats[c.field] = "YYYY-MM-DDTHH:mm:ss"
col.dataType = DataType.Date;
col.format = c.dateFormat;
col.cellTemplate = (ctx) =>
ctx.value
? moment(ctx.value, defaultFormats[c.field]).format(c.dateFormat)
: "";
Code for saving state
let state = {
columns: this.grid.columnLayout,
filterDefinition: this.state.gridFilter.filterDefinition,
sortDescriptions: this.grid.collectionView.sortDescriptions.map(
(sortDesc) => ({
property: sortDesc.property,
ascending: sortDesc.ascending,
})
),
};
localStorage.setItem(`${this.props.id}_gridState`, JSON.stringify(state));