Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data grid] Possible to Persist row collapse/expansion when data changes? #6314

Closed
2 tasks done
tnoetzel opened this issue Sep 27, 2022 · 3 comments
Closed
2 tasks done
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Row grouping Related to the data grid Row grouping feature feature: Tree data Related to the data grid Tree data feature support: commercial Support request from paid users

Comments

@tnoetzel
Copy link

Order ID 💳

51562

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

The problem in depth 🔍

I've been playing with row grouping, and I've noticed that if the data updates (via updating the rows prop) , rows will collapse or expand back to their default state (based on defaultGroupingExpansionDepth).

While there's a way to control the grouping model, I can't find a way to control the grouping state.

Is there a way to force the data-grid to remember / persist the state of the expanded / collapsed rows?

Your environment 🌎

`npx @mui/envinfo`
  System:
    OS: macOS 12.5.1
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: Not Found
    npm: 8.9.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
  Browsers:
    Chrome: 105.0.5195.102
    Edge: Not Found
    Firefox: 104.0.2
    Safari: 15.6.1
  npmPackages:
    @emotion/react: ^11.6.0 => 11.6.0 
    @emotion/styled: ^11.6.0 => 11.6.0 
    @mui/base:  5.0.0-alpha.92 
    @mui/icons-material: ^5.6.2 => 5.6.2 
    @mui/material: ^5.1.0 => 5.10.0 
    @mui/private-theming:  5.9.3 
    @mui/styled-engine:  5.10.0 
    @mui/system:  5.10.0 
    @mui/types:  7.1.5 
    @mui/utils:  5.10.6 
    @mui/x-data-grid:  5.17.4 
    @mui/x-data-grid-premium: ^5.17.4 => 5.17.4 
    @mui/x-data-grid-pro: ^5.15.2 => 5.17.4 
    @mui/x-license-pro:  5.17.0 
    @types/react: ^17.0.20 => 17.0.20 
    react: ^17.0.2 => 17.0.2 
    react-dom: ^17.0.2 => 17.0.2 
    typescript: ^4.4.2 => 4.4.2 
@tnoetzel tnoetzel added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Sep 27, 2022
@flaviendelangle
Copy link
Member

Hi

If you update the rows prop, the grid will update all its rows and loose there state.
If you want to add / remove / update some rows, you can use the apiRef.current.updateRows method.

Here is a working example, if you open any group, is should state opened after adding "Toy Story 4": https://codesandbox.io/s/data-grid-premium-forked-4de8zr?file=/package.json

@flaviendelangle flaviendelangle added component: data grid This is the name of the generic UI component, not the React module! feature: Tree data Related to the data grid Tree data feature feature: Row grouping Related to the data grid Row grouping feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 28, 2022
@flaviendelangle flaviendelangle changed the title Possible to Persist row collapse/expansion when data changes? [data grid] Possible to Persist row collapse/expansion when data changes? Sep 28, 2022
@tnoetzel
Copy link
Author

Super helpful!

That said, it'd still be nice to preserve which groups are open/closed for a user between sessions. Any way to do this?

@flaviendelangle
Copy link
Member

You have a temporary solution in #4930 (comment)
Maybe we could improve the built in solution at some point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Row grouping Related to the data grid Row grouping feature feature: Tree data Related to the data grid Tree data feature support: commercial Support request from paid users
Projects
None yet
Development

No branches or pull requests

2 participants