Skip to content

Commit 3b267d8

Browse files
authored
[DataGridPro] Retain the expansion state with expansion configuration props (#20126)
1 parent d1dd176 commit 3b267d8

File tree

1 file changed

+7
-3
lines changed
  • packages/x-data-grid-pro/src/utils/tree

1 file changed

+7
-3
lines changed

packages/x-data-grid-pro/src/utils/tree/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,20 @@ export const checkGroupChildrenExpansion = (
5757
return false;
5858
}
5959

60+
// If group existed in previous tree, preserve its expansion state
61+
if (prevChildrenExpanded !== undefined) {
62+
return prevChildrenExpanded;
63+
}
64+
65+
// For new groups, apply default expansion configuration
6066
let childrenExpanded: boolean;
6167
if (node.id === GRID_ROOT_GROUP_ID) {
6268
childrenExpanded = true;
6369
} else if (isGroupExpandedByDefault) {
6470
childrenExpanded = isGroupExpandedByDefault(node);
6571
} else {
6672
childrenExpanded =
67-
defaultGroupingExpansionDepth === -1 ||
68-
defaultGroupingExpansionDepth > node.depth ||
69-
(prevChildrenExpanded ?? false);
73+
defaultGroupingExpansionDepth === -1 || defaultGroupingExpansionDepth > node.depth;
7074
}
7175

7276
return childrenExpanded;

0 commit comments

Comments
 (0)