Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/pages/api-docs/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"getRowClassName": { "type": { "name": "func" } },
"getRowId": { "type": { "name": "func" } },
"getTreeDataPath": { "type": { "name": "func" } },
"groupingColDef": { "type": { "name": "object" } },
"groupingColDef": { "type": { "name": "union", "description": "func<br>&#124;&nbsp;object" } },
"headerHeight": { "type": { "name": "number" }, "default": "56" },
"hideFooter": { "type": { "name": "bool" } },
"hideFooterPagination": { "type": { "name": "bool" } },
Expand Down
11 changes: 8 additions & 3 deletions packages/grid/_modules_/grid/GridComponentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { SxProps } from '@mui/system';
import { Theme } from '@mui/material/styles';
import { GridInitialState } from './models/gridState';
import { GridApiRef } from './models/api/gridApiRef';
import { GridColDefOverride, GridColumns } from './models/colDef/gridColDef';
import {
GridGroupingColDefOverrideParams,
GridColumns,
GridGroupingColDefOverride,
} from './models/colDef/gridColDef';
import {
GridSimpleOptions,
GridProcessedMergedOptions,
Expand Down Expand Up @@ -395,8 +399,9 @@ interface GridComponentOtherProps extends CommonProps {
/**
* The grouping column used by the tree data.
*/
groupingColDef?: GridColDefOverride<'field' | 'editable'>;

groupingColDef?:
| GridGroupingColDefOverride
| ((params: GridGroupingColDefOverrideParams) => GridGroupingColDefOverride | undefined | null);
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from './gridTreeDataGroupColDef';
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
import { GridEvents, GridEventListener } from '../../../models/events';
import { GridColDef } from '../../../models';
import { GridColDef, GridGroupingColDefOverrideParams } from '../../../models';
import { isSpaceKey } from '../../../utils/keyboardUtils';
import { useFirstRender } from '../../utils/useFirstRender';
import { buildRowTree, BuildRowTreeGroupingCriteria } from '../../../utils/tree/buildRowTree';
Expand All @@ -16,6 +16,8 @@ import { gridFilteredDescendantCountLookupSelector } from '../filter';
import { GridPreProcessingGroup, useGridRegisterPreProcessor } from '../../core/preProcessing';
import { GridColumnsRawState } from '../columns/gridColumnsState';

const TREE_DATA_GROUPING_NAME = 'tree-data';

/**
* Only available in DataGridPro
* @requires useGridPreProcessing (method)
Expand All @@ -36,18 +38,18 @@ export const useGridTreeData = (
headerName: apiRef.current.getLocaleText('treeDataGroupingHeaderName'),
...GRID_TREE_DATA_GROUP_COL_DEF_FORCED_FIELDS,
};
const colDefOverride: Partial<GridColDef> = propGroupingColDef ?? {};
// let colDefOverride: Partial<GridColDef>;
//
// if (typeof propGroupingColDef === 'function') {
// const params: GridColDefOverrideParams = {
// colDef: baseColDef,
// };
//
// colDefOverride = propGroupingColDef(params);
// } else {
// colDefOverride = propGroupingColDef ?? {};
// }
let colDefOverride: Partial<GridColDef> | null | undefined;

if (typeof propGroupingColDef === 'function') {
const params: GridGroupingColDefOverrideParams = {
groupingName: TREE_DATA_GROUPING_NAME,
fields: [],
};

colDefOverride = propGroupingColDef(params);
} else {
colDefOverride = propGroupingColDef;
}

return {
...baseColDef,
Expand Down
22 changes: 12 additions & 10 deletions packages/grid/_modules_/grid/models/colDef/gridColDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,20 @@ export interface GridColumnsMeta {
positions: number[];
}

export type GridColDefOverride<ForcedFields extends keyof GridColDef> = Omit<
Partial<GridColDef>,
ForcedFields
>;
export interface GridGroupingColDefOverride
extends Omit<
GridColDef,
'editable' | 'valueSetter' | 'field' | 'preProcessEditCellProps' | 'renderEditCell'
> {}

export type GridColDefOverrideCallback<ForcedFields extends keyof GridColDef> = (
params: GridColDefOverrideParams,
) => GridColDefOverride<ForcedFields>;
export interface GridGroupingColDefOverrideParams {
/**
* The name of the grouping algorithm currently building the grouping column.
*/
groupingName: string;

export interface GridColDefOverrideParams {
/**
* The column we are generating before the override.
* The fields of the columns from which we want to group the values on this new grouping column.
*/
colDef: GridColDef;
fields: string[];
}
2 changes: 1 addition & 1 deletion packages/grid/x-data-grid-pro/src/DataGridPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ DataGridProRaw.propTypes = {
/**
* The grouping column used by the tree data.
*/
groupingColDef: PropTypes.object,
groupingColDef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
/**
* Set the height in pixel of the column headers in the grid.
* @default 56
Expand Down
5 changes: 2 additions & 3 deletions scripts/exportsSnapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
{ "name": "GridClasses", "kind": "Interface" },
{ "name": "GridClipboardApi", "kind": "Interface" },
{ "name": "GridColDef", "kind": "Interface" },
{ "name": "GridColDefOverrideParams", "kind": "Interface" },
{ "name": "GridColumnApi", "kind": "Interface" },
{ "name": "GridColumnHeaderEventLookup", "kind": "Interface" },
{ "name": "GridColumnHeaderIndexCoordinates", "kind": "Interface" },
Expand Down Expand Up @@ -90,6 +89,8 @@
{ "name": "GridFilterState", "kind": "Interface" },
{ "name": "GridFocusApi", "kind": "Interface" },
{ "name": "GridFocusState", "kind": "Interface" },
{ "name": "GridGroupingColDefOverride", "kind": "Interface" },
{ "name": "GridGroupingColDefOverrideParams", "kind": "Interface" },
{ "name": "GridHeaderSelectionCheckboxParams", "kind": "Interface" },
{ "name": "GridIconSlotsComponent", "kind": "Interface" },
{ "name": "GridInitialState", "kind": "Interface" },
Expand Down Expand Up @@ -156,8 +157,6 @@
{ "name": "GridCellMode", "kind": "Type alias" },
{ "name": "GridCellValue", "kind": "Type alias" },
{ "name": "GridClassKey", "kind": "Type alias" },
{ "name": "GridColDefOverride", "kind": "Type alias" },
{ "name": "GridColDefOverrideCallback", "kind": "Type alias" },
{ "name": "GridColType", "kind": "Type alias" },
{ "name": "GridColTypeDef", "kind": "Type alias" },
{ "name": "GridColumnHeaderClassFn", "kind": "Type alias" },
Expand Down