From 79ee1e2e7a619edcdff51c160446d1162ca96c7e Mon Sep 17 00:00:00 2001 From: matttdawson <89495499+matttdawson@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:00:58 +1300 Subject: [PATCH] fix: stale data being used by boolean editor (#509) --- src/components/gridPopoverEdit/GridEditBoolean.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/gridPopoverEdit/GridEditBoolean.tsx b/src/components/gridPopoverEdit/GridEditBoolean.tsx index 6e5a66c5..5cf929f4 100644 --- a/src/components/gridPopoverEdit/GridEditBoolean.tsx +++ b/src/components/gridPopoverEdit/GridEditBoolean.tsx @@ -47,7 +47,15 @@ const BooleanCellRenderer = (props: CustomCellEditorProps) => { if (!onValueChange) return; const params = props?.colDef?.cellEditorParams as GridEditBooleanEditorProps | 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();