From dcd0330475eb014eb0720f4eafbb40d5a9ee7d16 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Dec 2024 18:26:37 +0100 Subject: [PATCH] [DataGridPremium] Fix group column ignoring `valueOptions` for `singleSelect` column type (@arminmeh) (#15754) Co-authored-by: Armin Mehinovic <4390250+arminmeh@users.noreply.github.com> --- .../rowGrouping/createGroupingColDef.tsx | 10 +++++++ .../rowGrouping.DataGridPremium.test.tsx | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/packages/x-data-grid-premium/src/hooks/features/rowGrouping/createGroupingColDef.tsx b/packages/x-data-grid-premium/src/hooks/features/rowGrouping/createGroupingColDef.tsx index 194c62efa521..a56f6a8bbc02 100644 --- a/packages/x-data-grid-premium/src/hooks/features/rowGrouping/createGroupingColDef.tsx +++ b/packages/x-data-grid-premium/src/hooks/features/rowGrouping/createGroupingColDef.tsx @@ -7,6 +7,7 @@ import { GridGroupingColDefOverride, GridGroupNode, GridTreeNodeWithRender, + GridValueFormatter, } from '@mui/x-data-grid-pro'; import { GridColumnRawLookup, isSingleSelectColDef } from '@mui/x-data-grid-pro/internals'; import { GridApiPremium } from '../../../models/gridApiPremium'; @@ -94,10 +95,19 @@ const getLeafProperties = (leafColDef: GridColDef): Partial => ({ }, }); +const groupedByColValueFormatter: ( + groupedByColDef: GridColDef, +) => GridValueFormatter = + (groupedByColDef: GridColDef) => (value, row, _, apiRef) => + groupedByColDef.valueFormatter!(value, row, groupedByColDef, apiRef); + const getGroupingCriteriaProperties = (groupedByColDef: GridColDef, applyHeaderName: boolean) => { const properties: Partial = { sortable: groupedByColDef.sortable, filterable: groupedByColDef.filterable, + valueFormatter: groupedByColDef.valueFormatter + ? groupedByColValueFormatter(groupedByColDef) + : undefined, valueOptions: isSingleSelectColDef(groupedByColDef) ? groupedByColDef.valueOptions : undefined, sortComparator: (v1, v2, cellParams1, cellParams2) => { // We only want to sort the groups of the current grouping criteria 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 f956007843f7..f30b9e4374c7 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 @@ -169,6 +169,32 @@ describe(' - Row grouping', () => { expect(getColumnValues(0)).to.deep.equal(['Cat A (3)', '', '', '', 'Cat B (2)', '', '']); }); + it('should display the value from the `valueOptions` for `singleSelect` column type', () => { + render( + , + ); + expect(getColumnValues(0)).to.deep.equal(['categoryLabel1 (3)', 'categoryLabel2 (2)']); + }); + it('should display icon on auto-generated row', () => { render(