Skip to content

Commit

Permalink
fix: clear selected rows when a refresh is done (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra authored Oct 15, 2024
1 parent d437219 commit 925332d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/InfiniteTable/InfiniteTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const InfiniteTableComp = forwardRef<InfiniteTableRef, InfiniteTableProps>(
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);
Expand All @@ -116,6 +116,10 @@ const InfiniteTableComp = forwardRef<InfiniteTableRef, InfiniteTableProps>(
});
}, [selectedRowKeys]);

useDeepCompareEffect(() => {
updateSelectedRowKeys();
}, [selectedRowKeys]);

useImperativeHandle(ref, () => ({
setSelectedRows: (keys: number[]) => {
gridRef.current?.api?.forEachNode((node) => {
Expand All @@ -130,6 +134,7 @@ const InfiniteTableComp = forwardRef<InfiniteTableRef, InfiniteTableProps>(
gridRef.current?.api?.deselectAll();
},
refresh: () => {
gridRef.current?.api?.deselectAll();
gridRef.current?.api?.purgeInfiniteCache();
},
}));
Expand Down Expand Up @@ -383,6 +388,7 @@ const InfiniteTableComp = forwardRef<InfiniteTableRef, InfiniteTableProps>(
selectedRowKeys,
columnsPersistedStateRef,
memoizedOnRowStatus,
updateSelectedRowKeys,
applyAutoFitState,
scrollToSavedPosition,
],
Expand Down

0 comments on commit 925332d

Please sign in to comment.