From 13bff5e3f38c403f4febb6dd6ac213b5c31ddb46 Mon Sep 17 00:00:00 2001 From: Dominic Leung Date: Sun, 29 Sep 2024 18:11:34 +0800 Subject: [PATCH] try to badd back open groups --- app/src/components/grid/gridStates.ts | 32 ++++++++------------------- app/src/components/grid/stdGrid.tsx | 4 ++-- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/app/src/components/grid/gridStates.ts b/app/src/components/grid/gridStates.ts index a81ddb0..63e43ab 100644 --- a/app/src/components/grid/gridStates.ts +++ b/app/src/components/grid/gridStates.ts @@ -9,7 +9,7 @@ export async function initStateTable() { const query = ` CREATE TABLE IF NOT EXISTS grid_states_test ( table_name VARCHAR, - userSaved VARCHAR DEFAULT 'false', -- Added for Memory Store (MS) and Memory Recall (MV) + userSaved VARCHAR, -- Added for Memory Store (MS) and Memory Recall (MV) state VARCHAR, columnState VARCHAR, PRIMARY KEY (table_name, userSaved) @@ -25,7 +25,7 @@ export function fetchPreviousState(tableName: string) { const query = ` SELECT table_name, state, columnState FROM grid_states_test WHERE table_name = '${tableName}' - AND userSaved = 'false'; + AND userSaved = 'auto'; `; const arrowResult = await connection.query(query); const result = arrowResult.toArray().map((row) => row.toJSON()); @@ -94,27 +94,13 @@ export async function applySavedState( gridApi.setFilterModel(gridState.filter.filterModel); } - // await new Promise((resolve) => { - // gridApi.forEachNode((node) => { - // if (node.group) { - // console.log("leudom node", node.key); - // node.setExpanded(true); - // } - // }); - // resolve(); - // }); - - // Set Row Group Expansion - // if ( - // gridState.rowGroupExpansion && - // Array.isArray(gridState.rowGroupExpansion) - // ) { - // gridApi.forEachNode((node) => { - // if (gridState.rowGroupExpansion.includes(node.key)) { - // node.setExpanded(true); - // } - // }); - // } + // Open groups + const openGroups = gridState.rowGroupExpansion.expandedRowGroupIds; + gridApi.forEachNode((node) => { + if (openGroups.includes(node.id)) { + node.setExpanded(true); + } + }); } } diff --git a/app/src/components/grid/stdGrid.tsx b/app/src/components/grid/stdGrid.tsx index 997c590..18d059c 100644 --- a/app/src/components/grid/stdGrid.tsx +++ b/app/src/components/grid/stdGrid.tsx @@ -272,7 +272,7 @@ const StdAgGrid: React.FC = (props) => { }; const onFirstDataRendered = useCallback( - (params: any) => { + async (params: any) => { const endTime = performance.now(); const execTime = endTime - startTime.current; setExecTime(execTime); @@ -280,7 +280,7 @@ const StdAgGrid: React.FC = (props) => { // States initStateTable(); // Create table if not exists. - applySavedState(gridApi, props.tableName, "auto"); + await applySavedState(gridApi, props.tableName, "auto"); }, [gridApi], );