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] I want one row of the tree data to be expanded by default #15102

Closed
mahammahmood opened this issue Oct 24, 2024 · 2 comments
Closed
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: logic Logic customizability feature: Tree data Related to the data grid Tree data feature status: waiting for author Issue with insufficient information 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/ support: question Community support but can be turned into an improvement

Comments

@mahammahmood
Copy link

mahammahmood commented Oct 24, 2024

The problem in depth

  1. I want the itinerary to automatically expand when I click 'Add Itinerary,' so I can see the new itinerary without needing to manually click the expand icon. Currently, the itinerary does not expand by default after adding it. For example, in the picture, I added the itinerary, but it is not expanded.
    Screenshot 2024-10-24 182442

  2. The completion count for the itinerary shows 3/4. However, if all its children are completed, the count should be 4/4. I need the parent itinerary to be considered completed when all its children are completed.
    Screenshot 2024-10-24 183804

3 The direct child does not display any completion count. I would like the count to be displayed for the child as well, such as on Itinerary 1 the count should 3/3 in this case.

Here is the example
https://stackblitz.com/edit/react-sj2kwa?file=customGridTreeDataGroupingCell.tsx,Demo.tsx

For point 1 I have implemented this code:

  useEffect(() => {
    if (rowNode?.type === 'group' && rowNode.groupingKey === 'Itinerary') {
     const childrenExpanded = !rowNode.childrenExpanded;

      apiRef.current.setRowChildrenExpansion(rowNode.id, childrenExpanded);
    }
  }, [rowNode?.type, rowNode?.id, apiRef]);

but it only expand it when i added for the first time.

Your environment

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

Search keywords: Data, Grid, Premium, Tree, Data, row, Expanded
Order ID: 91010

@mahammahmood mahammahmood added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Oct 24, 2024
@github-actions github-actions bot added the support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ label Oct 24, 2024
@KenanYusuf KenanYusuf changed the title I want one row of the tree data to be expanded by default in Data Grid Tree Data [data grid] I want one row of the tree data to be expanded by default Oct 24, 2024
@KenanYusuf KenanYusuf 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 support: question Community support but can be turned into an improvement customization: logic Logic customizability labels Oct 24, 2024
@KenanYusuf
Copy link
Contributor

Hi @mahammahmood thanks for linking your example.

  1. I want the itinerary to automatically expand when I click 'Add Itinerary,'

Instead of using a React.useEffect, you can use the data grid's built in isGroupExpandedByDefault prop. You can add whatever logic you like to decide whether or not a node is opened when the grid mounts or an item is added. Something like this could work in your case:

isGroupExpandedByDefault={(node) => {
  if (typeof node.groupingKey === 'string') {
    return node.groupingKey.includes('Itinerary');
  }
  return false;
}}

For 2 and 3, I can see you're handling displaying the completion count for Itinerary and progress for Itinerary 1 within your customGridTreeDataGroupingCell - you should be able to update the logic there to display each piece of information at both levels. Is there any data from the grid that you're missing to be able to do this?

@KenanYusuf KenanYusuf 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 Oct 25, 2024
Copy link

github-actions bot commented Nov 1, 2024

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

@github-actions github-actions bot closed this as completed Nov 1, 2024
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! customization: logic Logic customizability feature: Tree data Related to the data grid Tree data feature status: waiting for author Issue with insufficient information 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/ support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

2 participants