@mui/x-data-grid 8.11.2 → 8.12.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 +231 -0
- package/DataGrid/DataGrid.js +3 -1
- package/DataGrid/useDataGridComponent.js +2 -2
- package/colDef/gridActionsColDef.js +1 -0
- package/colDef/gridBooleanColDef.js +1 -0
- package/colDef/gridCheckboxSelectionColDef.js +1 -0
- package/colDef/gridStringColDef.js +1 -0
- package/components/GridShadowScrollArea.js +2 -2
- package/components/GridSkeletonLoadingOverlay.js +2 -2
- package/components/cell/GridCell.js +7 -5
- package/components/panel/filterPanel/GridFilterInputBoolean.js +2 -2
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +2 -2
- package/components/panel/filterPanel/GridFilterInputValue.js +2 -2
- package/components/quickFilter/QuickFilterControl.js +1 -1
- package/constants/localeTextConstants.js +29 -0
- package/esm/DataGrid/DataGrid.js +3 -1
- package/esm/DataGrid/useDataGridComponent.js +2 -2
- package/esm/colDef/gridActionsColDef.js +1 -0
- package/esm/colDef/gridBooleanColDef.js +1 -0
- package/esm/colDef/gridCheckboxSelectionColDef.js +1 -0
- package/esm/colDef/gridStringColDef.js +1 -0
- package/esm/components/GridShadowScrollArea.js +2 -2
- package/esm/components/GridSkeletonLoadingOverlay.js +2 -2
- package/esm/components/cell/GridCell.js +7 -5
- package/esm/components/panel/filterPanel/GridFilterInputBoolean.js +2 -2
- package/esm/components/panel/filterPanel/GridFilterInputSingleSelect.js +2 -2
- package/esm/components/panel/filterPanel/GridFilterInputValue.js +2 -2
- package/esm/components/quickFilter/QuickFilterControl.js +1 -1
- package/esm/constants/localeTextConstants.js +29 -0
- package/esm/hooks/features/columnResize/useGridColumnResize.js +2 -2
- package/esm/hooks/features/columns/useGridColumns.js +21 -4
- package/esm/hooks/features/filter/gridFilterSelector.d.ts +12 -4
- package/esm/hooks/features/filter/gridFilterSelector.js +21 -4
- package/esm/hooks/features/filter/gridFilterState.d.ts +3 -1
- package/esm/hooks/features/filter/gridFilterUtils.d.ts +3 -3
- package/esm/hooks/features/filter/gridFilterUtils.js +23 -13
- package/esm/hooks/features/filter/useGridFilter.d.ts +2 -1
- package/esm/hooks/features/filter/useGridFilter.js +7 -5
- package/esm/hooks/features/rows/gridRowsSelector.d.ts +9 -0
- package/esm/hooks/features/rows/gridRowsSelector.js +12 -0
- package/esm/hooks/features/rows/index.d.ts +1 -1
- package/esm/hooks/features/rows/index.js +1 -1
- package/esm/hooks/features/rows/useGridParamsApi.js +16 -7
- package/esm/hooks/features/sorting/gridSortingUtils.d.ts +3 -1
- package/esm/hooks/features/sorting/gridSortingUtils.js +10 -4
- package/esm/hooks/features/sorting/useGridSorting.d.ts +2 -1
- package/esm/hooks/features/sorting/useGridSorting.js +4 -3
- package/esm/index.js +1 -1
- package/esm/internals/index.d.ts +1 -1
- package/esm/internals/index.js +1 -1
- package/esm/locales/arSD.js +31 -0
- package/esm/locales/beBY.js +31 -0
- package/esm/locales/bgBG.js +31 -0
- package/esm/locales/bnBD.js +31 -0
- package/esm/locales/csCZ.js +31 -0
- package/esm/locales/daDK.js +31 -0
- package/esm/locales/deDE.js +32 -0
- package/esm/locales/elGR.js +31 -0
- package/esm/locales/esES.js +31 -0
- package/esm/locales/faIR.js +31 -0
- package/esm/locales/fiFI.js +31 -0
- package/esm/locales/frFR.js +32 -2
- package/esm/locales/heIL.js +31 -0
- package/esm/locales/hrHR.js +31 -0
- package/esm/locales/huHU.js +31 -0
- package/esm/locales/hyAM.js +31 -0
- package/esm/locales/idID.d.ts +1 -1
- package/esm/locales/idID.js +32 -0
- package/esm/locales/isIS.js +31 -0
- package/esm/locales/itIT.js +31 -0
- package/esm/locales/jaJP.js +31 -0
- package/esm/locales/koKR.js +31 -0
- package/esm/locales/nbNO.js +31 -0
- package/esm/locales/nlNL.js +31 -0
- package/esm/locales/nnNO.js +32 -0
- package/esm/locales/plPL.js +31 -0
- package/esm/locales/ptBR.js +31 -0
- package/esm/locales/ptPT.js +31 -0
- package/esm/locales/roRO.js +31 -0
- package/esm/locales/ruRU.js +31 -0
- package/esm/locales/skSK.js +31 -0
- package/esm/locales/svSE.js +31 -0
- package/esm/locales/trTR.js +31 -0
- package/esm/locales/ukUA.js +31 -0
- package/esm/locales/urPK.js +31 -0
- package/esm/locales/viVN.js +31 -0
- package/esm/locales/zhCN.js +31 -0
- package/esm/locales/zhHK.js +31 -0
- package/esm/locales/zhTW.js +31 -0
- package/esm/material/augmentation.d.ts +8 -0
- package/esm/material/index.js +147 -49
- package/esm/material/variables.js +2 -1
- package/esm/models/api/gridLocaleTextApi.d.ts +27 -0
- package/esm/models/api/gridParamsApi.d.ts +5 -1
- package/esm/models/configuration/gridAggregationConfiguration.d.ts +25 -0
- package/esm/models/configuration/gridAggregationConfiguration.js +1 -0
- package/esm/models/configuration/gridConfiguration.d.ts +6 -9
- package/esm/models/gridBaseSlots.d.ts +15 -0
- package/esm/models/gridFilterItem.d.ts +4 -2
- package/esm/models/gridFilterOperator.d.ts +1 -1
- package/esm/models/gridSlotsComponent.d.ts +10 -0
- package/esm/models/gridSlotsComponentsProps.d.ts +5 -1
- package/hooks/features/columnResize/useGridColumnResize.js +2 -2
- package/hooks/features/columns/useGridColumns.js +23 -6
- package/hooks/features/filter/gridFilterSelector.d.ts +12 -4
- package/hooks/features/filter/gridFilterSelector.js +22 -5
- package/hooks/features/filter/gridFilterState.d.ts +3 -1
- package/hooks/features/filter/gridFilterUtils.d.ts +3 -3
- package/hooks/features/filter/gridFilterUtils.js +23 -13
- package/hooks/features/filter/useGridFilter.d.ts +2 -1
- package/hooks/features/filter/useGridFilter.js +7 -5
- package/hooks/features/rows/gridRowsSelector.d.ts +9 -0
- package/hooks/features/rows/gridRowsSelector.js +12 -0
- package/hooks/features/rows/index.d.ts +1 -1
- package/hooks/features/rows/index.js +7 -0
- package/hooks/features/rows/useGridParamsApi.js +16 -7
- package/hooks/features/sorting/gridSortingUtils.d.ts +3 -1
- package/hooks/features/sorting/gridSortingUtils.js +10 -4
- package/hooks/features/sorting/useGridSorting.d.ts +2 -1
- package/hooks/features/sorting/useGridSorting.js +4 -3
- package/index.js +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/index.js +7 -0
- package/locales/arSD.js +31 -0
- package/locales/beBY.js +31 -0
- package/locales/bgBG.js +31 -0
- package/locales/bnBD.js +31 -0
- package/locales/csCZ.js +31 -0
- package/locales/daDK.js +31 -0
- package/locales/deDE.js +32 -0
- package/locales/elGR.js +31 -0
- package/locales/esES.js +31 -0
- package/locales/faIR.js +31 -0
- package/locales/fiFI.js +31 -0
- package/locales/frFR.js +32 -2
- package/locales/heIL.js +31 -0
- package/locales/hrHR.js +31 -0
- package/locales/huHU.js +31 -0
- package/locales/hyAM.js +31 -0
- package/locales/idID.d.ts +1 -1
- package/locales/idID.js +32 -0
- package/locales/isIS.js +31 -0
- package/locales/itIT.js +31 -0
- package/locales/jaJP.js +31 -0
- package/locales/koKR.js +31 -0
- package/locales/nbNO.js +31 -0
- package/locales/nlNL.js +31 -0
- package/locales/nnNO.js +32 -0
- package/locales/plPL.js +31 -0
- package/locales/ptBR.js +31 -0
- package/locales/ptPT.js +31 -0
- package/locales/roRO.js +31 -0
- package/locales/ruRU.js +31 -0
- package/locales/skSK.js +31 -0
- package/locales/svSE.js +31 -0
- package/locales/trTR.js +31 -0
- package/locales/ukUA.js +31 -0
- package/locales/urPK.js +31 -0
- package/locales/viVN.js +31 -0
- package/locales/zhCN.js +31 -0
- package/locales/zhHK.js +31 -0
- package/locales/zhTW.js +31 -0
- package/material/augmentation.d.ts +8 -0
- package/material/index.js +147 -49
- package/material/variables.js +2 -1
- package/models/api/gridLocaleTextApi.d.ts +27 -0
- package/models/api/gridParamsApi.d.ts +5 -1
- package/models/configuration/gridAggregationConfiguration.d.ts +25 -0
- package/models/configuration/gridAggregationConfiguration.js +5 -0
- package/models/configuration/gridConfiguration.d.ts +6 -9
- package/models/gridBaseSlots.d.ts +15 -0
- package/models/gridFilterItem.d.ts +4 -2
- package/models/gridFilterOperator.d.ts +1 -1
- package/models/gridSlotsComponent.d.ts +10 -0
- package/models/gridSlotsComponentsProps.d.ts +5 -1
- package/package.json +3 -3
|
@@ -118,7 +118,7 @@ process.env.NODE_ENV !== "production" ? QuickFilterControl.propTypes = {
|
|
|
118
118
|
slotProps: PropTypes.object,
|
|
119
119
|
style: PropTypes.object,
|
|
120
120
|
tabIndex: PropTypes.number,
|
|
121
|
-
type: PropTypes.
|
|
121
|
+
type: PropTypes.string,
|
|
122
122
|
value: PropTypes.string
|
|
123
123
|
} : void 0;
|
|
124
124
|
export { QuickFilterControl };
|
|
@@ -32,6 +32,8 @@ export const GRID_DEFAULT_LOCALE_TEXT = {
|
|
|
32
32
|
toolbarExportExcel: 'Download as Excel',
|
|
33
33
|
// Toolbar pivot button
|
|
34
34
|
toolbarPivot: 'Pivot',
|
|
35
|
+
// Toolbar charts button
|
|
36
|
+
toolbarCharts: 'Charts',
|
|
35
37
|
// Toolbar AI Assistant button
|
|
36
38
|
toolbarAssistant: 'AI Assistant',
|
|
37
39
|
// Columns management text
|
|
@@ -111,6 +113,7 @@ export const GRID_DEFAULT_LOCALE_TEXT = {
|
|
|
111
113
|
columnMenuSortAsc: 'Sort by ASC',
|
|
112
114
|
columnMenuSortDesc: 'Sort by DESC',
|
|
113
115
|
columnMenuManagePivot: 'Manage pivot',
|
|
116
|
+
columnMenuManageCharts: 'Manage charts',
|
|
114
117
|
// Column header text
|
|
115
118
|
columnHeaderFiltersTooltipActive: count => count !== 1 ? `${count} active filters` : `${count} active filter`,
|
|
116
119
|
columnHeaderFiltersLabel: 'Show filters',
|
|
@@ -179,6 +182,7 @@ export const GRID_DEFAULT_LOCALE_TEXT = {
|
|
|
179
182
|
rowReorderingHeaderName: 'Row reordering',
|
|
180
183
|
// Aggregation
|
|
181
184
|
aggregationMenuItemHeader: 'Aggregation',
|
|
185
|
+
aggregationFunctionLabelNone: 'none',
|
|
182
186
|
aggregationFunctionLabelSum: 'sum',
|
|
183
187
|
aggregationFunctionLabelAvg: 'avg',
|
|
184
188
|
aggregationFunctionLabelMin: 'min',
|
|
@@ -212,6 +216,31 @@ export const GRID_DEFAULT_LOCALE_TEXT = {
|
|
|
212
216
|
pivotDragToValues: 'Drag here to create values',
|
|
213
217
|
pivotYearColumnHeaderName: '(Year)',
|
|
214
218
|
pivotQuarterColumnHeaderName: '(Quarter)',
|
|
219
|
+
// Charts configuration panel
|
|
220
|
+
chartsNoCharts: 'There are no charts available',
|
|
221
|
+
chartsChartNotSelected: 'Select a chart type to configure its options',
|
|
222
|
+
chartsTabChart: 'Chart',
|
|
223
|
+
chartsTabFields: 'Fields',
|
|
224
|
+
chartsTabCustomize: 'Customize',
|
|
225
|
+
chartsCloseButton: 'Close charts configuration',
|
|
226
|
+
chartsSyncButtonLabel: 'Sync chart',
|
|
227
|
+
chartsSearchPlaceholder: 'Search fields',
|
|
228
|
+
chartsSearchLabel: 'Search fields',
|
|
229
|
+
chartsSearchClear: 'Clear search',
|
|
230
|
+
chartsNoFields: 'No fields',
|
|
231
|
+
chartsFieldBlocked: 'This field cannot be added to any section',
|
|
232
|
+
chartsCategories: 'Categories',
|
|
233
|
+
chartsSeries: 'Series',
|
|
234
|
+
chartsMenuAddToDimensions: dimensionLabel => `Add to ${dimensionLabel}`,
|
|
235
|
+
chartsMenuAddToValues: valuesLabel => `Add to ${valuesLabel}`,
|
|
236
|
+
chartsMenuMoveUp: 'Move up',
|
|
237
|
+
chartsMenuMoveDown: 'Move down',
|
|
238
|
+
chartsMenuMoveToTop: 'Move to top',
|
|
239
|
+
chartsMenuMoveToBottom: 'Move to bottom',
|
|
240
|
+
chartsMenuOptions: 'Field options',
|
|
241
|
+
chartsMenuRemove: 'Remove',
|
|
242
|
+
chartsDragToDimensions: dimensionLabel => `Drag here to use column as ${dimensionLabel}`,
|
|
243
|
+
chartsDragToValues: valuesLabel => `Drag here to use column as ${valuesLabel}`,
|
|
215
244
|
// AI Assistant panel
|
|
216
245
|
aiAssistantPanelTitle: 'AI Assistant',
|
|
217
246
|
aiAssistantPanelClose: 'Close AI Assistant',
|
|
@@ -41,7 +41,7 @@ function computeNewWidth(initialOffsetToSeparator, clickX, columnBounds, resizeD
|
|
|
41
41
|
} else {
|
|
42
42
|
newWidth += columnBounds.right - clickX;
|
|
43
43
|
}
|
|
44
|
-
return newWidth;
|
|
44
|
+
return Math.round(newWidth);
|
|
45
45
|
}
|
|
46
46
|
function computeOffsetToSeparator(clickX, columnBounds, resizeDirection) {
|
|
47
47
|
if (resizeDirection === 'Left') {
|
|
@@ -560,5 +560,5 @@ function updateProperty(element, property, delta) {
|
|
|
560
560
|
if (!element) {
|
|
561
561
|
return;
|
|
562
562
|
}
|
|
563
|
-
element.style[property] = `${
|
|
563
|
+
element.style[property] = `${Math.round(parseFloat(element.style[property])) + delta}px`;
|
|
564
564
|
}
|
|
@@ -11,7 +11,7 @@ import { useGridRegisterPipeProcessor, useGridRegisterPipeApplier } from "../../
|
|
|
11
11
|
import { EMPTY_PINNED_COLUMN_FIELDS } from "./gridColumnsInterfaces.js";
|
|
12
12
|
import { hydrateColumnsWidth, createColumnsState, COLUMNS_DIMENSION_PROPERTIES } from "./gridColumnsUtils.js";
|
|
13
13
|
import { GridPreferencePanelsValue } from "../preferencesPanel/index.js";
|
|
14
|
-
import { gridPivotActiveSelector } from "../pivoting/
|
|
14
|
+
import { gridPivotActiveSelector, gridPivotInitialColumnsSelector } from "../pivoting/gridPivotingSelectors.js";
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
export const columnsStateInitializer = (state, props, apiRef) => {
|
|
17
17
|
apiRef.current.caches.columns = {
|
|
@@ -82,13 +82,30 @@ export function useGridColumns(apiRef, props) {
|
|
|
82
82
|
}
|
|
83
83
|
}, [apiRef]);
|
|
84
84
|
const updateColumns = React.useCallback(columns => {
|
|
85
|
+
let columnsToUpdate = columns;
|
|
85
86
|
if (gridPivotActiveSelector(apiRef)) {
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
const nonPivotColumns = [];
|
|
88
|
+
const pivotColumns = [];
|
|
89
|
+
const pivotInitialColumns = gridPivotInitialColumnsSelector(apiRef);
|
|
90
|
+
columns.forEach(column => {
|
|
91
|
+
const isNonPivotColumn = pivotInitialColumns.has(column.field);
|
|
92
|
+
if (isNonPivotColumn) {
|
|
93
|
+
nonPivotColumns.push(column);
|
|
94
|
+
} else {
|
|
95
|
+
pivotColumns.push(column);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
if (nonPivotColumns.length > 0) {
|
|
99
|
+
apiRef.current.updateNonPivotColumns(nonPivotColumns);
|
|
100
|
+
}
|
|
101
|
+
if (pivotColumns.length === 0) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
columnsToUpdate = pivotColumns;
|
|
88
105
|
}
|
|
89
106
|
const columnsState = createColumnsState({
|
|
90
107
|
apiRef,
|
|
91
|
-
columnsToUpsert:
|
|
108
|
+
columnsToUpsert: columnsToUpdate,
|
|
92
109
|
initialState: undefined,
|
|
93
110
|
keepOnlyColumnsToUpsert: false,
|
|
94
111
|
updateInitialVisibilityModel: true
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GridStateCommunity } from "../../../models/gridStateCommunity.js";
|
|
2
|
-
import { GridRowId } from "../../../models/gridRows.js";
|
|
2
|
+
import { GridRowEntry, GridRowId, GridValidRowModel } from "../../../models/gridRows.js";
|
|
3
3
|
import { GridFilterItem } from "../../../models/gridFilterItem.js";
|
|
4
4
|
/**
|
|
5
5
|
* Get the current filter model.
|
|
@@ -48,7 +48,7 @@ export declare const gridFilteredDescendantCountLookupSelector: (args_0: import(
|
|
|
48
48
|
*/
|
|
49
49
|
export declare const gridExpandedSortedRowEntriesSelector: (args_0: import("react").RefObject<{
|
|
50
50
|
state: GridStateCommunity;
|
|
51
|
-
} | null>) =>
|
|
51
|
+
} | null>) => GridRowEntry<GridValidRowModel>[];
|
|
52
52
|
/**
|
|
53
53
|
* Get the id of the rows accessible after the filtering process.
|
|
54
54
|
* Does not contain the collapsed children.
|
|
@@ -64,7 +64,7 @@ export declare const gridExpandedSortedRowIdsSelector: (args_0: import("react").
|
|
|
64
64
|
*/
|
|
65
65
|
export declare const gridFilteredSortedRowEntriesSelector: (args_0: import("react").RefObject<{
|
|
66
66
|
state: GridStateCommunity;
|
|
67
|
-
} | null>) =>
|
|
67
|
+
} | null>) => GridRowEntry<GridValidRowModel>[];
|
|
68
68
|
/**
|
|
69
69
|
* Get the id of the rows accessible after the filtering process.
|
|
70
70
|
* Contains the collapsed children.
|
|
@@ -82,13 +82,21 @@ export declare const gridFilteredSortedRowIdsSelector: (args_0: import("react").
|
|
|
82
82
|
export declare const gridExpandedSortedRowTreeLevelPositionLookupSelector: (args_0: import("react").RefObject<{
|
|
83
83
|
state: GridStateCommunity;
|
|
84
84
|
} | null>) => Record<GridRowId, number>;
|
|
85
|
+
/**
|
|
86
|
+
* Get the id and the model of the rows per depth level, accessible after the filtering process.
|
|
87
|
+
* Returns an array of arrays, where each array index contains the rows for the depth level equal to the index.
|
|
88
|
+
* @category Filtering
|
|
89
|
+
*/
|
|
90
|
+
export declare const gridFilteredSortedDepthRowEntriesSelector: (args_0: import("react").RefObject<{
|
|
91
|
+
state: GridStateCommunity;
|
|
92
|
+
} | null>) => GridRowEntry<GridValidRowModel>[][];
|
|
85
93
|
/**
|
|
86
94
|
* Get the id and the model of the top level rows accessible after the filtering process.
|
|
87
95
|
* @category Filtering
|
|
88
96
|
*/
|
|
89
97
|
export declare const gridFilteredSortedTopLevelRowEntriesSelector: (args_0: import("react").RefObject<{
|
|
90
98
|
state: GridStateCommunity;
|
|
91
|
-
} | null>) =>
|
|
99
|
+
} | null>) => GridRowEntry<GridValidRowModel>[];
|
|
92
100
|
/**
|
|
93
101
|
* Get the amount of rows accessible after the filtering process.
|
|
94
102
|
* @category Filtering
|
|
@@ -107,16 +107,33 @@ export const gridExpandedSortedRowTreeLevelPositionLookupSelector = createSelect
|
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
* Get the id and the model of the
|
|
110
|
+
* Get the id and the model of the rows per depth level, accessible after the filtering process.
|
|
111
|
+
* Returns an array of arrays, where each array index contains the rows for the depth level equal to the index.
|
|
111
112
|
* @category Filtering
|
|
112
113
|
*/
|
|
113
|
-
export const
|
|
114
|
+
export const gridFilteredSortedDepthRowEntriesSelector = createSelectorMemoized(gridFilteredSortedRowEntriesSelector, gridRowTreeSelector, gridRowMaximumTreeDepthSelector, (sortedRows, rowTree, rowTreeDepth) => {
|
|
114
115
|
if (rowTreeDepth < 2) {
|
|
115
|
-
return
|
|
116
|
+
return [sortedRows];
|
|
116
117
|
}
|
|
117
|
-
return
|
|
118
|
+
return sortedRows.reduce((acc, row) => {
|
|
119
|
+
const depth = rowTree[row.id]?.depth;
|
|
120
|
+
if (depth === undefined) {
|
|
121
|
+
return acc;
|
|
122
|
+
}
|
|
123
|
+
if (!acc[depth]) {
|
|
124
|
+
acc[depth] = [];
|
|
125
|
+
}
|
|
126
|
+
acc[depth].push(row);
|
|
127
|
+
return acc;
|
|
128
|
+
}, [[]]);
|
|
118
129
|
});
|
|
119
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Get the id and the model of the top level rows accessible after the filtering process.
|
|
133
|
+
* @category Filtering
|
|
134
|
+
*/
|
|
135
|
+
export const gridFilteredSortedTopLevelRowEntriesSelector = createSelector(gridFilteredSortedDepthRowEntriesSelector, filteredSortedDepthRows => filteredSortedDepthRows[0] ?? []);
|
|
136
|
+
|
|
120
137
|
/**
|
|
121
138
|
* Get the amount of rows accessible after the filtering process.
|
|
122
139
|
* @category Filtering
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GridFilterItem } from "../../../models/gridFilterItem.js";
|
|
2
2
|
import { GridFilterModel } from "../../../models/gridFilterModel.js";
|
|
3
|
-
import { GridRowId, GridValidRowModel } from "../../../models/gridRows.js";
|
|
3
|
+
import { GridRowId, GridRowModel, GridValidRowModel } from "../../../models/gridRows.js";
|
|
4
|
+
import { GridColDef } from "../../../models/colDef/index.js";
|
|
4
5
|
export type GridFilterItemResult = {
|
|
5
6
|
[key: Required<GridFilterItem>['id']]: boolean;
|
|
6
7
|
};
|
|
@@ -52,6 +53,7 @@ export type GridAggregatedFilterItemApplier = (row: GridValidRowModel, shouldApp
|
|
|
52
53
|
export interface GridFilteringMethodParams {
|
|
53
54
|
isRowMatchingFilters: GridAggregatedFilterItemApplier | null;
|
|
54
55
|
filterModel: GridFilterModel;
|
|
56
|
+
filterValueGetter: (row: GridRowModel, column: GridColDef) => any;
|
|
55
57
|
}
|
|
56
58
|
export type GridFilteringMethodValue = Omit<GridFilterState, 'filterModel'>;
|
|
57
59
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
-
import { GridFilterItem, GridFilterModel } from "../../../models/index.js";
|
|
2
|
+
import { GridColDef, GridFilterItem, GridFilterModel, GridRowModel } from "../../../models/index.js";
|
|
3
3
|
import type { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
|
|
4
4
|
import { GridStateCommunity } from "../../../models/gridStateCommunity.js";
|
|
5
5
|
import { GridAggregatedFilterItemApplier, GridFilterItemResult, GridQuickFilterValueResult } from "./gridFilterState.js";
|
|
@@ -15,9 +15,9 @@ export declare const sanitizeFilterModel: (model: GridFilterModel, disableMultip
|
|
|
15
15
|
export declare const mergeStateWithFilterModel: (filterModel: GridFilterModel, disableMultipleColumnsFiltering: boolean, apiRef: RefObject<GridPrivateApiCommunity>) => (filteringState: GridStateCommunity["filter"]) => GridStateCommunity["filter"];
|
|
16
16
|
export declare const removeDiacritics: (value: unknown) => unknown;
|
|
17
17
|
export declare const shouldQuickFilterExcludeHiddenColumns: (filterModel: GridFilterModel) => boolean;
|
|
18
|
-
export declare const buildAggregatedFilterApplier: (filterModel: GridFilterModel, apiRef: RefObject<GridPrivateApiCommunity>, disableEval: boolean) => GridAggregatedFilterItemApplier;
|
|
18
|
+
export declare const buildAggregatedFilterApplier: (filterModel: GridFilterModel, filterValueGetter: (row: GridRowModel, column: GridColDef) => any, apiRef: RefObject<GridPrivateApiCommunity>, disableEval: boolean) => GridAggregatedFilterItemApplier;
|
|
19
19
|
type FilterCache = {
|
|
20
20
|
cleanedFilterItems?: GridFilterItem[];
|
|
21
21
|
};
|
|
22
|
-
export declare const passFilterLogic: (allFilterItemResults: (null | GridFilterItemResult)[], allQuickFilterResults: (null | GridQuickFilterValueResult)[], filterModel: GridFilterModel, apiRef: RefObject<GridPrivateApiCommunity>, cache: FilterCache) => boolean;
|
|
22
|
+
export declare const passFilterLogic: (allFilterItemResults: (null | GridFilterItemResult)[], allQuickFilterResults: (null | GridQuickFilterValueResult)[], filterModel: GridFilterModel, filterValueGetter: (row: GridRowModel, column: GridColDef) => any, apiRef: RefObject<GridPrivateApiCommunity>, cache: FilterCache) => boolean;
|
|
23
23
|
export {};
|
|
@@ -81,7 +81,7 @@ export const removeDiacritics = value => {
|
|
|
81
81
|
}
|
|
82
82
|
return value;
|
|
83
83
|
};
|
|
84
|
-
const getFilterCallbackFromItem = (filterItem, apiRef) => {
|
|
84
|
+
const getFilterCallbackFromItem = (filterItem, filterValueGetter, apiRef) => {
|
|
85
85
|
if (!filterItem.field || !filterItem.operator) {
|
|
86
86
|
return null;
|
|
87
87
|
}
|
|
@@ -121,7 +121,7 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
|
|
|
121
121
|
return {
|
|
122
122
|
item: newFilterItem,
|
|
123
123
|
fn: row => {
|
|
124
|
-
let value =
|
|
124
|
+
let value = filterValueGetter(row, column);
|
|
125
125
|
if (ignoreDiacritics) {
|
|
126
126
|
value = removeDiacritics(value);
|
|
127
127
|
}
|
|
@@ -132,16 +132,21 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
|
|
|
132
132
|
let filterItemsApplierId = 1;
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
+
* @name filterValueGetter
|
|
136
|
+
* @param {GridRowModel} row The row to get the value from.
|
|
137
|
+
* @param {GridColDef} column The column that the filter is applied on.
|
|
138
|
+
*
|
|
135
139
|
* Generates a method to easily check if a row is matching the current filter model.
|
|
136
140
|
* @param {GridFilterModel} filterModel The model with which we want to filter the rows.
|
|
141
|
+
* @param {FilterValueGetterFn} filterValueGetter The function to get the value to filter by.
|
|
137
142
|
* @param {RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
|
|
138
143
|
* @returns {GridAggregatedFilterItemApplier | null} A method that checks if a row is matching the current filter model. If `null`, we consider that all the rows are matching the filters.
|
|
139
144
|
*/
|
|
140
|
-
const buildAggregatedFilterItemsApplier = (filterModel, apiRef, disableEval) => {
|
|
145
|
+
const buildAggregatedFilterItemsApplier = (filterModel, filterValueGetter, apiRef, disableEval) => {
|
|
141
146
|
const {
|
|
142
147
|
items
|
|
143
148
|
} = filterModel;
|
|
144
|
-
const appliers = items.map(item => getFilterCallbackFromItem(item, apiRef)).filter(callback => !!callback);
|
|
149
|
+
const appliers = items.map(item => getFilterCallbackFromItem(item, filterValueGetter, apiRef)).filter(callback => !!callback);
|
|
145
150
|
if (appliers.length === 0) {
|
|
146
151
|
return null;
|
|
147
152
|
}
|
|
@@ -181,12 +186,17 @@ export const shouldQuickFilterExcludeHiddenColumns = filterModel => {
|
|
|
181
186
|
};
|
|
182
187
|
|
|
183
188
|
/**
|
|
189
|
+
* @name filterValueGetter
|
|
190
|
+
* @param {GridRowModel} row The row to get the value from.
|
|
191
|
+
* @param {GridColDef} column The column that the filter is applied on.
|
|
192
|
+
*
|
|
184
193
|
* Generates a method to easily check if a row is matching the current quick filter.
|
|
185
194
|
* @param {any[]} filterModel The model with which we want to filter the rows.
|
|
195
|
+
* @param {FilterValueGetterFn} filterValueGetter The function to get the value to filter by.
|
|
186
196
|
* @param {RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
|
|
187
197
|
* @returns {GridAggregatedFilterItemApplier | null} A method that checks if a row is matching the current filter model. If `null`, we consider that all the rows are matching the filters.
|
|
188
198
|
*/
|
|
189
|
-
const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
199
|
+
const buildAggregatedQuickFilterApplier = (filterModel, filterValueGetter, apiRef) => {
|
|
190
200
|
const quickFilterValues = filterModel.quickFilterValues?.filter(Boolean) ?? [];
|
|
191
201
|
if (quickFilterValues.length === 0) {
|
|
192
202
|
return null;
|
|
@@ -239,7 +249,7 @@ const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
|
239
249
|
continue;
|
|
240
250
|
}
|
|
241
251
|
const applier = appliers[v];
|
|
242
|
-
let value =
|
|
252
|
+
let value = filterValueGetter(row, column);
|
|
243
253
|
if (applier.fn === null) {
|
|
244
254
|
continue;
|
|
245
255
|
}
|
|
@@ -257,23 +267,23 @@ const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
|
257
267
|
return result;
|
|
258
268
|
};
|
|
259
269
|
};
|
|
260
|
-
export const buildAggregatedFilterApplier = (filterModel, apiRef, disableEval) => {
|
|
261
|
-
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(filterModel, apiRef, disableEval);
|
|
262
|
-
const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(filterModel, apiRef);
|
|
270
|
+
export const buildAggregatedFilterApplier = (filterModel, filterValueGetter, apiRef, disableEval) => {
|
|
271
|
+
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(filterModel, filterValueGetter, apiRef, disableEval);
|
|
272
|
+
const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(filterModel, filterValueGetter, apiRef);
|
|
263
273
|
return function isRowMatchingFilters(row, shouldApplyFilter, result) {
|
|
264
274
|
result.passingFilterItems = isRowMatchingFilterItems?.(row, shouldApplyFilter) ?? null;
|
|
265
275
|
result.passingQuickFilterValues = isRowMatchingQuickFilter?.(row, shouldApplyFilter) ?? null;
|
|
266
276
|
};
|
|
267
277
|
};
|
|
268
278
|
const isNotNull = result => result != null;
|
|
269
|
-
const filterModelItems = (cache, apiRef, items) => {
|
|
279
|
+
const filterModelItems = (cache, filterValueGetter, apiRef, items) => {
|
|
270
280
|
if (!cache.cleanedFilterItems) {
|
|
271
|
-
cache.cleanedFilterItems = items.filter(item => getFilterCallbackFromItem(item, apiRef) !== null);
|
|
281
|
+
cache.cleanedFilterItems = items.filter(item => getFilterCallbackFromItem(item, filterValueGetter, apiRef) !== null);
|
|
272
282
|
}
|
|
273
283
|
return cache.cleanedFilterItems;
|
|
274
284
|
};
|
|
275
|
-
export const passFilterLogic = (allFilterItemResults, allQuickFilterResults, filterModel, apiRef, cache) => {
|
|
276
|
-
const cleanedFilterItems = filterModelItems(cache, apiRef, filterModel.items);
|
|
285
|
+
export const passFilterLogic = (allFilterItemResults, allQuickFilterResults, filterModel, filterValueGetter, apiRef, cache) => {
|
|
286
|
+
const cleanedFilterItems = filterModelItems(cache, filterValueGetter, apiRef, filterModel.items);
|
|
277
287
|
const cleanedFilterItemResults = allFilterItemResults.filter(isNotNull);
|
|
278
288
|
const cleanedQuickFilterResults = allQuickFilterResults.filter(isNotNull);
|
|
279
289
|
|
|
@@ -2,10 +2,11 @@ import { RefObject } from '@mui/x-internals/types';
|
|
|
2
2
|
import { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
|
|
3
3
|
import { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
|
|
4
4
|
import { GridStateInitializer } from "../../utils/useGridInitializeState.js";
|
|
5
|
+
import type { GridConfiguration } from "../../../models/configuration/gridConfiguration.js";
|
|
5
6
|
export declare const filterStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'filterModel' | 'initialState' | 'disableMultipleColumnsFiltering'>>;
|
|
6
7
|
/**
|
|
7
8
|
* @requires useGridColumns (method, event)
|
|
8
9
|
* @requires useGridParamsApi (method)
|
|
9
10
|
* @requires useGridRows (event)
|
|
10
11
|
*/
|
|
11
|
-
export declare const useGridFilter: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "rows" | "initialState" | "filterModel" | "getRowId" | "onFilterModelChange" | "filterMode" | "disableMultipleColumnsFiltering" | "slots" | "slotProps" | "disableColumnFilter" | "disableEval" | "ignoreDiacritics"
|
|
12
|
+
export declare const useGridFilter: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "rows" | "initialState" | "filterModel" | "getRowId" | "onFilterModelChange" | "filterMode" | "disableMultipleColumnsFiltering" | "slots" | "slotProps" | "disableColumnFilter" | "disableEval" | "ignoreDiacritics">, configuration: GridConfiguration) => void;
|
|
@@ -45,7 +45,7 @@ function createMemoizedValues() {
|
|
|
45
45
|
* @requires useGridParamsApi (method)
|
|
46
46
|
* @requires useGridRows (event)
|
|
47
47
|
*/
|
|
48
|
-
export const useGridFilter = (apiRef, props) => {
|
|
48
|
+
export const useGridFilter = (apiRef, props, configuration) => {
|
|
49
49
|
const logger = useGridLogger(apiRef, 'useGridFilter');
|
|
50
50
|
apiRef.current.registerControlState({
|
|
51
51
|
stateId: 'filter',
|
|
@@ -195,15 +195,17 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
195
195
|
}, [apiRef, logger, props.disableMultipleColumnsFiltering]);
|
|
196
196
|
const getFilterState = React.useCallback(inputFilterModel => {
|
|
197
197
|
const filterModel = sanitizeFilterModel(inputFilterModel, props.disableMultipleColumnsFiltering, apiRef);
|
|
198
|
-
const
|
|
198
|
+
const filterValueGetter = configuration.hooks.useFilterValueGetter(apiRef, props);
|
|
199
|
+
const isRowMatchingFilters = props.filterMode === 'client' ? buildAggregatedFilterApplier(filterModel, filterValueGetter, apiRef, props.disableEval) : null;
|
|
199
200
|
const filterResult = apiRef.current.applyStrategyProcessor('filtering', {
|
|
200
201
|
isRowMatchingFilters,
|
|
201
|
-
filterModel: filterModel ?? getDefaultGridFilterModel()
|
|
202
|
+
filterModel: filterModel ?? getDefaultGridFilterModel(),
|
|
203
|
+
filterValueGetter
|
|
202
204
|
});
|
|
203
205
|
return _extends({}, filterResult, {
|
|
204
206
|
filterModel
|
|
205
207
|
});
|
|
206
|
-
}, [
|
|
208
|
+
}, [apiRef, configuration.hooks, props]);
|
|
207
209
|
const filterApi = {
|
|
208
210
|
setFilterLogicOperator,
|
|
209
211
|
unstable_applyFilters: updateFilteredRows,
|
|
@@ -287,7 +289,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
287
289
|
const row = rows[i];
|
|
288
290
|
const id = getRowId ? getRowId(row) : row.id;
|
|
289
291
|
isRowMatchingFilters(row, undefined, result);
|
|
290
|
-
const isRowPassing = passFilterLogic([result.passingFilterItems], [result.passingQuickFilterValues], params.filterModel, apiRef, filterCache);
|
|
292
|
+
const isRowPassing = passFilterLogic([result.passingFilterItems], [result.passingQuickFilterValues], params.filterModel, params.filterValueGetter, apiRef, filterCache);
|
|
291
293
|
if (!isRowPassing) {
|
|
292
294
|
filteredRowsLookup[id] = isRowPassing;
|
|
293
295
|
}
|
|
@@ -13,12 +13,18 @@ export declare const gridTopLevelRowCountSelector: (args_0: import("react").RefO
|
|
|
13
13
|
export declare const gridRowsLookupSelector: (args_0: import("react").RefObject<{
|
|
14
14
|
state: GridStateCommunity;
|
|
15
15
|
} | null>) => import("@mui/x-data-grid").GridRowIdToModelLookup<import("@mui/x-data-grid").GridValidRowModel>;
|
|
16
|
+
/**
|
|
17
|
+
* @category Rows
|
|
18
|
+
*/
|
|
16
19
|
export declare const gridRowSelector: (args_0: import("react").RefObject<{
|
|
17
20
|
state: GridStateCommunity;
|
|
18
21
|
} | null>, id: GridRowId) => import("@mui/x-data-grid").GridValidRowModel;
|
|
19
22
|
export declare const gridRowTreeSelector: (args_0: import("react").RefObject<{
|
|
20
23
|
state: GridStateCommunity;
|
|
21
24
|
} | null>) => import("@mui/x-data-grid").GridRowTreeConfig;
|
|
25
|
+
/**
|
|
26
|
+
* @category Rows
|
|
27
|
+
*/
|
|
22
28
|
export declare const gridRowNodeSelector: (args_0: import("react").RefObject<{
|
|
23
29
|
state: GridStateCommunity;
|
|
24
30
|
} | null>, rowId: GridRowId) => import("@mui/x-data-grid").GridTreeNode;
|
|
@@ -34,6 +40,9 @@ export declare const gridRowTreeDepthsSelector: (args_0: import("react").RefObje
|
|
|
34
40
|
export declare const gridRowMaximumTreeDepthSelector: (args_0: import("react").RefObject<{
|
|
35
41
|
state: GridStateCommunity;
|
|
36
42
|
} | null>) => number;
|
|
43
|
+
/**
|
|
44
|
+
* @category Rows
|
|
45
|
+
*/
|
|
37
46
|
export declare const gridDataRowIdsSelector: (args_0: import("react").RefObject<{
|
|
38
47
|
state: GridStateCommunity;
|
|
39
48
|
} | null>) => GridRowId[];
|
|
@@ -6,8 +6,16 @@ export const gridTopLevelRowCountSelector = createSelector(gridRowsStateSelector
|
|
|
6
6
|
|
|
7
7
|
// TODO rows v6: Rename
|
|
8
8
|
export const gridRowsLookupSelector = createSelector(gridRowsStateSelector, rows => rows.dataRowIdToModelLookup);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @category Rows
|
|
12
|
+
*/
|
|
9
13
|
export const gridRowSelector = createSelector(gridRowsLookupSelector, (rows, id) => rows[id]);
|
|
10
14
|
export const gridRowTreeSelector = createSelector(gridRowsStateSelector, rows => rows.tree);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @category Rows
|
|
18
|
+
*/
|
|
11
19
|
export const gridRowNodeSelector = createSelector(gridRowTreeSelector, (rowTree, rowId) => rowTree[rowId]);
|
|
12
20
|
export const gridRowGroupsToFetchSelector = createSelector(gridRowsStateSelector, rows => rows.groupsToFetch);
|
|
13
21
|
export const gridRowGroupingNameSelector = createSelector(gridRowsStateSelector, rows => rows.groupingName);
|
|
@@ -19,6 +27,10 @@ export const gridRowMaximumTreeDepthSelector = createSelectorMemoized(gridRowsSt
|
|
|
19
27
|
}
|
|
20
28
|
return (entries.filter(([, nodeCount]) => nodeCount > 0).map(([depth]) => Number(depth)).sort((a, b) => b - a)[0] ?? 0) + 1;
|
|
21
29
|
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @category Rows
|
|
33
|
+
*/
|
|
22
34
|
export const gridDataRowIdsSelector = createSelector(gridRowsStateSelector, rows => rows.dataRowIds);
|
|
23
35
|
export const gridDataRowsSelector = createSelectorMemoized(gridDataRowIdsSelector, gridRowsLookupSelector, (dataRowIds, rowsLookup) => dataRowIds.reduce((acc, id) => {
|
|
24
36
|
if (!rowsLookup[id]) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./gridRowsMetaSelector.js";
|
|
2
2
|
export * from "./gridRowsMetaState.js";
|
|
3
|
-
export { gridRowCountSelector, gridRowsLoadingSelector, gridTopLevelRowCountSelector, gridRowsLookupSelector, gridRowTreeSelector, gridRowGroupingNameSelector, gridRowTreeDepthsSelector, gridRowMaximumTreeDepthSelector, gridDataRowIdsSelector, gridRowNodeSelector } from "./gridRowsSelector.js";
|
|
3
|
+
export { gridRowCountSelector, gridRowsLoadingSelector, gridTopLevelRowCountSelector, gridRowsLookupSelector, gridRowTreeSelector, gridRowGroupingNameSelector, gridRowTreeDepthsSelector, gridRowMaximumTreeDepthSelector, gridDataRowIdsSelector, gridRowNodeSelector, gridRowSelector } from "./gridRowsSelector.js";
|
|
4
4
|
export type { GridRowsState, GridRowIdToModelLookup } from "./gridRowsInterfaces.js";
|
|
5
5
|
export { GRID_ROOT_GROUP_ID, checkGridRowIdIsValid, isAutogeneratedRow } from "./gridRowsUtils.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from "./gridRowsMetaSelector.js";
|
|
2
2
|
export * from "./gridRowsMetaState.js";
|
|
3
|
-
export { gridRowCountSelector, gridRowsLoadingSelector, gridTopLevelRowCountSelector, gridRowsLookupSelector, gridRowTreeSelector, gridRowGroupingNameSelector, gridRowTreeDepthsSelector, gridRowMaximumTreeDepthSelector, gridDataRowIdsSelector, gridRowNodeSelector } from "./gridRowsSelector.js";
|
|
3
|
+
export { gridRowCountSelector, gridRowsLoadingSelector, gridTopLevelRowCountSelector, gridRowsLookupSelector, gridRowTreeSelector, gridRowGroupingNameSelector, gridRowTreeDepthsSelector, gridRowMaximumTreeDepthSelector, gridDataRowIdsSelector, gridRowNodeSelector, gridRowSelector } from "./gridRowsSelector.js";
|
|
4
4
|
export { GRID_ROOT_GROUP_ID, checkGridRowIdIsValid, isAutogeneratedRow } from "./gridRowsUtils.js";
|
|
@@ -37,10 +37,22 @@ export function useGridParamsApi(apiRef, props) {
|
|
|
37
37
|
colDef,
|
|
38
38
|
hasFocus,
|
|
39
39
|
rowNode,
|
|
40
|
-
tabIndex
|
|
40
|
+
tabIndex,
|
|
41
|
+
value: forcedValue,
|
|
42
|
+
formattedValue: forcedFormattedValue
|
|
41
43
|
}) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
let value = row[field];
|
|
45
|
+
if (forcedValue !== undefined) {
|
|
46
|
+
value = forcedValue;
|
|
47
|
+
} else if (colDef?.valueGetter) {
|
|
48
|
+
value = colDef.valueGetter(value, row, colDef, apiRef);
|
|
49
|
+
}
|
|
50
|
+
let formattedValue = value;
|
|
51
|
+
if (forcedFormattedValue !== undefined) {
|
|
52
|
+
formattedValue = forcedFormattedValue;
|
|
53
|
+
} else if (colDef?.valueFormatter) {
|
|
54
|
+
formattedValue = colDef.valueFormatter(value, row, colDef, apiRef);
|
|
55
|
+
}
|
|
44
56
|
const params = {
|
|
45
57
|
id,
|
|
46
58
|
field,
|
|
@@ -51,13 +63,10 @@ export function useGridParamsApi(apiRef, props) {
|
|
|
51
63
|
hasFocus,
|
|
52
64
|
tabIndex,
|
|
53
65
|
value,
|
|
54
|
-
formattedValue
|
|
66
|
+
formattedValue,
|
|
55
67
|
isEditable: false,
|
|
56
68
|
api: apiRef.current
|
|
57
69
|
};
|
|
58
|
-
if (colDef && colDef.valueFormatter) {
|
|
59
|
-
params.formattedValue = colDef.valueFormatter(value, row, colDef, apiRef);
|
|
60
|
-
}
|
|
61
70
|
params.isEditable = colDef && apiRef.current.isCellEditable(params);
|
|
62
71
|
return params;
|
|
63
72
|
}, [apiRef]);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RefObject } from '@mui/x-internals/types';
|
|
2
2
|
import { GridSortingModelApplier } from "./gridSortingState.js";
|
|
3
|
+
import type { GridRowId } from "../../../models/index.js";
|
|
3
4
|
import { GridApiCommunity } from "../../../models/api/gridApiCommunity.js";
|
|
4
5
|
import { GridStateCommunity } from "../../../models/gridStateCommunity.js";
|
|
5
6
|
import { GridComparatorFn, GridSortDirection, GridSortModel } from "../../../models/gridSortModel.js";
|
|
@@ -8,10 +9,11 @@ export declare const mergeStateWithSortModel: (sortModel: GridSortModel, disable
|
|
|
8
9
|
/**
|
|
9
10
|
* Generates a method to easily sort a list of rows according to the current sort model.
|
|
10
11
|
* @param {GridSortModel} sortModel The model with which we want to sort the rows.
|
|
12
|
+
* @param {Function} sortValueGetter A function to get the value to sort by.
|
|
11
13
|
* @param {RefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
12
14
|
* @returns {GridSortingModelApplier | null} A method that generates a list of sorted row ids from a list of rows according to the current sort model. If `null`, we consider that the rows should remain in the order there were provided.
|
|
13
15
|
*/
|
|
14
|
-
export declare const buildAggregatedSortingApplier: (sortModel: GridSortModel, apiRef: RefObject<GridApiCommunity>) => GridSortingModelApplier | null;
|
|
16
|
+
export declare const buildAggregatedSortingApplier: (sortModel: GridSortModel, sortValueGetter: (id: GridRowId, field: string) => any, apiRef: RefObject<GridApiCommunity>) => GridSortingModelApplier | null;
|
|
15
17
|
export declare const getNextGridSortDirection: (sortingOrder: readonly GridSortDirection[], current?: GridSortDirection) => GridSortDirection;
|
|
16
18
|
export declare const gridStringOrNumberComparator: GridComparatorFn;
|
|
17
19
|
export declare const gridNumberComparator: GridComparatorFn;
|
|
@@ -18,12 +18,17 @@ export const mergeStateWithSortModel = (sortModel, disableMultipleColumnsSorting
|
|
|
18
18
|
const isDesc = direction => direction === 'desc';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
+
* @name sortValueGetter
|
|
22
|
+
* @param {GridRowId} id The id of the row.
|
|
23
|
+
* @param {string} field The field to sort by.
|
|
24
|
+
*
|
|
21
25
|
* Transform an item of the sorting model into a method comparing two rows.
|
|
22
26
|
* @param {GridSortItem} sortItem The sort item we want to apply.
|
|
27
|
+
* @param {Function} sortValueGetter A function to get the value to sort by.
|
|
23
28
|
* @param {RefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
24
29
|
* @returns {GridParsedSortItem | null} The parsed sort item. Returns `null` is the sort item is not valid.
|
|
25
30
|
*/
|
|
26
|
-
const parseSortItem = (sortItem, apiRef) => {
|
|
31
|
+
const parseSortItem = (sortItem, sortValueGetter, apiRef) => {
|
|
27
32
|
const column = apiRef.current.getColumn(sortItem.field);
|
|
28
33
|
if (!column || sortItem.sort === null) {
|
|
29
34
|
return null;
|
|
@@ -41,7 +46,7 @@ const parseSortItem = (sortItem, apiRef) => {
|
|
|
41
46
|
id,
|
|
42
47
|
field: column.field,
|
|
43
48
|
rowNode: gridRowNodeSelector(apiRef, id),
|
|
44
|
-
value:
|
|
49
|
+
value: sortValueGetter(id, column.field),
|
|
45
50
|
api: apiRef.current
|
|
46
51
|
});
|
|
47
52
|
return {
|
|
@@ -73,11 +78,12 @@ const compareRows = (parsedSortItems, row1, row2) => {
|
|
|
73
78
|
/**
|
|
74
79
|
* Generates a method to easily sort a list of rows according to the current sort model.
|
|
75
80
|
* @param {GridSortModel} sortModel The model with which we want to sort the rows.
|
|
81
|
+
* @param {Function} sortValueGetter A function to get the value to sort by.
|
|
76
82
|
* @param {RefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
77
83
|
* @returns {GridSortingModelApplier | null} A method that generates a list of sorted row ids from a list of rows according to the current sort model. If `null`, we consider that the rows should remain in the order there were provided.
|
|
78
84
|
*/
|
|
79
|
-
export const buildAggregatedSortingApplier = (sortModel, apiRef) => {
|
|
80
|
-
const comparatorList = sortModel.map(item => parseSortItem(item, apiRef)).filter(comparator => !!comparator);
|
|
85
|
+
export const buildAggregatedSortingApplier = (sortModel, sortValueGetter, apiRef) => {
|
|
86
|
+
const comparatorList = sortModel.map(item => parseSortItem(item, sortValueGetter, apiRef)).filter(comparator => !!comparator);
|
|
81
87
|
if (comparatorList.length === 0) {
|
|
82
88
|
return null;
|
|
83
89
|
}
|
|
@@ -2,9 +2,10 @@ import { RefObject } from '@mui/x-internals/types';
|
|
|
2
2
|
import { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
|
|
3
3
|
import { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
|
|
4
4
|
import { GridStateInitializer } from "../../utils/useGridInitializeState.js";
|
|
5
|
+
import type { GridConfiguration } from "../../../models/configuration/gridConfiguration.js";
|
|
5
6
|
export declare const sortingStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'sortModel' | 'initialState' | 'disableMultipleColumnsSorting'>>;
|
|
6
7
|
/**
|
|
7
8
|
* @requires useGridRows (event)
|
|
8
9
|
* @requires useGridColumns (event)
|
|
9
10
|
*/
|
|
10
|
-
export declare const useGridSorting: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "initialState" | "sortModel" | "onSortModelChange" | "sortingOrder" | "sortingMode" | "disableColumnSorting" | "disableMultipleColumnsSorting" | "multipleColumnsSortingMode"
|
|
11
|
+
export declare const useGridSorting: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "initialState" | "sortModel" | "onSortModelChange" | "sortingOrder" | "sortingMode" | "disableColumnSorting" | "disableMultipleColumnsSorting" | "multipleColumnsSortingMode">, configuration: GridConfiguration) => void;
|
|
@@ -26,7 +26,7 @@ export const sortingStateInitializer = (state, props) => {
|
|
|
26
26
|
* @requires useGridRows (event)
|
|
27
27
|
* @requires useGridColumns (event)
|
|
28
28
|
*/
|
|
29
|
-
export const useGridSorting = (apiRef, props) => {
|
|
29
|
+
export const useGridSorting = (apiRef, props, configuration) => {
|
|
30
30
|
const logger = useGridLogger(apiRef, 'useGridSorting');
|
|
31
31
|
apiRef.current.registerControlState({
|
|
32
32
|
stateId: 'sortModel',
|
|
@@ -79,6 +79,7 @@ export const useGridSorting = (apiRef, props) => {
|
|
|
79
79
|
* API METHODS
|
|
80
80
|
*/
|
|
81
81
|
const applySorting = React.useCallback(() => {
|
|
82
|
+
const sortValueGetter = configuration.hooks.useSortValueGetter(apiRef);
|
|
82
83
|
apiRef.current.setState(state => {
|
|
83
84
|
if (props.sortingMode === 'server') {
|
|
84
85
|
logger.debug('Skipping sorting rows as sortingMode = server');
|
|
@@ -89,7 +90,7 @@ export const useGridSorting = (apiRef, props) => {
|
|
|
89
90
|
});
|
|
90
91
|
}
|
|
91
92
|
const sortModel = gridSortModelSelector(apiRef);
|
|
92
|
-
const sortRowList = buildAggregatedSortingApplier(sortModel, apiRef);
|
|
93
|
+
const sortRowList = buildAggregatedSortingApplier(sortModel, sortValueGetter, apiRef);
|
|
93
94
|
const sortedRows = apiRef.current.applyStrategyProcessor('sorting', {
|
|
94
95
|
sortRowList
|
|
95
96
|
});
|
|
@@ -100,7 +101,7 @@ export const useGridSorting = (apiRef, props) => {
|
|
|
100
101
|
});
|
|
101
102
|
});
|
|
102
103
|
apiRef.current.publishEvent('sortedRowsSet');
|
|
103
|
-
}, [apiRef, logger, props.sortingMode]);
|
|
104
|
+
}, [apiRef, logger, configuration, props.sortingMode]);
|
|
104
105
|
const setSortModel = React.useCallback(model => {
|
|
105
106
|
const currentModel = gridSortModelSelector(apiRef);
|
|
106
107
|
if (currentModel !== model) {
|