diff --git a/packages/x-data-grid-premium/src/hooks/features/rowGrouping/gridRowGroupingUtils.ts b/packages/x-data-grid-premium/src/hooks/features/rowGrouping/gridRowGroupingUtils.ts
index 353b51936bd4a..95621030ed52c 100644
--- a/packages/x-data-grid-premium/src/hooks/features/rowGrouping/gridRowGroupingUtils.ts
+++ b/packages/x-data-grid-premium/src/hooks/features/rowGrouping/gridRowGroupingUtils.ts
@@ -20,6 +20,7 @@ import {
getRowGroupingCriteriaFromGroupingField,
isGroupingColumn,
GridStrategyGroup,
+ getRowValue,
} from '@mui/x-data-grid-pro/internals';
import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
import {
@@ -230,7 +231,7 @@ export const getCellGroupingCriteria = ({
if (groupingRule.groupingValueGetter) {
key = groupingRule.groupingValueGetter(row[groupingRule.field] as never, row, colDef, apiRef);
} else {
- key = row[groupingRule.field] as GridKeyValue | null | undefined;
+ key = getRowValue(row, colDef, apiRef) as GridKeyValue | null | undefined;
}
return {
diff --git a/packages/x-data-grid-premium/src/tests/rowGrouping.DataGridPremium.test.tsx b/packages/x-data-grid-premium/src/tests/rowGrouping.DataGridPremium.test.tsx
index 6a0979cff342c..8014e93a6948a 100644
--- a/packages/x-data-grid-premium/src/tests/rowGrouping.DataGridPremium.test.tsx
+++ b/packages/x-data-grid-premium/src/tests/rowGrouping.DataGridPremium.test.tsx
@@ -1605,7 +1605,7 @@ describe(' - Row grouping', () => {
expect(getColumnValues(1)).to.deep.equal(['', '0', '3', '', '1', '4', '', '2']);
});
- it('should not use valueGetter to group the rows when defined', () => {
+ it('should use valueGetter to group the rows when defined', () => {
render(
- Row grouping', () => {
defaultGroupingExpansionDepth={-1}
/>,
);
- expect(getColumnValues(0)).to.deep.equal(['Cat A (3)', '', '', '', 'Cat B (2)', '', '']);
+ expect(getColumnValues(0)).to.deep.equal([
+ 'value Cat A (3)',
+ '',
+ '',
+ '',
+ 'value Cat B (2)',
+ '',
+ '',
+ ]);
expect(getColumnValues(1)).to.deep.equal(['', '0', '1', '2', '', '3', '4']);
});
diff --git a/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts b/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts
index a56b68bddcdba..33ce39dd1cae9 100644
--- a/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts
+++ b/packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts
@@ -2,6 +2,7 @@ import * as React from 'react';
import {
GridAutoGeneratedGroupNode,
GridAutoGeneratedPinnedRowNode,
+ GridColDef,
GridFooterNode,
GridGroupNode,
GridRowId,
@@ -11,6 +12,7 @@ import {
GridRowTreeConfig,
GridSkeletonRowNode,
GridTreeNode,
+ GridValidRowModel,
} from '../../../models';
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
import { GridApiCommunity, GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity';
@@ -74,6 +76,21 @@ export const getRowIdFromRowModel = (
return id;
};
+export const getRowValue = (
+ row: GridValidRowModel,
+ colDef: GridColDef,
+ apiRef: React.MutableRefObject,
+) => {
+ const field = colDef.field;
+
+ if (!colDef || !colDef.valueGetter) {
+ return row[field];
+ }
+
+ const value = row[colDef.field];
+ return colDef.valueGetter(value as never, row, colDef, apiRef);
+};
+
export const createRowsInternalCache = ({
rows,
getRowId,
diff --git a/packages/x-data-grid/src/hooks/features/rows/useGridParamsApi.ts b/packages/x-data-grid/src/hooks/features/rows/useGridParamsApi.ts
index 0b37235679826..918360d1733f3 100644
--- a/packages/x-data-grid/src/hooks/features/rows/useGridParamsApi.ts
+++ b/packages/x-data-grid/src/hooks/features/rows/useGridParamsApi.ts
@@ -13,6 +13,7 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
import { gridFocusCellSelector, gridTabIndexCellSelector } from '../focus/gridFocusStateSelector';
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
import { gridListColumnSelector } from '../listView/gridListViewSelectors';
+import { getRowValue as getRowValueFn } from './gridRowsUtils';
export class MissingRowIdError extends Error {}
@@ -118,16 +119,7 @@ export function useGridParamsApi(
);
const getRowValue = React.useCallback(
- (row, colDef) => {
- const field = colDef.field;
-
- if (!colDef || !colDef.valueGetter) {
- return row[field];
- }
-
- const value = row[colDef.field];
- return colDef.valueGetter(value as never, row, colDef, apiRef);
- },
+ (row, colDef) => getRowValueFn(row, colDef, apiRef),
[apiRef],
);
diff --git a/packages/x-data-grid/src/internals/index.ts b/packages/x-data-grid/src/internals/index.ts
index 60848709e1927..0a96160632332 100644
--- a/packages/x-data-grid/src/internals/index.ts
+++ b/packages/x-data-grid/src/internals/index.ts
@@ -101,7 +101,11 @@ export type {
export { getTreeNodeDescendants, buildRootGroup } from '../hooks/features/rows/gridRowsUtils';
export { useGridRowsMeta, rowsMetaStateInitializer } from '../hooks/features/rows/useGridRowsMeta';
export { useGridParamsApi } from '../hooks/features/rows/useGridParamsApi';
-export { getRowIdFromRowModel, GRID_ID_AUTOGENERATED } from '../hooks/features/rows/gridRowsUtils';
+export {
+ getRowIdFromRowModel,
+ GRID_ID_AUTOGENERATED,
+ getRowValue,
+} from '../hooks/features/rows/gridRowsUtils';
export {
gridAdditionalRowGroupsSelector,
gridPinnedRowsSelector,