@mui/x-data-grid-premium 5.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4052 -0
- package/DataGridPremium/DataGridPremium.d.ts +9 -0
- package/DataGridPremium/DataGridPremium.js +986 -0
- package/DataGridPremium/index.d.ts +2 -0
- package/DataGridPremium/index.js +2 -0
- package/DataGridPremium/package.json +6 -0
- package/DataGridPremium/useDataGridPremiumComponent.d.ts +4 -0
- package/DataGridPremium/useDataGridPremiumComponent.js +78 -0
- package/DataGridPremium/useDataGridPremiumProps.d.ts +6 -0
- package/DataGridPremium/useDataGridPremiumProps.js +37 -0
- package/LICENSE +12 -0
- package/README.md +31 -0
- package/components/GridExcelExportMenuItem.d.ts +9 -0
- package/components/GridExcelExportMenuItem.js +32 -0
- package/components/GridGroupingColumnLeafCell.d.ts +4 -0
- package/components/GridGroupingColumnLeafCell.js +22 -0
- package/components/GridGroupingCriteriaCell.d.ts +7 -0
- package/components/GridGroupingCriteriaCell.js +78 -0
- package/components/GridRowGroupableColumnMenuItems.d.ts +11 -0
- package/components/GridRowGroupableColumnMenuItems.js +63 -0
- package/components/GridRowGroupingColumnMenuItems.d.ts +11 -0
- package/components/GridRowGroupingColumnMenuItems.js +58 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +1 -0
- package/components/package.json +6 -0
- package/hooks/features/export/gridExcelExportInterface.d.ts +58 -0
- package/hooks/features/export/gridExcelExportInterface.js +1 -0
- package/hooks/features/export/index.d.ts +1 -0
- package/hooks/features/export/index.js +1 -0
- package/hooks/features/export/serializer/excelSerializer.d.ts +14 -0
- package/hooks/features/export/serializer/excelSerializer.js +218 -0
- package/hooks/features/export/useGridExcelExport.d.ts +10 -0
- package/hooks/features/export/useGridExcelExport.js +77 -0
- package/hooks/features/index.d.ts +2 -0
- package/hooks/features/index.js +3 -0
- package/hooks/features/rowGrouping/createGroupingColDef.d.ts +42 -0
- package/hooks/features/rowGrouping/createGroupingColDef.js +318 -0
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +37 -0
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
- package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +4 -0
- package/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +27 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +139 -0
- package/hooks/features/rowGrouping/index.d.ts +3 -0
- package/hooks/features/rowGrouping/index.js +3 -0
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +11 -0
- package/hooks/features/rowGrouping/useGridRowGrouping.js +200 -0
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +4 -0
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +3 -0
- package/hooks/package.json +6 -0
- package/hooks/utils/index.d.ts +1 -0
- package/hooks/utils/index.js +1 -0
- package/hooks/utils/useGridApiContext.d.ts +4 -0
- package/hooks/utils/useGridApiContext.js +2 -0
- package/hooks/utils/useGridApiRef.d.ts +4 -0
- package/hooks/utils/useGridApiRef.js +2 -0
- package/hooks/utils/useGridRootProps.d.ts +2 -0
- package/hooks/utils/useGridRootProps.js +2 -0
- package/hooks/utils/useKeepGroupedColumnsHidden.d.ts +12 -0
- package/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
- package/index.d.ts +22 -0
- package/index.js +25 -0
- package/legacy/DataGridPremium/DataGridPremium.js +986 -0
- package/legacy/DataGridPremium/index.js +2 -0
- package/legacy/DataGridPremium/useDataGridPremiumComponent.js +78 -0
- package/legacy/DataGridPremium/useDataGridPremiumProps.js +46 -0
- package/legacy/components/GridExcelExportMenuItem.js +30 -0
- package/legacy/components/GridGroupingColumnLeafCell.js +20 -0
- package/legacy/components/GridGroupingCriteriaCell.js +74 -0
- package/legacy/components/GridRowGroupableColumnMenuItems.js +61 -0
- package/legacy/components/GridRowGroupingColumnMenuItems.js +56 -0
- package/legacy/components/index.js +1 -0
- package/legacy/hooks/features/export/gridExcelExportInterface.js +1 -0
- package/legacy/hooks/features/export/index.js +1 -0
- package/legacy/hooks/features/export/serializer/excelSerializer.js +260 -0
- package/legacy/hooks/features/export/useGridExcelExport.js +111 -0
- package/legacy/hooks/features/index.js +3 -0
- package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +319 -0
- package/legacy/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
- package/legacy/hooks/features/rowGrouping/gridRowGroupingSelector.js +13 -0
- package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +147 -0
- package/legacy/hooks/features/rowGrouping/index.js +3 -0
- package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +206 -0
- package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +215 -0
- package/legacy/hooks/index.js +3 -0
- package/legacy/hooks/utils/index.js +1 -0
- package/legacy/hooks/utils/useGridApiContext.js +2 -0
- package/legacy/hooks/utils/useGridApiRef.js +2 -0
- package/legacy/hooks/utils/useGridRootProps.js +2 -0
- package/legacy/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
- package/legacy/index.js +25 -0
- package/legacy/models/dataGridPremiumProps.js +1 -0
- package/legacy/models/gridApiPremium.js +1 -0
- package/legacy/models/gridGroupingValueGetterParams.js +1 -0
- package/legacy/models/gridStatePremium.js +1 -0
- package/legacy/models/index.js +1 -0
- package/legacy/typeOverloads/index.js +1 -0
- package/legacy/typeOverloads/modules.js +33 -0
- package/legacy/typeOverloads/reexports.js +6 -0
- package/legacy/utils/releaseInfo.js +15 -0
- package/models/dataGridPremiumProps.d.ts +64 -0
- package/models/dataGridPremiumProps.js +1 -0
- package/models/gridApiPremium.d.ts +13 -0
- package/models/gridApiPremium.js +1 -0
- package/models/gridGroupingValueGetterParams.d.ts +31 -0
- package/models/gridGroupingValueGetterParams.js +1 -0
- package/models/gridStatePremium.d.ts +14 -0
- package/models/gridStatePremium.js +1 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +1 -0
- package/models/package.json +6 -0
- package/modern/DataGridPremium/DataGridPremium.js +986 -0
- package/modern/DataGridPremium/index.js +2 -0
- package/modern/DataGridPremium/useDataGridPremiumComponent.js +76 -0
- package/modern/DataGridPremium/useDataGridPremiumProps.js +37 -0
- package/modern/components/GridExcelExportMenuItem.js +32 -0
- package/modern/components/GridGroupingColumnLeafCell.js +20 -0
- package/modern/components/GridGroupingCriteriaCell.js +76 -0
- package/modern/components/GridRowGroupableColumnMenuItems.js +61 -0
- package/modern/components/GridRowGroupingColumnMenuItems.js +56 -0
- package/modern/components/index.js +1 -0
- package/modern/hooks/features/export/gridExcelExportInterface.js +1 -0
- package/modern/hooks/features/export/index.js +1 -0
- package/modern/hooks/features/export/serializer/excelSerializer.js +216 -0
- package/modern/hooks/features/export/useGridExcelExport.js +73 -0
- package/modern/hooks/features/index.js +3 -0
- package/modern/hooks/features/rowGrouping/createGroupingColDef.js +302 -0
- package/modern/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
- package/modern/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +137 -0
- package/modern/hooks/features/rowGrouping/index.js +3 -0
- package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +192 -0
- package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
- package/modern/hooks/index.js +3 -0
- package/modern/hooks/utils/index.js +1 -0
- package/modern/hooks/utils/useGridApiContext.js +2 -0
- package/modern/hooks/utils/useGridApiRef.js +2 -0
- package/modern/hooks/utils/useGridRootProps.js +2 -0
- package/modern/hooks/utils/useKeepGroupedColumnsHidden.js +46 -0
- package/modern/index.js +25 -0
- package/modern/models/dataGridPremiumProps.js +1 -0
- package/modern/models/gridApiPremium.js +1 -0
- package/modern/models/gridGroupingValueGetterParams.js +1 -0
- package/modern/models/gridStatePremium.js +1 -0
- package/modern/models/index.js +1 -0
- package/modern/typeOverloads/index.js +1 -0
- package/modern/typeOverloads/modules.js +33 -0
- package/modern/typeOverloads/reexports.js +6 -0
- package/modern/utils/releaseInfo.js +15 -0
- package/node/DataGridPremium/DataGridPremium.js +1009 -0
- package/node/DataGridPremium/index.js +30 -0
- package/node/DataGridPremium/useDataGridPremiumComponent.js +91 -0
- package/node/DataGridPremium/useDataGridPremiumProps.js +57 -0
- package/node/components/GridExcelExportMenuItem.js +49 -0
- package/node/components/GridGroupingColumnLeafCell.js +38 -0
- package/node/components/GridGroupingCriteriaCell.js +99 -0
- package/node/components/GridRowGroupableColumnMenuItems.js +82 -0
- package/node/components/GridRowGroupingColumnMenuItems.js +78 -0
- package/node/components/index.js +18 -0
- package/node/hooks/features/export/gridExcelExportInterface.js +5 -0
- package/node/hooks/features/export/index.js +18 -0
- package/node/hooks/features/export/serializer/excelSerializer.js +233 -0
- package/node/hooks/features/export/useGridExcelExport.js +95 -0
- package/node/hooks/features/index.js +31 -0
- package/node/hooks/features/rowGrouping/createGroupingColDef.js +341 -0
- package/node/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +5 -0
- package/node/hooks/features/rowGrouping/gridRowGroupingSelector.js +18 -0
- package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +172 -0
- package/node/hooks/features/rowGrouping/index.js +51 -0
- package/node/hooks/features/rowGrouping/useGridRowGrouping.js +228 -0
- package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +223 -0
- package/node/hooks/index.js +31 -0
- package/node/hooks/utils/index.js +18 -0
- package/node/hooks/utils/useGridApiContext.js +11 -0
- package/node/hooks/utils/useGridApiRef.js +11 -0
- package/node/hooks/utils/useGridRootProps.js +11 -0
- package/node/hooks/utils/useKeepGroupedColumnsHidden.js +66 -0
- package/node/index.js +272 -0
- package/node/models/dataGridPremiumProps.js +5 -0
- package/node/models/gridApiPremium.js +5 -0
- package/node/models/gridGroupingValueGetterParams.js +5 -0
- package/node/models/gridStatePremium.js +5 -0
- package/node/models/index.js +18 -0
- package/node/typeOverloads/index.js +3 -0
- package/node/typeOverloads/modules.js +34 -0
- package/node/typeOverloads/reexports.js +29 -0
- package/node/utils/releaseInfo.js +25 -0
- package/package.json +63 -0
- package/typeOverloads/index.d.ts +1 -0
- package/typeOverloads/index.js +1 -0
- package/typeOverloads/modules.d.ts +0 -0
- package/typeOverloads/modules.js +33 -0
- package/typeOverloads/package.json +6 -0
- package/typeOverloads/reexports.d.ts +22 -0
- package/typeOverloads/reexports.js +6 -0
- package/utils/releaseInfo.d.ts +1 -0
- package/utils/releaseInfo.js +15 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare type GridRowGroupingModel = string[];
|
|
2
|
+
export interface GridRowGroupingState {
|
|
3
|
+
model: GridRowGroupingModel;
|
|
4
|
+
/**
|
|
5
|
+
* Tracks the model on the last pre-processing
|
|
6
|
+
* Allows to check if we need to re-build the grouping columns when the grid upserts a column.
|
|
7
|
+
* TODO: Move outside of the state
|
|
8
|
+
*/
|
|
9
|
+
unstable_sanitizedModelOnLastRowTreeCreation: GridRowGroupingModel;
|
|
10
|
+
}
|
|
11
|
+
export interface GridRowGroupingInitialState {
|
|
12
|
+
model?: GridRowGroupingModel;
|
|
13
|
+
}
|
|
14
|
+
export interface GridRowGroupingApi {
|
|
15
|
+
/**
|
|
16
|
+
* Sets the columns to use as grouping criteria.
|
|
17
|
+
* @param {GridRowGroupingModel} model The columns to use as grouping criteria.
|
|
18
|
+
*/
|
|
19
|
+
setRowGroupingModel: (model: GridRowGroupingModel) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Adds the field to the row grouping model.
|
|
22
|
+
* @param {string} groupingCriteriaField The field from which we want to group the rows.
|
|
23
|
+
* @param {number | undefined} groupingIndex The grouping index at which we want to insert the new grouping criteria. By default, it will be inserted at the end of the model.
|
|
24
|
+
*/
|
|
25
|
+
addRowGroupingCriteria: (groupingCriteriaField: string, groupingIndex?: number) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Remove the field from the row grouping model.
|
|
28
|
+
* @param {string} groupingCriteriaField The field from which we want to stop grouping the rows.
|
|
29
|
+
*/
|
|
30
|
+
removeRowGroupingCriteria: (groupingCriteriaField: string) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Sets the grouping index of a grouping criteria.
|
|
33
|
+
* @param {string} groupingCriteriaField The field of the grouping criteria from which we want to change the grouping index.
|
|
34
|
+
* @param {number} groupingIndex The new grouping index of this grouping criteria.
|
|
35
|
+
*/
|
|
36
|
+
setRowGroupingCriteriaIndex: (groupingCriteriaField: string, groupingIndex: number) => void;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GridStatePremium } from '../../../models/gridStatePremium';
|
|
2
|
+
export declare const gridRowGroupingStateSelector: (state: GridStatePremium) => import("./gridRowGroupingInterfaces").GridRowGroupingState;
|
|
3
|
+
export declare const gridRowGroupingModelSelector: import("@mui/x-data-grid-pro").OutputSelector<GridStatePremium, import("./gridRowGroupingInterfaces").GridRowGroupingModel>;
|
|
4
|
+
export declare const gridRowGroupingSanitizedModelSelector: import("@mui/x-data-grid-pro").OutputSelector<GridStatePremium, string[]>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { gridColumnLookupSelector } from '@mui/x-data-grid-pro';
|
|
2
|
+
import { createSelector } from '@mui/x-data-grid-pro/internals';
|
|
3
|
+
export const gridRowGroupingStateSelector = state => state.rowGrouping;
|
|
4
|
+
export const gridRowGroupingModelSelector = createSelector(gridRowGroupingStateSelector, rowGrouping => rowGrouping.model);
|
|
5
|
+
export const gridRowGroupingSanitizedModelSelector = createSelector(gridRowGroupingModelSelector, gridColumnLookupSelector, (model, columnsLookup) => model.filter(field => !!columnsLookup[field] && columnsLookup[field].groupable));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GridRowTreeConfig, GridFilterState } from '@mui/x-data-grid-pro';
|
|
3
|
+
import { GridAggregatedFilterItemApplier } from '@mui/x-data-grid-pro/internals';
|
|
4
|
+
import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
|
|
5
|
+
import { GridRowGroupingModel } from './gridRowGroupingInterfaces';
|
|
6
|
+
import { GridStatePremium } from '../../../models/gridStatePremium';
|
|
7
|
+
import { GridApiPremium } from '../../../models/gridApiPremium';
|
|
8
|
+
export declare const GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = "__row_group_by_columns_group__";
|
|
9
|
+
export declare const ROW_GROUPING_STRATEGY = "grouping-columns";
|
|
10
|
+
export declare const getRowGroupingFieldFromGroupingCriteria: (groupingCriteria: string | null) => string;
|
|
11
|
+
export declare const getRowGroupingCriteriaFromGroupingField: (groupingColDefField: string) => string | null;
|
|
12
|
+
export declare const isGroupingColumn: (field: string) => boolean;
|
|
13
|
+
interface FilterRowTreeFromTreeDataParams {
|
|
14
|
+
rowTree: GridRowTreeConfig;
|
|
15
|
+
isRowMatchingFilters: GridAggregatedFilterItemApplier | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A leaf is visible if it passed the filter
|
|
19
|
+
* A group is visible if all the following criteria are met:
|
|
20
|
+
* - One of its children is passing the filter
|
|
21
|
+
* - It is passing the filter
|
|
22
|
+
*/
|
|
23
|
+
export declare const filterRowTreeFromGroupingColumns: (params: FilterRowTreeFromTreeDataParams) => Omit<GridFilterState, 'filterModel'>;
|
|
24
|
+
export declare const getColDefOverrides: (groupingColDefProp: DataGridPremiumProcessedProps['groupingColDef'], fields: string[]) => import("@mui/x-data-grid-pro").GridGroupingColDefOverride<any> | null | undefined;
|
|
25
|
+
export declare const mergeStateWithRowGroupingModel: (rowGroupingModel: GridRowGroupingModel) => (state: GridStatePremium) => GridStatePremium;
|
|
26
|
+
export declare const setStrategyAvailability: (apiRef: React.MutableRefObject<GridApiPremium>, disableRowGrouping: boolean) => void;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
|
|
3
|
+
export const GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = '__row_group_by_columns_group__';
|
|
4
|
+
export const ROW_GROUPING_STRATEGY = 'grouping-columns';
|
|
5
|
+
export const getRowGroupingFieldFromGroupingCriteria = groupingCriteria => {
|
|
6
|
+
if (groupingCriteria === null) {
|
|
7
|
+
return GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return `__row_group_by_columns_group_${groupingCriteria}__`;
|
|
11
|
+
};
|
|
12
|
+
export const getRowGroupingCriteriaFromGroupingField = groupingColDefField => {
|
|
13
|
+
const match = groupingColDefField.match(/^__row_group_by_columns_group_(.*)__$/);
|
|
14
|
+
|
|
15
|
+
if (!match) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return match[1];
|
|
20
|
+
};
|
|
21
|
+
export const isGroupingColumn = field => field === GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD || getRowGroupingCriteriaFromGroupingField(field) !== null;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* When filtering a group, we only want to filter according to the items related to this grouping column.
|
|
25
|
+
*/
|
|
26
|
+
const shouldApplyFilterItemOnGroup = (columnField, node) => {
|
|
27
|
+
if (columnField === GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const groupingCriteriaField = getRowGroupingCriteriaFromGroupingField(columnField);
|
|
32
|
+
return groupingCriteriaField === node.groupingField;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* A leaf is visible if it passed the filter
|
|
36
|
+
* A group is visible if all the following criteria are met:
|
|
37
|
+
* - One of its children is passing the filter
|
|
38
|
+
* - It is passing the filter
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
export const filterRowTreeFromGroupingColumns = params => {
|
|
43
|
+
const {
|
|
44
|
+
rowTree,
|
|
45
|
+
isRowMatchingFilters
|
|
46
|
+
} = params;
|
|
47
|
+
const visibleRowsLookup = {};
|
|
48
|
+
const filteredRowsLookup = {};
|
|
49
|
+
const filteredDescendantCountLookup = {};
|
|
50
|
+
|
|
51
|
+
const filterTreeNode = (node, areAncestorsPassingChildren, areAncestorsExpanded) => {
|
|
52
|
+
var _node$children, _node$children2;
|
|
53
|
+
|
|
54
|
+
let isMatchingFilters;
|
|
55
|
+
|
|
56
|
+
if (!isRowMatchingFilters) {
|
|
57
|
+
isMatchingFilters = true;
|
|
58
|
+
} else {
|
|
59
|
+
const shouldApplyItem = node.isAutoGenerated ? columnField => shouldApplyFilterItemOnGroup(columnField, node) : undefined;
|
|
60
|
+
isMatchingFilters = isRowMatchingFilters(node.id, shouldApplyItem);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let filteredDescendantCount = 0;
|
|
64
|
+
(_node$children = node.children) == null ? void 0 : _node$children.forEach(childId => {
|
|
65
|
+
const childNode = rowTree[childId];
|
|
66
|
+
const childSubTreeSize = filterTreeNode(childNode, areAncestorsPassingChildren && isMatchingFilters, areAncestorsExpanded && !!node.childrenExpanded);
|
|
67
|
+
filteredDescendantCount += childSubTreeSize;
|
|
68
|
+
});
|
|
69
|
+
let shouldPassFilters;
|
|
70
|
+
|
|
71
|
+
if (!areAncestorsPassingChildren) {
|
|
72
|
+
shouldPassFilters = false;
|
|
73
|
+
} else if ((_node$children2 = node.children) != null && _node$children2.length) {
|
|
74
|
+
shouldPassFilters = isMatchingFilters && filteredDescendantCount > 0;
|
|
75
|
+
} else {
|
|
76
|
+
shouldPassFilters = isMatchingFilters;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
visibleRowsLookup[node.id] = shouldPassFilters && areAncestorsExpanded;
|
|
80
|
+
filteredRowsLookup[node.id] = shouldPassFilters;
|
|
81
|
+
|
|
82
|
+
if (!shouldPassFilters) {
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
filteredDescendantCountLookup[node.id] = filteredDescendantCount;
|
|
87
|
+
|
|
88
|
+
if (!node.children) {
|
|
89
|
+
return filteredDescendantCount + 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return filteredDescendantCount;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const nodes = Object.values(rowTree);
|
|
96
|
+
|
|
97
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
98
|
+
const node = nodes[i];
|
|
99
|
+
|
|
100
|
+
if (node.depth === 0) {
|
|
101
|
+
filterTreeNode(node, true, true);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
visibleRowsLookup,
|
|
107
|
+
filteredRowsLookup,
|
|
108
|
+
filteredDescendantCountLookup
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export const getColDefOverrides = (groupingColDefProp, fields) => {
|
|
112
|
+
if (typeof groupingColDefProp === 'function') {
|
|
113
|
+
return groupingColDefProp({
|
|
114
|
+
groupingName: ROW_GROUPING_STRATEGY,
|
|
115
|
+
fields
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return groupingColDefProp;
|
|
120
|
+
};
|
|
121
|
+
export const mergeStateWithRowGroupingModel = rowGroupingModel => state => _extends({}, state, {
|
|
122
|
+
rowGrouping: _extends({}, state.rowGrouping, {
|
|
123
|
+
model: rowGroupingModel
|
|
124
|
+
})
|
|
125
|
+
});
|
|
126
|
+
export const setStrategyAvailability = (apiRef, disableRowGrouping) => {
|
|
127
|
+
let isAvailable;
|
|
128
|
+
|
|
129
|
+
if (disableRowGrouping) {
|
|
130
|
+
isAvailable = () => false;
|
|
131
|
+
} else {
|
|
132
|
+
isAvailable = () => {
|
|
133
|
+
const rowGroupingSanitizedModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
134
|
+
return rowGroupingSanitizedModel.length > 0;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
apiRef.current.unstable_setStrategyAvailability('rowTree', ROW_GROUPING_STRATEGY, isAvailable);
|
|
139
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GridStateInitializer } from '@mui/x-data-grid-pro/internals';
|
|
3
|
+
import { GridApiPremium } from '../../../models/gridApiPremium';
|
|
4
|
+
import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
|
|
5
|
+
export declare const rowGroupingStateInitializer: GridStateInitializer<Pick<DataGridPremiumProcessedProps, 'rowGroupingModel' | 'initialState'>>;
|
|
6
|
+
/**
|
|
7
|
+
* @requires useGridColumns (state, method) - can be after, async only
|
|
8
|
+
* @requires useGridRows (state, method) - can be after, async only
|
|
9
|
+
* @requires useGridParamsApi (method) - can be after, async only
|
|
10
|
+
*/
|
|
11
|
+
export declare const useGridRowGrouping: (apiRef: React.MutableRefObject<GridApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'initialState' | 'rowGroupingModel' | 'onRowGroupingModelChange' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault' | 'groupingColDef' | 'rowGroupingColumnMode' | 'disableRowGrouping'>) => void;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import Divider from '@mui/material/Divider';
|
|
4
|
+
import { useGridApiEventHandler, useGridApiMethod, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid-pro';
|
|
5
|
+
import { useGridRegisterPipeProcessor, isDeepEqual } from '@mui/x-data-grid-pro/internals';
|
|
6
|
+
import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector, gridRowGroupingStateSelector } from './gridRowGroupingSelector';
|
|
7
|
+
import { getRowGroupingFieldFromGroupingCriteria, ROW_GROUPING_STRATEGY, isGroupingColumn, mergeStateWithRowGroupingModel, setStrategyAvailability } from './gridRowGroupingUtils';
|
|
8
|
+
import { GridRowGroupableColumnMenuItems } from '../../../components/GridRowGroupableColumnMenuItems';
|
|
9
|
+
import { GridRowGroupingColumnMenuItems } from '../../../components/GridRowGroupingColumnMenuItems';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
export const rowGroupingStateInitializer = (state, props) => {
|
|
12
|
+
var _ref, _props$rowGroupingMod, _props$initialState, _props$initialState$r;
|
|
13
|
+
|
|
14
|
+
return _extends({}, state, {
|
|
15
|
+
rowGrouping: {
|
|
16
|
+
model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model) != null ? _ref : [],
|
|
17
|
+
unstable_sanitizedModelOnLastRowTreeCreation: []
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @requires useGridColumns (state, method) - can be after, async only
|
|
23
|
+
* @requires useGridRows (state, method) - can be after, async only
|
|
24
|
+
* @requires useGridParamsApi (method) - can be after, async only
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export const useGridRowGrouping = (apiRef, props) => {
|
|
28
|
+
apiRef.current.unstable_updateControlState({
|
|
29
|
+
stateId: 'rowGrouping',
|
|
30
|
+
propModel: props.rowGroupingModel,
|
|
31
|
+
propOnChange: props.onRowGroupingModelChange,
|
|
32
|
+
stateSelector: gridRowGroupingModelSelector,
|
|
33
|
+
changeEvent: 'rowGroupingModelChange'
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* API METHODS
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
const setRowGroupingModel = React.useCallback(model => {
|
|
40
|
+
const currentModel = gridRowGroupingModelSelector(apiRef);
|
|
41
|
+
|
|
42
|
+
if (currentModel !== model) {
|
|
43
|
+
apiRef.current.setState(mergeStateWithRowGroupingModel(model));
|
|
44
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping);
|
|
45
|
+
apiRef.current.forceUpdate();
|
|
46
|
+
}
|
|
47
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
48
|
+
const addRowGroupingCriteria = React.useCallback((field, groupingIndex) => {
|
|
49
|
+
const currentModel = gridRowGroupingModelSelector(apiRef);
|
|
50
|
+
|
|
51
|
+
if (currentModel.includes(field)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const cleanGroupingIndex = groupingIndex != null ? groupingIndex : currentModel.length;
|
|
56
|
+
const updatedModel = [...currentModel.slice(0, cleanGroupingIndex), field, ...currentModel.slice(cleanGroupingIndex)];
|
|
57
|
+
apiRef.current.setRowGroupingModel(updatedModel);
|
|
58
|
+
}, [apiRef]);
|
|
59
|
+
const removeRowGroupingCriteria = React.useCallback(field => {
|
|
60
|
+
const currentModel = gridRowGroupingModelSelector(apiRef);
|
|
61
|
+
|
|
62
|
+
if (!currentModel.includes(field)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
apiRef.current.setRowGroupingModel(currentModel.filter(el => el !== field));
|
|
67
|
+
}, [apiRef]);
|
|
68
|
+
const setRowGroupingCriteriaIndex = React.useCallback((field, targetIndex) => {
|
|
69
|
+
const currentModel = gridRowGroupingModelSelector(apiRef);
|
|
70
|
+
const currentTargetIndex = currentModel.indexOf(field);
|
|
71
|
+
|
|
72
|
+
if (currentTargetIndex === -1) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const updatedModel = [...currentModel];
|
|
77
|
+
updatedModel.splice(targetIndex, 0, updatedModel.splice(currentTargetIndex, 1)[0]);
|
|
78
|
+
apiRef.current.setRowGroupingModel(updatedModel);
|
|
79
|
+
}, [apiRef]);
|
|
80
|
+
const rowGroupingApi = {
|
|
81
|
+
setRowGroupingModel,
|
|
82
|
+
addRowGroupingCriteria,
|
|
83
|
+
removeRowGroupingCriteria,
|
|
84
|
+
setRowGroupingCriteriaIndex
|
|
85
|
+
};
|
|
86
|
+
useGridApiMethod(apiRef, rowGroupingApi, 'GridRowGroupingApi');
|
|
87
|
+
/**
|
|
88
|
+
* PRE-PROCESSING
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
const addColumnMenuButtons = React.useCallback((initialValue, columns) => {
|
|
92
|
+
if (props.disableRowGrouping) {
|
|
93
|
+
return initialValue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let menuItems;
|
|
97
|
+
|
|
98
|
+
if (isGroupingColumn(columns.field)) {
|
|
99
|
+
menuItems = /*#__PURE__*/_jsx(GridRowGroupingColumnMenuItems, {});
|
|
100
|
+
} else if (columns.groupable) {
|
|
101
|
+
menuItems = /*#__PURE__*/_jsx(GridRowGroupableColumnMenuItems, {});
|
|
102
|
+
} else {
|
|
103
|
+
menuItems = null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (menuItems == null) {
|
|
107
|
+
return initialValue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return [...initialValue, /*#__PURE__*/_jsx(Divider, {}), menuItems];
|
|
111
|
+
}, [props.disableRowGrouping]);
|
|
112
|
+
const stateExportPreProcessing = React.useCallback(prevState => {
|
|
113
|
+
if (props.disableRowGrouping) {
|
|
114
|
+
return prevState;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const rowGroupingModelToExport = gridRowGroupingModelSelector(apiRef);
|
|
118
|
+
|
|
119
|
+
if (rowGroupingModelToExport.length === 0) {
|
|
120
|
+
return prevState;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return _extends({}, prevState, {
|
|
124
|
+
rowGrouping: {
|
|
125
|
+
model: rowGroupingModelToExport
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
129
|
+
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
130
|
+
var _context$stateToResto;
|
|
131
|
+
|
|
132
|
+
if (props.disableRowGrouping) {
|
|
133
|
+
return params;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const rowGroupingModel = (_context$stateToResto = context.stateToRestore.rowGrouping) == null ? void 0 : _context$stateToResto.model;
|
|
137
|
+
|
|
138
|
+
if (rowGroupingModel != null) {
|
|
139
|
+
apiRef.current.setState(mergeStateWithRowGroupingModel(rowGroupingModel));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return params;
|
|
143
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
144
|
+
useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
|
|
145
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
146
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
147
|
+
/**
|
|
148
|
+
* EVENTS
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
152
|
+
const cellParams = apiRef.current.getCellParams(params.id, params.field);
|
|
153
|
+
|
|
154
|
+
if (isGroupingColumn(cellParams.field) && event.key === ' ' && !event.shiftKey) {
|
|
155
|
+
var _gridFilteredDescenda;
|
|
156
|
+
|
|
157
|
+
event.stopPropagation();
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
const filteredDescendantCount = (_gridFilteredDescenda = gridFilteredDescendantCountLookupSelector(apiRef)[params.id]) != null ? _gridFilteredDescenda : 0;
|
|
160
|
+
const isOnGroupingCell = props.rowGroupingColumnMode === 'single' || getRowGroupingFieldFromGroupingCriteria(params.rowNode.groupingField) === params.field;
|
|
161
|
+
|
|
162
|
+
if (!isOnGroupingCell || filteredDescendantCount === 0) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
apiRef.current.setRowChildrenExpansion(params.id, !params.rowNode.childrenExpanded);
|
|
167
|
+
}
|
|
168
|
+
}, [apiRef, props.rowGroupingColumnMode]);
|
|
169
|
+
const checkGroupingColumnsModelDiff = React.useCallback(() => {
|
|
170
|
+
const rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
171
|
+
const lastGroupingColumnsModelApplied = gridRowGroupingStateSelector(apiRef.current.state).unstable_sanitizedModelOnLastRowTreeCreation;
|
|
172
|
+
|
|
173
|
+
if (!isDeepEqual(lastGroupingColumnsModelApplied, rowGroupingModel)) {
|
|
174
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
175
|
+
rowGrouping: _extends({}, state.rowGrouping, {
|
|
176
|
+
unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
|
|
177
|
+
})
|
|
178
|
+
}));
|
|
179
|
+
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
|
|
180
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
|
|
181
|
+
// TODO: Add a clean way to re-run a strategy processing without publishing a private event
|
|
182
|
+
|
|
183
|
+
if (apiRef.current.unstable_getActiveStrategy('rowTree') === ROW_GROUPING_STRATEGY) {
|
|
184
|
+
apiRef.current.publishEvent('activeStrategyProcessorChange', 'rowTreeCreation');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
188
|
+
useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
|
|
189
|
+
useGridApiEventHandler(apiRef, 'columnsChange', checkGroupingColumnsModelDiff);
|
|
190
|
+
useGridApiEventHandler(apiRef, 'rowGroupingModelChange', checkGroupingColumnsModelDiff);
|
|
191
|
+
/**
|
|
192
|
+
* EFFECTS
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
React.useEffect(() => {
|
|
196
|
+
if (props.rowGroupingModel !== undefined) {
|
|
197
|
+
apiRef.current.setRowGroupingModel(props.rowGroupingModel);
|
|
198
|
+
}
|
|
199
|
+
}, [apiRef, props.rowGroupingModel]);
|
|
200
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
|
|
3
|
+
import { GridApiPremium } from '../../../models/gridApiPremium';
|
|
4
|
+
export declare const useGridRowGroupingPreProcessors: (apiRef: React.MutableRefObject<GridApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'disableRowGrouping' | 'groupingColDef' | 'rowGroupingColumnMode' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault'>) => void;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { gridColumnLookupSelector, gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid-pro';
|
|
4
|
+
import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor, sortRowTree, buildRowTree } from '@mui/x-data-grid-pro/internals';
|
|
5
|
+
import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
|
|
6
|
+
import { createGroupingColDefForAllGroupingCriteria, createGroupingColDefForOneGroupingCriteria } from './createGroupingColDef';
|
|
7
|
+
import { filterRowTreeFromGroupingColumns, getColDefOverrides, ROW_GROUPING_STRATEGY, isGroupingColumn, setStrategyAvailability } from './gridRowGroupingUtils';
|
|
8
|
+
export const useGridRowGroupingPreProcessors = (apiRef, props) => {
|
|
9
|
+
const getGroupingColDefs = React.useCallback(columnsState => {
|
|
10
|
+
if (props.disableRowGrouping) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const groupingColDefProp = props.groupingColDef; // We can't use `gridGroupingRowsSanitizedModelSelector` here because the new columns are not in the state yet
|
|
15
|
+
|
|
16
|
+
const rowGroupingModel = gridRowGroupingModelSelector(apiRef).filter(field => !!columnsState.lookup[field]);
|
|
17
|
+
|
|
18
|
+
if (rowGroupingModel.length === 0) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
switch (props.rowGroupingColumnMode) {
|
|
23
|
+
case 'single':
|
|
24
|
+
{
|
|
25
|
+
return [createGroupingColDefForAllGroupingCriteria({
|
|
26
|
+
apiRef,
|
|
27
|
+
rowGroupingModel,
|
|
28
|
+
colDefOverride: getColDefOverrides(groupingColDefProp, rowGroupingModel),
|
|
29
|
+
columnsLookup: columnsState.lookup
|
|
30
|
+
})];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
case 'multiple':
|
|
34
|
+
{
|
|
35
|
+
return rowGroupingModel.map(groupingCriteria => createGroupingColDefForOneGroupingCriteria({
|
|
36
|
+
groupingCriteria,
|
|
37
|
+
colDefOverride: getColDefOverrides(groupingColDefProp, [groupingCriteria]),
|
|
38
|
+
groupedByColDef: columnsState.lookup[groupingCriteria],
|
|
39
|
+
columnsLookup: columnsState.lookup
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
default:
|
|
44
|
+
{
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, [apiRef, props.groupingColDef, props.rowGroupingColumnMode, props.disableRowGrouping]);
|
|
49
|
+
const updateGroupingColumn = React.useCallback(columnsState => {
|
|
50
|
+
const groupingColDefs = getGroupingColDefs(columnsState);
|
|
51
|
+
let newColumnFields = [];
|
|
52
|
+
const newColumnsLookup = {}; // We only keep the non-grouping columns
|
|
53
|
+
|
|
54
|
+
columnsState.all.forEach(field => {
|
|
55
|
+
if (!isGroupingColumn(field)) {
|
|
56
|
+
newColumnFields.push(field);
|
|
57
|
+
newColumnsLookup[field] = columnsState.lookup[field];
|
|
58
|
+
}
|
|
59
|
+
}); // We add the grouping column
|
|
60
|
+
|
|
61
|
+
groupingColDefs.forEach(groupingColDef => {
|
|
62
|
+
const matchingGroupingColDef = columnsState.lookup[groupingColDef.field];
|
|
63
|
+
|
|
64
|
+
if (matchingGroupingColDef) {
|
|
65
|
+
groupingColDef.width = matchingGroupingColDef.width;
|
|
66
|
+
groupingColDef.flex = matchingGroupingColDef.flex;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
newColumnsLookup[groupingColDef.field] = groupingColDef;
|
|
70
|
+
});
|
|
71
|
+
const startIndex = newColumnFields[0] === '__check__' ? 1 : 0;
|
|
72
|
+
newColumnFields = [...newColumnFields.slice(0, startIndex), ...groupingColDefs.map(colDef => colDef.field), ...newColumnFields.slice(startIndex)];
|
|
73
|
+
columnsState.all = newColumnFields;
|
|
74
|
+
columnsState.lookup = newColumnsLookup;
|
|
75
|
+
return columnsState;
|
|
76
|
+
}, [getGroupingColDefs]);
|
|
77
|
+
const createRowTree = React.useCallback(params => {
|
|
78
|
+
const rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
79
|
+
const columnsLookup = gridColumnLookupSelector(apiRef);
|
|
80
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
81
|
+
rowGrouping: _extends({}, state.rowGrouping, {
|
|
82
|
+
unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
|
|
83
|
+
})
|
|
84
|
+
}));
|
|
85
|
+
const distinctValues = Object.fromEntries(rowGroupingModel.map(groupingField => [groupingField, {
|
|
86
|
+
lookup: {},
|
|
87
|
+
list: []
|
|
88
|
+
}]));
|
|
89
|
+
|
|
90
|
+
const getCellGroupingCriteria = ({
|
|
91
|
+
row,
|
|
92
|
+
id,
|
|
93
|
+
colDef
|
|
94
|
+
}) => {
|
|
95
|
+
let key;
|
|
96
|
+
|
|
97
|
+
if (colDef.groupingValueGetter) {
|
|
98
|
+
const groupingValueGetterParams = {
|
|
99
|
+
colDef,
|
|
100
|
+
field: colDef.field,
|
|
101
|
+
value: row[colDef.field],
|
|
102
|
+
id,
|
|
103
|
+
row,
|
|
104
|
+
rowNode: {
|
|
105
|
+
isAutoGenerated: false,
|
|
106
|
+
id
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
key = colDef.groupingValueGetter(groupingValueGetterParams);
|
|
110
|
+
} else {
|
|
111
|
+
key = row[colDef.field];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
key,
|
|
116
|
+
field: colDef.field
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
params.ids.forEach(rowId => {
|
|
121
|
+
const row = params.idRowsLookup[rowId];
|
|
122
|
+
rowGroupingModel.forEach(groupingCriteria => {
|
|
123
|
+
const {
|
|
124
|
+
key
|
|
125
|
+
} = getCellGroupingCriteria({
|
|
126
|
+
row,
|
|
127
|
+
id: rowId,
|
|
128
|
+
colDef: columnsLookup[groupingCriteria]
|
|
129
|
+
});
|
|
130
|
+
const groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
|
|
131
|
+
|
|
132
|
+
if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
|
|
133
|
+
groupingFieldsDistinctKeys.lookup[key.toString()] = true;
|
|
134
|
+
groupingFieldsDistinctKeys.list.push(key);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
const rows = params.ids.map(rowId => {
|
|
139
|
+
const row = params.idRowsLookup[rowId];
|
|
140
|
+
const parentPath = rowGroupingModel.map(groupingField => getCellGroupingCriteria({
|
|
141
|
+
row,
|
|
142
|
+
id: rowId,
|
|
143
|
+
colDef: columnsLookup[groupingField]
|
|
144
|
+
})).filter(cell => cell.key != null);
|
|
145
|
+
const leafGroupingCriteria = {
|
|
146
|
+
key: rowId.toString(),
|
|
147
|
+
field: null
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
path: [...parentPath, leafGroupingCriteria],
|
|
151
|
+
id: rowId
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
return buildRowTree(_extends({}, params, {
|
|
155
|
+
rows,
|
|
156
|
+
defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
|
|
157
|
+
isGroupExpandedByDefault: props.isGroupExpandedByDefault,
|
|
158
|
+
groupingName: ROW_GROUPING_STRATEGY
|
|
159
|
+
}));
|
|
160
|
+
}, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
|
|
161
|
+
const filterRows = React.useCallback(params => {
|
|
162
|
+
const rowTree = gridRowTreeSelector(apiRef);
|
|
163
|
+
return filterRowTreeFromGroupingColumns({
|
|
164
|
+
rowTree,
|
|
165
|
+
isRowMatchingFilters: params.isRowMatchingFilters
|
|
166
|
+
});
|
|
167
|
+
}, [apiRef]);
|
|
168
|
+
const sortRows = React.useCallback(params => {
|
|
169
|
+
const rowTree = gridRowTreeSelector(apiRef);
|
|
170
|
+
const rowIds = gridRowIdsSelector(apiRef);
|
|
171
|
+
return sortRowTree({
|
|
172
|
+
rowTree,
|
|
173
|
+
rowIds,
|
|
174
|
+
sortRowList: params.sortRowList,
|
|
175
|
+
disableChildrenSorting: false
|
|
176
|
+
});
|
|
177
|
+
}, [apiRef]);
|
|
178
|
+
useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
|
|
179
|
+
useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'rowTreeCreation', createRowTree);
|
|
180
|
+
useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'filtering', filterRows);
|
|
181
|
+
useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'sorting', sortRows);
|
|
182
|
+
/**
|
|
183
|
+
* 1ST RENDER
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
useFirstRender(() => {
|
|
187
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping);
|
|
188
|
+
});
|
|
189
|
+
/**
|
|
190
|
+
* EFFECTS
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
const isFirstRender = React.useRef(true);
|
|
194
|
+
React.useEffect(() => {
|
|
195
|
+
if (!isFirstRender.current) {
|
|
196
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping);
|
|
197
|
+
} else {
|
|
198
|
+
isFirstRender.current = false;
|
|
199
|
+
}
|
|
200
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
201
|
+
};
|
package/hooks/index.d.ts
ADDED
package/hooks/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useKeepGroupedColumnsHidden';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useKeepGroupedColumnsHidden';
|