-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGridPro] Add support for master/detail #3387
Conversation
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
4755866
to
0f7ce90
Compare
I still want to add some very complex demos (e.g. combine with column pinning and use a form as the detail), but this can be done while the PR is reviewed. Don't focus too much in the changes done to support variable row height, this is not the main concern here. The changes I made are likely to change depending on #3218. |
|
||
const heights = apiRef.current.unstable_applyPreProcessors( | ||
GridPreProcessingGroup.rowHeight, | ||
{ base: rowHeight }, // We use an object to make simple to check if a size was already added or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing other hooks to pre-process the row height unblocks #2144.
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice documentation, I enjoyed the DataGrind inside a DataGrid. It should probably have its own page because it does not have that much relation with the tree data.
docs/src/pages/components/data-grid/group-pivot/ControlMasterDetail.tsx
Outdated
Show resolved
Hide resolved
docs/src/pages/components/data-grid/group-pivot/NestedDetailPanels.tsx
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/detailPanel/gridDetailPanelSelector.ts
Outdated
Show resolved
Hide resolved
const ownerState: OwnerState = { classes: rootProps.classes, isExpanded }; | ||
const classes = useUtilityClasses(ownerState); | ||
|
||
const contentCache = useGridSelector(apiRef, gridExpandedRowsContentCache); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a function disableDetailPannel
which takes the row as an input and returns a boolean?
I would avoid having to cache its value and decouple the action management (allowing/preventing google) and the rendering of the panel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to add a hasDetailPanel(row)
method to the API? Similar to isColumnPinned(field)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly. For now, developers have access to two parameters:
getDetailPanelContent
getDetailPanelHeight
And if you do not want to have a detail panel for some row, the getDetailPanelContent
must return null
or undefined
. With this method, you have to evaluate all the getDetailPanelContent(row)
to know if the detail panel is a valid component. I'm proposing to let developers provide a third prop disableDetailPannel(row)
.
I thought about it for two reasons:
- Using
React.isValidElement
seems a bit hacky. - I imagine for developers, knowing if the row has a detail panel will be easy. It will probably be a condition such as: "the row status is open"
packages/grid/_modules_/grid/hooks/features/detailPanel/useGridDetailPanel.ts
Outdated
Show resolved
Hide resolved
I'm eager to be able to use this feature, guys!! Do you have an ETA for it or should I ask Santa for a late gift? 😄 |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks awesome and the docs and examples are perfect, really great job! Should we aim to merge this and have it in this week's release?
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Not sure what the best option is here
|
@flaviendelangle I changed to a "+" and "-" icon. I don't agree that we should tell users to change the icon if they want to use master detail and tree data. Kendo UI uses the same combination that we're now using: arrow for grouping and "+" for master detail. https://www.telerik.com/kendo-angular-ui/components/grid/master-detail/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's looking great!
Any update about this feature ? Will it be available in v5.x or the upcoming major release ? |
The feature has been available for quite some time I would be interested to know why you did not find it |
Ok I'm glad it's released and available in datagrid pro, thanks you and mui team ! For the story, At first, I stumbled between every documentation page (Rows, Editing, Components) having in mind words like "Edit panel" / "Detail panel" (like in material-table ) and never thought to search in Group&Pivot sub-categories, in my opinion the name 'Master detail' is not very explicit (even if this makes sense now), and maybe should be in or 'Rows' or an independent page. Maybe I'm wrong and it really belongs to Group & Pivot category because it shares some UI parts. Also, in mui table the equivalent feature has a different name, collapsible table . Finally, It will be great if such feature appears on main demo , since we often look at it to describe a custom feature, based on what is already available on mui-x datagarid. But I understand that too much on demo can be overhelming, it's just supposed to be a demo not an exhaustive datagrid capabilities. |
Thanks for your feedback ! @joserodolfofreitas I think that will interest you I think there are two three things here:
|
@flaviendelangle @m4theushw, can we close the opened row detail when we click on the other row? Is this possible with detailPanelContent in DataGridPro? |
@niralivasoya Yes, you need to update the |
Preview: https://deploy-preview-3387--material-ui-x.netlify.app/components/data-grid/group-pivot/#master-detail
Closes #211
How does it work?
The master/detail implemented here works in two steps:
The first step is to adjust the height of the row whose we want to show the detail to include the height of the panel too. That way, the final row height is: base row height (defined via
rowHeight
prop) + detail panel height (defined viagetDetailPanelHeight
prop). Doing this, we don't need to worry aboutscrollToIndexes
nor fixing the virtualization, because, in theory, it would already have #3218. The rendering of the detail panel is done later. To fill the space left for the panel, a bottom margin is applied to the row.The second step is to render all of the detail panels. This is achieved by rendering all of them inside a div placed on top of the render zone, which can be understood as a "layer". Each panel is absolute positioned so the
top
corresponds to thebottom
position of the row it belongs to. That way, it creates the impression that the panel is rendered immediately below the row, when it's not. I chose this approach because the alternative would be to render the panel inside theGridRow
, which could cause some flickering when the virtualization renders new rows. The idea of adding another layer ensures that the open detail panels are rendered once and never again, no matter how much the user scrolls.Changelog