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

[question] DataGridPro Expand and Collapse All nodes programmatically #10025

Closed
2 tasks done
sbmaggarwal opened this issue Aug 13, 2023 · 3 comments
Closed
2 tasks done
Labels
component: data grid This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists plan: Pro Impact at least one Pro user support: commercial Support request from paid users

Comments

@sbmaggarwal
Copy link

Order ID or Support key 💳 (optional)

71425

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

The problem in depth 🔍

How can I make all rows expand/collapse programmatically in MUI ReactJS DataGrid?

What have I tried?
I used prop defaultGroupingExpansionDepth based on MUI documentation:

export const EXPAND_ALL = -1;
export const COLLAPSE_ALL = 0;
...
const [expandedState, setExpandedState] = useState(COLLAPSE_ALL);
...

return <Stack>
        <Stack spacing={2} direction="row" m={1}>
            <Button variant={"contained"} onClick={() => setExpandedState(EXPAND_ALL)}>Expand All</Button>
            <Button variant={"contained"} onClick={() => setExpandedState(COLLAPSE_ALL)}>Collapse All</Button>
        </Stack>
        <DataGridPro
            treeData
            ...
            apiRef={dataGridApi}
            defaultGroupingExpansionDepth={expandedState}
            ... />
    </Stack>;

But the problem is that these buttons only work when tree is not already partially expanded.

As soon as I partially expand the tree grid, these buttons don't work any more. How can I make these buttons work irrespective of the current expansion/collapse state of the tree grid?

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
@sbmaggarwal sbmaggarwal added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Aug 13, 2023
@zannager zannager added component: data grid This is the name of the generic UI component, not the React module! plan: Pro Impact at least one Pro user labels Aug 14, 2023
@romgrk
Copy link
Contributor

romgrk commented Aug 14, 2023

Have you read that section of the documentation in full? The last part seems to be what you're looking for:

image

If a prop start by default... it usually only applies when the component is mounted, just like defaultValue for input.

@romgrk romgrk added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Aug 14, 2023
@sbmaggarwal
Copy link
Author

But I don't want to expand a single row, I want to expand and collapse all rows. Is there a direct way to do this?

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Aug 14, 2023
@romgrk
Copy link
Contributor

romgrk commented Aug 14, 2023

Duplicate of #8505

@romgrk romgrk marked this as a duplicate of #8505 Aug 14, 2023
@romgrk romgrk closed this as completed Aug 14, 2023
@github-actions github-actions bot added the duplicate This issue or pull request already exists label Aug 14, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2023
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! duplicate This issue or pull request already exists plan: Pro Impact at least one Pro user support: commercial Support request from paid users
Projects
None yet
Development

No branches or pull requests

3 participants