From b0fde6190f5a278d83f180e5256c6a6454001374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Tue, 15 Oct 2024 12:32:35 +0200 Subject: [PATCH] fix: clear selected rows when a refresh is done Fixes: https://github.com/gisce/webclient/issues/1289 --- src/components/InfiniteTable/InfiniteTable.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/InfiniteTable/InfiniteTable.tsx b/src/components/InfiniteTable/InfiniteTable.tsx index 6491de7..205c017 100644 --- a/src/components/InfiniteTable/InfiniteTable.tsx +++ b/src/components/InfiniteTable/InfiniteTable.tsx @@ -106,7 +106,7 @@ const InfiniteTableComp = forwardRef( const notifyColumnChanges = useRef(false); const firstTimeResized = useRef(false); - useDeepCompareEffect(() => { + const updateSelectedRowKeys = useCallback(() => { gridRef.current?.api?.forEachNode((node) => { if (node?.data?.id && selectedRowKeys.includes(node.data.id)) { node.setSelected(true); @@ -116,6 +116,10 @@ const InfiniteTableComp = forwardRef( }); }, [selectedRowKeys]); + useDeepCompareEffect(() => { + updateSelectedRowKeys(); + }, [selectedRowKeys]); + useImperativeHandle(ref, () => ({ setSelectedRows: (keys: number[]) => { gridRef.current?.api?.forEachNode((node) => { @@ -130,6 +134,7 @@ const InfiniteTableComp = forwardRef( gridRef.current?.api?.deselectAll(); }, refresh: () => { + gridRef.current?.api?.deselectAll(); gridRef.current?.api?.purgeInfiniteCache(); }, })); @@ -383,6 +388,7 @@ const InfiniteTableComp = forwardRef( selectedRowKeys, columnsPersistedStateRef, memoizedOnRowStatus, + updateSelectedRowKeys, applyAutoFitState, scrollToSavedPosition, ],