Skip to content

Commit

Permalink
Merge branch 'feature/allow-update-rows' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Dec 4, 2024
2 parents 6de16c0 + 9a696c6 commit c275067
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/InfiniteTable/InfiniteTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export type InfiniteTableRef = {
setSelectedRows: (keys: number[]) => void;
unselectAll: () => void;
refresh: () => void;
updateRows: (updates: Array<Record<string, any>>) => void;
getVisibleRowIds: () => string[];
};

const InfiniteTableComp = forwardRef<InfiniteTableRef, InfiniteTableProps>(
Expand Down Expand Up @@ -147,6 +149,24 @@ const InfiniteTableComp = forwardRef<InfiniteTableRef, InfiniteTableProps>(
gridRef.current?.api?.deselectAll();
gridRef.current?.api?.purgeInfiniteCache();
},
updateRows: (updates: Array<Record<string, any>>) => {
if (!gridRef.current?.api) return;

updates.forEach((update) => {
const node = gridRef.current?.api
.getRenderedNodes()
.find((node) => node.data.id === update.id);
if (node) {
// Update specific fields without refreshing entire row
node.setData({ ...node.data, ...update });
}
});
},
getVisibleRowIds: () => {
if (!gridRef.current?.api) return [];
const visibleNodes = gridRef.current.api.getRenderedNodes();
return visibleNodes.map((node) => node?.data?.id);
},
}));

const columns = useDeepArrayMemo(columnsProps, "key");
Expand Down

0 comments on commit c275067

Please sign in to comment.