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] How to programmatically expand rows #15518

Closed
shoxter opened this issue Nov 20, 2024 · 7 comments
Closed

[data grid] How to programmatically expand rows #15518

shoxter opened this issue Nov 20, 2024 · 7 comments
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 support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@shoxter
Copy link

shoxter commented Nov 20, 2024

The problem in depth

There is currently an example for master detail that shows how to expand/collapse all in a custom header component (here). I want to do the same but for row groupings (expand/collapse all the groupings) but I can't find any selectors that would allow for this or any functions in the API itself as all of the expansion state functions are concerned with master/detail from what I can tell. How can I achieve what I'm looking to do?

Your environment

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: row grouping selector api
Order ID: 96266

@shoxter shoxter added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Nov 20, 2024
@github-actions github-actions bot added component: data grid This is the name of the generic UI component, not the React module! support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ labels Nov 20, 2024
@michelengelen michelengelen changed the title [question] How do I get the expanded rows? [data grid] How to programmatically expand rows Nov 21, 2024
@michelengelen
Copy link
Member

You can use the setRowChildrenExpansion on the apiRef for that.

@michelengelen michelengelen added status: waiting for author Issue with insufficient information 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 Nov 21, 2024
@shoxter
Copy link
Author

shoxter commented Nov 21, 2024

You can use the setRowChildrenExpansion on the apiRef for that.

For clarity, I think what I was looking for is something similar to the behavior of the recipe for the master/detail expand/collapse all. That being, a way to know what rows are currently collapsed/expanded so I know what type of button I need to display (collapse all vs expand all).

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Nov 21, 2024
@michelengelen
Copy link
Member

you can get the current grouping rows with this:

// on the root level
const groups = apiRef.current.getRowNode<GridGroupNode>(GRID_ROOT_GROUP_ID)!.children;

if you want deeper levels you would need to run this for the respective parent rows.

With this you get the groupIds (rowIds from the grouping rows), with which you can check the current expansion state:

const areSomeRowsExpanded = groups.some((groupId) => apiRef.current.getRowNode<GridGroupNode>(groupId)!.childrenExpanded);

@michelengelen michelengelen 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 Nov 22, 2024
Copy link

The issue has been inactive for 7 days and has been automatically closed.

@shoxter
Copy link
Author

shoxter commented Dec 2, 2024

you can get the current grouping rows with this:

// on the root level
const groups = apiRef.current.getRowNode<GridGroupNode>(GRID_ROOT_GROUP_ID)!.children;

if you want deeper levels you would need to run this for the respective parent rows.

With this you get the groupIds (rowIds from the grouping rows), with which you can check the current expansion state:

const areSomeRowsExpanded = groups.some((groupId) => apiRef.current.getRowNode<GridGroupNode>(groupId)!.childrenExpanded);

This is perfect and the linked example makes perfect sense in light of the specific methods you linked. Sorry for the misunderstanding on my part! Thanks again!

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Dec 2, 2024
@github-actions github-actions bot reopened this Dec 2, 2024
@shoxter shoxter closed this as completed Dec 2, 2024
@github-actions github-actions bot removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 2, 2024
Copy link

github-actions bot commented Dec 2, 2024

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@shoxter How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

@shoxter shoxter reopened this Dec 2, 2024
@shoxter shoxter closed this as completed Dec 2, 2024
Copy link

github-actions bot commented Dec 2, 2024

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@shoxter How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

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 support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/
Projects
None yet
Development

No branches or pull requests

2 participants