@mui/x-data-grid-premium 8.10.2 → 8.11.1
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 +214 -13
- package/DataGridPremium/DataGridPremium.js +6 -4
- package/DataGridPremium/useDataGridPremiumComponent.d.ts +2 -1
- package/DataGridPremium/useDataGridPremiumComponent.js +2 -2
- package/esm/DataGridPremium/DataGridPremium.js +6 -4
- package/esm/DataGridPremium/useDataGridPremiumComponent.d.ts +2 -1
- package/esm/DataGridPremium/useDataGridPremiumComponent.js +2 -2
- package/esm/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +1 -0
- package/esm/hooks/features/clipboard/useGridClipboardImport.js +1 -1
- package/esm/hooks/features/export/serializer/setupExcelExportWebWorker.js +1 -2
- package/esm/hooks/features/rowGrouping/createGroupingColDef.d.ts +2 -1
- package/esm/hooks/features/rowGrouping/createGroupingColDef.js +31 -7
- package/esm/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +1 -0
- package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/esm/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
- package/esm/hooks/features/rowGrouping/useGridRowGrouping.js +48 -2
- package/esm/hooks/features/rowReorder/operations.d.ts +40 -0
- package/esm/hooks/features/rowReorder/operations.js +535 -0
- package/esm/hooks/features/rowReorder/reorderExecutor.d.ts +15 -0
- package/esm/hooks/features/rowReorder/reorderExecutor.js +25 -0
- package/esm/hooks/features/rowReorder/reorderValidator.d.ts +16 -0
- package/esm/hooks/features/rowReorder/reorderValidator.js +116 -0
- package/esm/hooks/features/rowReorder/types.d.ts +42 -0
- package/esm/hooks/features/rowReorder/types.js +1 -0
- package/esm/hooks/features/rowReorder/utils.d.ts +127 -0
- package/esm/hooks/features/rowReorder/utils.js +343 -0
- package/esm/hooks/features/rows/useGridRowsOverridableMethods.d.ts +7 -0
- package/esm/hooks/features/rows/useGridRowsOverridableMethods.js +52 -0
- package/esm/index.js +1 -1
- package/esm/models/gridGroupingValueSetter.d.ts +14 -0
- package/esm/models/gridGroupingValueSetter.js +1 -0
- package/esm/models/index.d.ts +1 -0
- package/esm/models/index.js +1 -0
- package/esm/typeOverloads/modules.d.ts +7 -1
- package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +1 -0
- package/hooks/features/clipboard/useGridClipboardImport.js +1 -1
- package/hooks/features/export/serializer/setupExcelExportWebWorker.js +1 -2
- package/hooks/features/rowGrouping/createGroupingColDef.d.ts +2 -1
- package/hooks/features/rowGrouping/createGroupingColDef.js +31 -7
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +1 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
- package/hooks/features/rowGrouping/useGridRowGrouping.js +46 -0
- package/hooks/features/rowReorder/operations.d.ts +40 -0
- package/hooks/features/rowReorder/operations.js +546 -0
- package/hooks/features/rowReorder/reorderExecutor.d.ts +15 -0
- package/hooks/features/rowReorder/reorderExecutor.js +31 -0
- package/hooks/features/rowReorder/reorderValidator.d.ts +16 -0
- package/hooks/features/rowReorder/reorderValidator.js +122 -0
- package/hooks/features/rowReorder/types.d.ts +42 -0
- package/hooks/features/rowReorder/types.js +5 -0
- package/hooks/features/rowReorder/utils.d.ts +127 -0
- package/hooks/features/rowReorder/utils.js +360 -0
- package/hooks/features/rows/useGridRowsOverridableMethods.d.ts +7 -0
- package/hooks/features/rows/useGridRowsOverridableMethods.js +60 -0
- package/index.js +1 -1
- package/models/gridGroupingValueSetter.d.ts +14 -0
- package/models/gridGroupingValueSetter.js +5 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +11 -0
- package/package.json +14 -14
- package/typeOverloads/modules.d.ts +7 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { gridRowTreeSelector, gridExpandedSortedRowIdsSelector, gridRowNodeSelector } from '@mui/x-data-grid-pro';
|
|
3
|
+
import { gridExpandedSortedRowIndexLookupSelector } from '@mui/x-data-grid-pro/internals';
|
|
4
|
+
import { rowGroupingReorderExecutor } from "../rowReorder/reorderExecutor.js";
|
|
5
|
+
export const useGridRowsOverridableMethods = (apiRef, props) => {
|
|
6
|
+
const {
|
|
7
|
+
processRowUpdate,
|
|
8
|
+
onProcessRowUpdateError
|
|
9
|
+
} = props;
|
|
10
|
+
const setRowIndex = React.useCallback(async (sourceRowId, targetOriginalIndex) => {
|
|
11
|
+
const sortedFilteredRowIds = gridExpandedSortedRowIdsSelector(apiRef);
|
|
12
|
+
const sortedFilteredRowIndexLookup = gridExpandedSortedRowIndexLookupSelector(apiRef);
|
|
13
|
+
const rowTree = gridRowTreeSelector(apiRef);
|
|
14
|
+
const sourceNode = gridRowNodeSelector(apiRef, sourceRowId);
|
|
15
|
+
if (!sourceNode) {
|
|
16
|
+
throw new Error(`MUI X: No row with id #${sourceRowId} found.`);
|
|
17
|
+
}
|
|
18
|
+
if (sourceNode.type === 'footer') {
|
|
19
|
+
throw new Error(`MUI X: The row reordering do not support reordering of footer rows.`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Row Grouping Reordering Use Cases
|
|
24
|
+
* =================================
|
|
25
|
+
*
|
|
26
|
+
* | Case | Source Node | Target Node | Parent Relationship | Action |
|
|
27
|
+
* | :--- | :---------- | :---------- | :------------------------ | :-------------------------------------------------------------------------- |
|
|
28
|
+
* | A ✅ | Leaf | Leaf | Same parent | Swap positions (similar to flat tree structure) |
|
|
29
|
+
* | B ✅ | Group | Group | Same parent | Swap positions (along with their descendants) |
|
|
30
|
+
* | C ✅ | Leaf | Leaf | Different parents | Make source node a child of target's parent and update parent nodes in tree |
|
|
31
|
+
* | D ✅ | Leaf | Group | Different parents | Make source a child of target, only allowed at same depth as source.parent |
|
|
32
|
+
* | E ❌ | Leaf | Group | Target is source's parent | Not allowed, will have no difference |
|
|
33
|
+
* | F ❌ | Group | Leaf | Any | Not allowed, will break the row grouping criteria |
|
|
34
|
+
* | G ✅ | Group | Group | Different parents | Only allowed at same depth to preserve grouping criteria |
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const executionContext = {
|
|
38
|
+
sourceRowId,
|
|
39
|
+
placeholderIndex: targetOriginalIndex,
|
|
40
|
+
sortedFilteredRowIds,
|
|
41
|
+
sortedFilteredRowIndexLookup,
|
|
42
|
+
rowTree,
|
|
43
|
+
apiRef,
|
|
44
|
+
processRowUpdate,
|
|
45
|
+
onProcessRowUpdateError
|
|
46
|
+
};
|
|
47
|
+
await rowGroupingReorderExecutor.execute(executionContext);
|
|
48
|
+
}, [apiRef, processRowUpdate, onProcessRowUpdateError]);
|
|
49
|
+
return {
|
|
50
|
+
setRowIndex
|
|
51
|
+
};
|
|
52
|
+
};
|
package/esm/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
+
import { GridValidRowModel, GridColDef, GridKeyValue } from '@mui/x-data-grid-pro';
|
|
3
|
+
import { GridApiPremium } from "./gridApiPremium.js";
|
|
4
|
+
/**
|
|
5
|
+
* Function signature for setting a grouping value on a row.
|
|
6
|
+
* This is the inverse operation of GridGroupingValueGetter.
|
|
7
|
+
*
|
|
8
|
+
* @param {GridKeyValue | null | undefined} groupingValue The grouping value to set
|
|
9
|
+
* @param {R} row The row to update
|
|
10
|
+
* @param {GridColDef<R>} column The column definition
|
|
11
|
+
* @param {RefObject<GridApiPremium>} apiRef Reference to the grid API
|
|
12
|
+
* @returns {R} The updated row with the new grouping value applied
|
|
13
|
+
*/
|
|
14
|
+
export type GridGroupingValueSetter<R extends GridValidRowModel = GridValidRowModel> = (groupingValue: GridKeyValue | null | undefined, row: R, column: GridColDef<R>, apiRef: RefObject<GridApiPremium>) => R;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/models/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./gridApiPremium.js";
|
|
2
2
|
export * from "./gridGroupingValueGetter.js";
|
|
3
|
+
export * from "./gridGroupingValueSetter.js";
|
|
3
4
|
export * from "./gridPremiumIconSlotsComponent.js";
|
|
4
5
|
export * from "./gridPremiumSlotsComponent.js";
|
|
5
6
|
export * from "./gridPastedValueParser.js";
|
package/esm/models/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./gridApiPremium.js";
|
|
2
2
|
export * from "./gridGroupingValueGetter.js";
|
|
3
|
+
export * from "./gridGroupingValueSetter.js";
|
|
3
4
|
export * from "./gridPremiumIconSlotsComponent.js";
|
|
4
5
|
export * from "./gridPremiumSlotsComponent.js";
|
|
5
6
|
export * from "./gridPastedValueParser.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GridExportDisplayOptions, GridValidRowModel } from '@mui/x-data-grid-pro';
|
|
2
2
|
import type { GridPipeProcessingLookupPro, GridControlledStateEventLookupPro, GridApiCachesPro, GridEventLookupPro } from '@mui/x-data-grid-pro/typeOverloads';
|
|
3
|
-
import type { GridGroupingValueGetter, GridPastedValueParser } from "../models/index.js";
|
|
3
|
+
import type { GridGroupingValueGetter, GridGroupingValueSetter, GridPastedValueParser } from "../models/index.js";
|
|
4
4
|
import type { GridRowGroupingModel, GridAggregationModel, GridAggregationCellMeta, GridAggregationHeaderMeta, GridCellSelectionModel, Conversation } from "../hooks/index.js";
|
|
5
5
|
import { GridRowGroupingInternalCache } from "../hooks/features/rowGrouping/gridRowGroupingInterfaces.js";
|
|
6
6
|
import { GridAggregationInternalCache } from "../hooks/features/aggregation/gridAggregationInterfaces.js";
|
|
@@ -107,6 +107,12 @@ export interface GridColDefPremium<R extends GridValidRowModel = any, V = any, F
|
|
|
107
107
|
* @returns {GridKeyValue | null | undefined} The cell key.
|
|
108
108
|
*/
|
|
109
109
|
groupingValueGetter?: GridGroupingValueGetter<R>;
|
|
110
|
+
/**
|
|
111
|
+
* Function that takes a grouping value and updates the row data accordingly.
|
|
112
|
+
* This is the inverse operation of `groupingValueGetter`.
|
|
113
|
+
* @returns {R} The updated row.
|
|
114
|
+
*/
|
|
115
|
+
groupingValueSetter?: GridGroupingValueSetter<R>;
|
|
110
116
|
/**
|
|
111
117
|
* Function that takes the clipboard-pasted value and converts it to a value used internally.
|
|
112
118
|
* @returns {V} The converted value.
|
|
@@ -56,6 +56,7 @@ export declare const unwrapColumnFromAggregation: (column: GridColDef) => GridBa
|
|
|
56
56
|
aggregable?: boolean;
|
|
57
57
|
availableAggregationFunctions?: string[];
|
|
58
58
|
groupingValueGetter?: import("../../../index.js").GridGroupingValueGetter<import("@mui/x-data-grid").GridValidRowModel> | undefined;
|
|
59
|
+
groupingValueSetter?: import("../../../index.js").GridGroupingValueSetter<import("@mui/x-data-grid").GridValidRowModel> | undefined;
|
|
59
60
|
pastedValueParser?: import("../../../index.js").GridPastedValueParser<import("@mui/x-data-grid").GridValidRowModel, any, any> | undefined;
|
|
60
61
|
pivotable?: boolean;
|
|
61
62
|
};
|
|
@@ -127,7 +127,7 @@ class CellValueUpdater {
|
|
|
127
127
|
if (onProcessRowUpdateError) {
|
|
128
128
|
onProcessRowUpdateError(errorThrown);
|
|
129
129
|
} else if (process.env.NODE_ENV !== 'production') {
|
|
130
|
-
(0, _warning.warnOnce)(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
|
|
130
|
+
(0, _warning.warnOnce)(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
133
|
try {
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.setupExcelExportWebWorker = setupExcelExportWebWorker;
|
|
7
7
|
var _utils = require("./utils");
|
|
8
8
|
function setupExcelExportWebWorker(workerOptions = {}) {
|
|
9
|
-
|
|
10
|
-
addEventListener('message', async event => {
|
|
9
|
+
globalThis.addEventListener('message', async event => {
|
|
11
10
|
const {
|
|
12
11
|
namespace,
|
|
13
12
|
serializedColumns,
|
|
@@ -2,6 +2,7 @@ import { RefObject } from '@mui/x-internals/types';
|
|
|
2
2
|
import { GridColDef, GridGroupingColDefOverride } from '@mui/x-data-grid-pro';
|
|
3
3
|
import { GridColumnRawLookup, RowGroupingStrategy } from '@mui/x-data-grid-pro/internals';
|
|
4
4
|
import { GridApiPremium } from "../../../models/gridApiPremium.js";
|
|
5
|
+
import type { GridRowGroupingModel } from "./gridRowGroupingInterfaces.js";
|
|
5
6
|
interface CreateGroupingColDefMonoCriteriaParams {
|
|
6
7
|
columnsLookup: GridColumnRawLookup;
|
|
7
8
|
/**
|
|
@@ -35,7 +36,7 @@ interface CreateGroupingColDefSeveralCriteriaParams {
|
|
|
35
36
|
/**
|
|
36
37
|
* The fields from which we are grouping the rows.
|
|
37
38
|
*/
|
|
38
|
-
rowGroupingModel:
|
|
39
|
+
rowGroupingModel: GridRowGroupingModel;
|
|
39
40
|
/**
|
|
40
41
|
* The col def properties the user wants to override.
|
|
41
42
|
* This value comes `prop.groupingColDef`.
|
|
@@ -81,11 +81,34 @@ const groupedByColValueFormatter = groupedByColDef => (value, row, _, apiRef) =>
|
|
|
81
81
|
}
|
|
82
82
|
return value;
|
|
83
83
|
};
|
|
84
|
-
|
|
84
|
+
function getGroupingCriteriaProperties(groupedByColDef, rowGroupingColumnMode, rowGroupingModel = [], columnsLookup = {}) {
|
|
85
|
+
let valueFormatter;
|
|
86
|
+
if (rowGroupingColumnMode === 'single' && rowGroupingModel.length > 1) {
|
|
87
|
+
// In single column grouping mode, the `valueFormatter` of the grouping column uses
|
|
88
|
+
// value formatters from original columns for each of the grouping criteria
|
|
89
|
+
valueFormatter = (value, row, column, apiRef) => {
|
|
90
|
+
const rowId = (0, _xDataGridPro.gridRowIdSelector)(apiRef, row);
|
|
91
|
+
const rowNode = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, rowId);
|
|
92
|
+
if (rowNode.type === 'group') {
|
|
93
|
+
const originalColDef = columnsLookup[rowNode.groupingField];
|
|
94
|
+
if (originalColDef.type === 'singleSelect') {
|
|
95
|
+
// the default valueFormatter of a singleSelect colDef won't work with the grouping column values
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
const columnValueFormatter = originalColDef.valueFormatter;
|
|
99
|
+
if (typeof columnValueFormatter === 'function') {
|
|
100
|
+
return columnValueFormatter(value, row, column, apiRef);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return value;
|
|
104
|
+
};
|
|
105
|
+
} else {
|
|
106
|
+
valueFormatter = groupedByColDef.valueFormatter ? groupedByColValueFormatter(groupedByColDef) : undefined;
|
|
107
|
+
}
|
|
85
108
|
const properties = {
|
|
86
109
|
sortable: groupedByColDef.sortable,
|
|
87
110
|
filterable: groupedByColDef.filterable,
|
|
88
|
-
valueFormatter
|
|
111
|
+
valueFormatter,
|
|
89
112
|
valueOptions: (0, _internals.isSingleSelectColDef)(groupedByColDef) ? groupedByColDef.valueOptions : undefined,
|
|
90
113
|
sortComparator: (v1, v2, cellParams1, cellParams2) => {
|
|
91
114
|
// We only want to sort the groups of the current grouping criteria
|
|
@@ -97,11 +120,12 @@ const getGroupingCriteriaProperties = (groupedByColDef, applyHeaderName) => {
|
|
|
97
120
|
},
|
|
98
121
|
filterOperators: groupedByColDef.filterOperators
|
|
99
122
|
};
|
|
123
|
+
const applyHeaderName = !(rowGroupingColumnMode === 'single' && rowGroupingModel.length > 1);
|
|
100
124
|
if (applyHeaderName) {
|
|
101
125
|
properties.headerName = groupedByColDef.headerName ?? groupedByColDef.field;
|
|
102
126
|
}
|
|
103
127
|
return properties;
|
|
104
|
-
}
|
|
128
|
+
}
|
|
105
129
|
/**
|
|
106
130
|
* Creates the `GridColDef` for a grouping column that only takes care of a single grouping criteria
|
|
107
131
|
*/
|
|
@@ -183,11 +207,11 @@ const createGroupingColDefForOneGroupingCriteria = ({
|
|
|
183
207
|
// By default, we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `groupedColDef`.
|
|
184
208
|
let sourceProperties;
|
|
185
209
|
if (mainGroupingCriteria && mainGroupingCriteria === groupingCriteria) {
|
|
186
|
-
sourceProperties = getGroupingCriteriaProperties(groupedByColDef,
|
|
210
|
+
sourceProperties = getGroupingCriteriaProperties(groupedByColDef, 'multiple');
|
|
187
211
|
} else if (leafColDef) {
|
|
188
212
|
sourceProperties = getLeafProperties(leafColDef);
|
|
189
213
|
} else {
|
|
190
|
-
sourceProperties = getGroupingCriteriaProperties(groupedByColDef,
|
|
214
|
+
sourceProperties = getGroupingCriteriaProperties(groupedByColDef, 'multiple');
|
|
191
215
|
}
|
|
192
216
|
|
|
193
217
|
// The properties that can't be overridden with `colDefOverride`
|
|
@@ -274,11 +298,11 @@ const createGroupingColDefForAllGroupingCriteria = ({
|
|
|
274
298
|
if (process.env.NODE_ENV !== "production") commonProperties.renderCell.displayName = "commonProperties.renderCell";
|
|
275
299
|
let sourceProperties;
|
|
276
300
|
if (mainGroupingCriteria && rowGroupingModel.includes(mainGroupingCriteria)) {
|
|
277
|
-
sourceProperties = getGroupingCriteriaProperties(columnsLookup[mainGroupingCriteria],
|
|
301
|
+
sourceProperties = getGroupingCriteriaProperties(columnsLookup[mainGroupingCriteria], 'single', rowGroupingModel, columnsLookup);
|
|
278
302
|
} else if (leafColDef) {
|
|
279
303
|
sourceProperties = getLeafProperties(leafColDef);
|
|
280
304
|
} else {
|
|
281
|
-
sourceProperties = getGroupingCriteriaProperties(columnsLookup[rowGroupingModel[0]], rowGroupingModel
|
|
305
|
+
sourceProperties = getGroupingCriteriaProperties(columnsLookup[rowGroupingModel[0]], 'single', rowGroupingModel, columnsLookup);
|
|
282
306
|
}
|
|
283
307
|
|
|
284
308
|
// The properties that can't be overridden with `colDefOverride`
|
|
@@ -40,5 +40,6 @@ export interface GridRowGroupingApi {
|
|
|
40
40
|
export interface GridGroupingRule<R extends GridValidRowModel = GridValidRowModel, V = any> {
|
|
41
41
|
field: string;
|
|
42
42
|
groupingValueGetter?: GridColDef<R, V>['groupingValueGetter'];
|
|
43
|
+
groupingValueSetter?: GridColDef<R, V>['groupingValueSetter'];
|
|
43
44
|
}
|
|
44
45
|
export type GridGroupingRules<R extends GridValidRowModel = GridValidRowModel> = GridGroupingRule<R>[];
|
|
@@ -181,7 +181,8 @@ const getGroupingRules = ({
|
|
|
181
181
|
columnsLookup
|
|
182
182
|
}) => sanitizedRowGroupingModel.map(field => ({
|
|
183
183
|
field,
|
|
184
|
-
groupingValueGetter: columnsLookup[field]?.groupingValueGetter
|
|
184
|
+
groupingValueGetter: columnsLookup[field]?.groupingValueGetter,
|
|
185
|
+
groupingValueSetter: columnsLookup[field]?.groupingValueSetter
|
|
185
186
|
}));
|
|
186
187
|
|
|
187
188
|
/**
|
|
@@ -197,6 +198,9 @@ const areGroupingRulesEqual = (newValue, previousValue) => {
|
|
|
197
198
|
if (previousRule.groupingValueGetter !== newRule.groupingValueGetter) {
|
|
198
199
|
return false;
|
|
199
200
|
}
|
|
201
|
+
if (previousRule.groupingValueSetter !== newRule.groupingValueSetter) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
200
204
|
if (previousRule.field !== newRule.field) {
|
|
201
205
|
return false;
|
|
202
206
|
}
|
|
@@ -8,4 +8,4 @@ export declare const rowGroupingStateInitializer: GridStateInitializer<Pick<Data
|
|
|
8
8
|
* @requires useGridRows (state, method) - can be after, async only
|
|
9
9
|
* @requires useGridParamsApi (method) - can be after, async only
|
|
10
10
|
*/
|
|
11
|
-
export declare const useGridRowGrouping: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "initialState" | "rowGroupingModel" | "onRowGroupingModelChange" | "defaultGroupingExpansionDepth" | "isGroupExpandedByDefault" | "rowGroupingColumnMode" | "disableRowGrouping" | "slotProps" | "slots" | "dataSource">) => void;
|
|
11
|
+
export declare const useGridRowGrouping: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "initialState" | "rowGroupingModel" | "onRowGroupingModelChange" | "defaultGroupingExpansionDepth" | "isGroupExpandedByDefault" | "rowGroupingColumnMode" | "disableRowGrouping" | "slotProps" | "slots" | "dataSource" | "treeData">) => void;
|
|
@@ -13,6 +13,7 @@ var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
|
13
13
|
var _internals = require("@mui/x-data-grid-pro/internals");
|
|
14
14
|
var _gridRowGroupingSelector = require("./gridRowGroupingSelector");
|
|
15
15
|
var _gridRowGroupingUtils = require("./gridRowGroupingUtils");
|
|
16
|
+
var _reorderValidator = require("../rowReorder/reorderValidator");
|
|
16
17
|
const rowGroupingStateInitializer = (state, props, apiRef) => {
|
|
17
18
|
apiRef.current.caches.rowGrouping = {
|
|
18
19
|
rulesOnLastRowTreeCreation: []
|
|
@@ -176,6 +177,51 @@ const useGridRowGrouping = (apiRef, props) => {
|
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
}, [apiRef, props.disableRowGrouping]);
|
|
180
|
+
const getRowReorderTargetIndex = React.useCallback((initialValue, {
|
|
181
|
+
sourceRowId,
|
|
182
|
+
targetRowId,
|
|
183
|
+
dropPosition,
|
|
184
|
+
dragDirection
|
|
185
|
+
}) => {
|
|
186
|
+
if ((0, _xDataGridPro.gridRowMaximumTreeDepthSelector)(apiRef) === 1 || props.treeData) {
|
|
187
|
+
return initialValue;
|
|
188
|
+
}
|
|
189
|
+
const expandedSortedRowIndexLookup = (0, _internals.gridExpandedSortedRowIndexLookupSelector)(apiRef);
|
|
190
|
+
const expandedSortedRowIds = (0, _xDataGridPro.gridExpandedSortedRowIdsSelector)(apiRef);
|
|
191
|
+
const rowTree = (0, _xDataGridPro.gridRowTreeSelector)(apiRef);
|
|
192
|
+
const sourceRowIndex = expandedSortedRowIndexLookup[sourceRowId];
|
|
193
|
+
const targetRowIndex = expandedSortedRowIndexLookup[targetRowId];
|
|
194
|
+
const sourceNode = rowTree[sourceRowId];
|
|
195
|
+
const targetNode = rowTree[targetRowId];
|
|
196
|
+
const prevNode = targetRowIndex > 0 ? rowTree[expandedSortedRowIds[targetRowIndex - 1]] : null;
|
|
197
|
+
const nextNode = targetRowIndex < expandedSortedRowIds.length - 1 ? rowTree[expandedSortedRowIds[targetRowIndex + 1]] : null;
|
|
198
|
+
|
|
199
|
+
// Basic validity checks
|
|
200
|
+
if (!sourceNode || !targetNode) {
|
|
201
|
+
return -1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Create context object
|
|
205
|
+
const context = {
|
|
206
|
+
sourceNode,
|
|
207
|
+
targetNode,
|
|
208
|
+
prevNode,
|
|
209
|
+
nextNode,
|
|
210
|
+
rowTree,
|
|
211
|
+
dropPosition,
|
|
212
|
+
dragDirection,
|
|
213
|
+
targetRowIndex,
|
|
214
|
+
sourceRowIndex,
|
|
215
|
+
expandedSortedRowIndexLookup
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Check if the reorder is valid
|
|
219
|
+
if (_reorderValidator.rowGroupingReorderValidator.validate(context)) {
|
|
220
|
+
return dropPosition === 'below' ? targetRowIndex + 1 : targetRowIndex;
|
|
221
|
+
}
|
|
222
|
+
return -1;
|
|
223
|
+
}, [apiRef, props.treeData]);
|
|
224
|
+
(0, _internals.useGridRegisterPipeProcessor)(apiRef, 'getRowReorderTargetIndex', getRowReorderTargetIndex);
|
|
179
225
|
(0, _xDataGridPro.useGridEvent)(apiRef, 'cellKeyDown', handleCellKeyDown);
|
|
180
226
|
(0, _xDataGridPro.useGridEvent)(apiRef, 'columnsChange', checkGroupingColumnsModelDiff);
|
|
181
227
|
(0, _xDataGridPro.useGridEvent)(apiRef, 'rowGroupingModelChange', checkGroupingColumnsModelDiff);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ReorderOperation, ReorderExecutionContext } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all reorder operations.
|
|
4
|
+
* Provides abstract methods for operation detection and execution.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseReorderOperation {
|
|
7
|
+
abstract readonly operationType: string;
|
|
8
|
+
/**
|
|
9
|
+
* Detects if this operation can handle the given context.
|
|
10
|
+
*/
|
|
11
|
+
abstract detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
|
|
12
|
+
/**
|
|
13
|
+
* Executes the detected operation.
|
|
14
|
+
*/
|
|
15
|
+
abstract executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): Promise<void> | void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Handles reordering of items within the same parent group.
|
|
19
|
+
*/
|
|
20
|
+
export declare class SameParentSwapOperation extends BaseReorderOperation {
|
|
21
|
+
readonly operationType = "same-parent-swap";
|
|
22
|
+
detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
|
|
23
|
+
executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Handles moving leaf nodes between different parent groups.
|
|
27
|
+
*/
|
|
28
|
+
export declare class CrossParentLeafOperation extends BaseReorderOperation {
|
|
29
|
+
readonly operationType = "cross-parent-leaf";
|
|
30
|
+
detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
|
|
31
|
+
executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Handles moving entire groups between different parents.
|
|
35
|
+
*/
|
|
36
|
+
export declare class CrossParentGroupOperation extends BaseReorderOperation {
|
|
37
|
+
readonly operationType = "cross-parent-group";
|
|
38
|
+
detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
|
|
39
|
+
executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): Promise<void>;
|
|
40
|
+
}
|