Skip to content
This repository was archived by the owner on Jun 28, 2026. It is now read-only.

Commit f7e1e9d

Browse files
Fix: Datatable row expansion bug (#8039)
* Create cell memoization options in datatable props, including detailed documentation * Prettier * Fixed TS error * Fixed TS error * Update datatable.d.ts * Created ref for expandedRows in TableBody.js so that the onRowToggle runs with the most updated value --------- Co-authored-by: Melloware <mellowaredev@gmail.com>
1 parent b07b650 commit f7e1e9d

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

components/lib/datatable/TableBody.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,12 @@ export const TableBody = React.memo(
629629
}
630630
};
631631

632+
const expandedRowsRef = React.useRef(props.expandedRows);
633+
634+
React.useEffect(() => {
635+
expandedRowsRef.current = props.expandedRows;
636+
}, [props.expandedRows]);
637+
632638
const onRowToggle = (event) => {
633639
let expandedRows;
634640
let dataKey = props.dataKey;
@@ -637,7 +643,7 @@ export const TableBody = React.memo(
637643
if (hasDataKey) {
638644
let dataKeyValue = String(ObjectUtils.resolveFieldData(event.data, dataKey));
639645

640-
expandedRows = props.expandedRows ? { ...props.expandedRows } : {};
646+
expandedRows = expandedRowsRef.current ? { ...expandedRowsRef.current } : {};
641647

642648
if (expandedRows[dataKeyValue] != null) {
643649
delete expandedRows[dataKeyValue];
@@ -653,9 +659,9 @@ export const TableBody = React.memo(
653659
}
654660
}
655661
} else {
656-
let expandedRowIndex = findIndex(props.expandedRows, event.data);
662+
let expandedRowIndex = findIndex(expandedRowsRef.current, event.data);
657663

658-
expandedRows = props.expandedRows ? [...props.expandedRows] : [];
664+
expandedRows = expandedRowsRef.current ? [...expandedRowsRef.current] : [];
659665

660666
if (expandedRowIndex !== -1) {
661667
expandedRows = expandedRows.filter((_, i) => i !== expandedRowIndex);

0 commit comments

Comments
 (0)