Skip to content

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Aug 27, 2025

@siriwatknp siriwatknp added docs Improvements or additions to the documentation. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: data grid Changes related to the data grid. labels Aug 27, 2025
@mui-bot
Copy link

mui-bot commented Aug 27, 2025

Deploy preview: https://deploy-preview-19349--material-ui-x.netlify.app/

Updated pages:

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) ▼-1B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) ▼-1B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) ▼-1B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) ▼-1B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) ▼-1B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against a79834c

Copy link
Member

@MBilalShafi MBilalShafi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice looking recipe ❇️

if (childNode && childNode.type === 'leaf') {
const childRow = apiRef.current?.getRow<Movie>(childId);
if (childRow?.gross && childRow.gross > EXPECTED_GROSS) {
hasExpectedGross = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would directly returning from here also work?

Suggested change
hasExpectedGross = true;
return 'highlighted-group';

let hasExpectedGross = false;

for (const childId of childIds) {
const childNode = apiRef.current?.getRowNode(childId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recommended approach to get row node would be the gridRowNodeSelector() which is a selector with arguments. getRowNode() is a deprecated method and should not be around by v9.

Suggested change
const childNode = apiRef.current?.getRowNode(childId);
const childNode = gridRowNodeSelector(apiRef, childId);

const data = useMovieData();

const getRowClassName = (params: GridRowClassNameParams<Movie>) => {
const node = apiRef.current?.getRowNode(params.id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const node = apiRef.current?.getRowNode(params.id);
const node = gridRowNodeSelector(apiRef, params.id);

import {
DataGridPremium,
useGridApiRef,
useKeepGroupedColumnsHidden,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
useKeepGroupedColumnsHidden,
useKeepGroupedColumnsHidden,
gridRowNodeSelector,

position: 'absolute',
left: 0,
width: 4,
height: 'calc(var(--height) * 0.8)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While using CSS variable (--height) definitely adds value, it's not a public API, how about using a local variable to avoid confusion? (same with marginTop)

Suggested change
height: 'calc(var(--height) * 0.8)',
height: 'calc(rowHeight * 0.8)',

let hasExpectedGross = false;

for (const childId of childIds) {
const childNode = apiRef.current?.getRowNode(childId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better, we could make rowNode a part of GridRowClassNameParams, following the same of GridCellParams so that it's already readily available:

/**
* The node of the row that the current cell belongs to.
*/
rowNode: N;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean updating the implementation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be a minimal and non breaking change.

Copy link
Member

@MBilalShafi MBilalShafi Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't necessarily need to be done in the same PR though. Keeping the scope relevant should also be fine.

@@ -37,3 +37,17 @@ By default, the row count in the footer is the number of top level rows that are
In the demo below, a `CustomFooterRowCount` component is added to the `footerRowCount` slot. This component uses the `gridFilteredDescendantRowCountSelector` to get the number of child rows and display it alongside the number of groups.

{{"demo": "RowGroupingChildRowCount.js", "bg": "inline", "defaultCodeOpen": false}}

## Styling row groups based on child conditions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we make this recipe an extension of https://mui.com/x/react-data-grid/style/#styling-rows instead, as that one also leverages getRowClassName(). (We can also add a backlink here if necessary)

Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, it's better to be in that page.


Use `getRowClassName` to add a custom class to the row group and then write CSS to style it.

To write a condition, use [`apiRef.current.getRowNode`](/x/api/data-grid/grid-api/#grid-api-prop-getRowNode) to check for the targeted row type and use [`apiRef.current.getRow`](/x/api/data-grid/grid-api/#grid-api-prop-getRow) to get the row data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote: Due to the imperative nature of apiRef, it's recommended to use selectors instead of apiRef where possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's about apiRef.current.getRow? I don't see a selector I could use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't any, we could create a selector with arguments though on top of gridRowsLookupSelector
We could also possibly do in another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation. recipe scope: data grid Changes related to the data grid. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data grid] How can I add a class in expand panel in row grouping?
3 participants