Skip to content

Conversation

MBilalShafi
Copy link
Member

@MBilalShafi MBilalShafi commented Sep 24, 2025

Fixes #13064

Tree data example: https://stackblitz.com/edit/4ug6uohs
Row grouping example: https://stackblitz.com/edit/nqsdch2j

Main Fix

The createRowTree() pre processing passes down a previousTree param to the node generator methods, childrenExpanded value is now reused from the previous tree if defined.

It doesn't affect the functionality of defaultGroupingExpansionDepth() and isRowExpandedByDefault()

However if new rows are added with the same IDs as the previous ones, this logic will assume them the same rows and try to expand them, even though they are new ones. This shouldn't be a concern in a real use-case since IDs should be unique, but for numeric IDs always starting from 0, the users need to be mindful.

Additions

A couple API methods expandAllRows() and collapseAllRows are added to be used in case someone was using updation of the rows prop reference to reset the expansion status of the rows.

// Expand all rows
apiRef.current.expandAllRows();

// Collapse all rows
apiRef.current.collapseAllRows();

As part of v9, I think we can make the setRowChildrenExpansion() to receive multiple rows rather than a single, or even a function that will be used by an internal traversal method.

Changelog

  • Row groups now persist their expansion state when the rows are updated

@MBilalShafi MBilalShafi added scope: data grid Changes related to the data grid. feature: Tree data Related to the data grid Tree data feature proof of concept Studying and/or experimenting with a to be validated approach. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. labels Sep 24, 2025
@mui-bot
Copy link

mui-bot commented Sep 24, 2025

Deploy preview: https://deploy-preview-19697--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+571B(+0.15%) 🔺+123B(+0.10%)
@mui/x-data-grid-pro 🔺+671B(+0.14%) 🔺+116B(+0.08%)
@mui/x-data-grid-premium 🔺+664B(+0.11%) 🔺+141B(+0.07%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against c2b2ad2

@MBilalShafi MBilalShafi added the RFC Request For Comments. label Sep 24, 2025
@MBilalShafi MBilalShafi requested review from a team September 24, 2025 16:31
@MBilalShafi MBilalShafi changed the title [DataGrid] POC: Retain expansion state on rows update [DataGrid] Retain expansion state on rows update Sep 29, 2025
@MBilalShafi MBilalShafi added type: bug It doesn't behave as expected. and removed RFC Request For Comments. proof of concept Studying and/or experimenting with a to be validated approach. labels Sep 29, 2025
@MBilalShafi MBilalShafi removed the type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. label Sep 29, 2025
@MBilalShafi MBilalShafi marked this pull request as ready for review September 29, 2025 12:30
@MBilalShafi MBilalShafi merged commit 3acf6d5 into mui:master Sep 30, 2025
21 checks passed
@MBilalShafi MBilalShafi changed the title [DataGrid] Retain expansion state on rows update [DataGridPro] Retain expansion state on rows update Sep 30, 2025
@MBilalShafi MBilalShafi deleted the retain-expansion-state branch September 30, 2025 03:22
MBilalShafi added a commit to MBilalShafi/mui-x that referenced this pull request Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: Tree data Related to the data grid Tree data feature scope: data grid Changes related to the data grid. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[data grid] All grouped rows collapses when rows updating (by state, not by updateRows)

3 participants