Skip to content

Commit

Permalink
fix: stale data being used by boolean editor (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
matttdawson authored Oct 29, 2024
1 parent 1ad25a9 commit 79ee1e2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/gridPopoverEdit/GridEditBoolean.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ const BooleanCellRenderer = (props: CustomCellEditorProps) => {
if (!onValueChange) return;
const params = props?.colDef?.cellEditorParams as GridEditBooleanEditorProps<any> | undefined;
if (!params) return;
const selectedRows = [data];
// The data cannot be relied upon if grid changed whilst editing, data will be stale
// So I get the data from the node itself which will be up to date.
const selectedRows: { id: string | number }[] = [];
api.forEachNode((n) => {
if (n.data.id === data.id) {
selectedRows.push(n.data);
}
});

const checked = !value;
onValueChange(checked);
params.onClick({ selectedRows, selectedRowIds: selectedRows.map((r) => r.id), checked }).then();
Expand Down

0 comments on commit 79ee1e2

Please sign in to comment.