Skip to content

Commit 67f332b

Browse files
committed
fix(grid-state): await columns loaded to restore state
1 parent 89defd2 commit 67f332b

File tree

1 file changed

+14
-3
lines changed
  • samples/grids/grid/state-persistence-main/src

1 file changed

+14
-3
lines changed

samples/grids/grid/state-persistence-main/src/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class Sample {
1818
private gridData;
1919
private grid: IgcGridComponent;
2020
private gridState: IgcGridStateComponent;
21+
private columnsLoaded: Promise<void>;
2122
public stateKey = 'grid-state';
2223

2324
public options: IgcGridStateOptions = {
@@ -58,13 +59,14 @@ export class Sample {
5859
registerIconFromText("forward", forwardIcon, "material");
5960
registerIconFromText("delete", deleteIcon, "material");
6061
registerIconFromText("refresh", refreshIcon, "material");
61-
62+
6263
grid.data = this.gridData;
6364
grid.allowAdvancedFiltering = true;
6465
grid.filterMode = 'excelStyleFilter';
6566
grid.columnSelection = 'multiple';
6667
grid.rowSelection = 'multiple';
67-
68+
69+
grid.addEventListener("columnInit", (ev: any) => { this.onColumnInit(ev); });
6870
saveStateBtn.addEventListener('click', (ev: any) => { this.saveGridState(); });
6971
restoreStateBtn.addEventListener('click', (ev: any) => { this.restoreGridState(); });
7072
resetStateBtn.addEventListener('click', (ev: any) => { this.resetGridState(); });
@@ -77,7 +79,10 @@ export class Sample {
7779
cb.addEventListener("igcChange", (ev: CustomEvent) => { this.onChange(ev, cb.id); });
7880
});
7981

80-
window.addEventListener("load", () => { this.restoreGridState(); })
82+
window.addEventListener("load", async () => {
83+
await this.columnsLoaded;
84+
this.restoreGridState();
85+
});
8186
window.addEventListener("beforeunload", () => { this.saveGridState(); });
8287
}
8388
this._bind();
@@ -134,6 +139,12 @@ export class Sample {
134139
public reloadPage() {
135140
window.location.reload();
136141
}
142+
143+
private onColumnInit(event: any) {
144+
if(event.detail.index === this.grid.columns.length - 1) {
145+
this.columnsLoaded = new Promise((resolve) => resolve());
146+
}
147+
}
137148
}
138149

139150
new Sample();

0 commit comments

Comments
 (0)