@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
|
@@ -48,7 +48,7 @@ function computeNewWidth(initialOffsetToSeparator, clickX, columnBounds, resizeD
|
|
|
48
48
|
} else {
|
|
49
49
|
newWidth += columnBounds.right - clickX;
|
|
50
50
|
}
|
|
51
|
-
return newWidth;
|
|
51
|
+
return Math.round(newWidth);
|
|
52
52
|
}
|
|
53
53
|
function computeOffsetToSeparator(clickX, columnBounds, resizeDirection) {
|
|
54
54
|
if (resizeDirection === 'Left') {
|
|
@@ -569,5 +569,5 @@ function updateProperty(element, property, delta) {
|
|
|
569
569
|
if (!element) {
|
|
570
570
|
return;
|
|
571
571
|
}
|
|
572
|
-
element.style[property] = `${
|
|
572
|
+
element.style[property] = `${Math.round(parseFloat(element.style[property])) + delta}px`;
|
|
573
573
|
}
|
|
@@ -19,7 +19,7 @@ var _pipeProcessing = require("../../core/pipeProcessing");
|
|
|
19
19
|
var _gridColumnsInterfaces = require("./gridColumnsInterfaces");
|
|
20
20
|
var _gridColumnsUtils = require("./gridColumnsUtils");
|
|
21
21
|
var _preferencesPanel = require("../preferencesPanel");
|
|
22
|
-
var
|
|
22
|
+
var _gridPivotingSelectors = require("../pivoting/gridPivotingSelectors");
|
|
23
23
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
24
24
|
const columnsStateInitializer = (state, props, apiRef) => {
|
|
25
25
|
apiRef.current.caches.columns = {
|
|
@@ -91,13 +91,30 @@ function useGridColumns(apiRef, props) {
|
|
|
91
91
|
}
|
|
92
92
|
}, [apiRef]);
|
|
93
93
|
const updateColumns = React.useCallback(columns => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
let columnsToUpdate = columns;
|
|
95
|
+
if ((0, _gridPivotingSelectors.gridPivotActiveSelector)(apiRef)) {
|
|
96
|
+
const nonPivotColumns = [];
|
|
97
|
+
const pivotColumns = [];
|
|
98
|
+
const pivotInitialColumns = (0, _gridPivotingSelectors.gridPivotInitialColumnsSelector)(apiRef);
|
|
99
|
+
columns.forEach(column => {
|
|
100
|
+
const isNonPivotColumn = pivotInitialColumns.has(column.field);
|
|
101
|
+
if (isNonPivotColumn) {
|
|
102
|
+
nonPivotColumns.push(column);
|
|
103
|
+
} else {
|
|
104
|
+
pivotColumns.push(column);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
if (nonPivotColumns.length > 0) {
|
|
108
|
+
apiRef.current.updateNonPivotColumns(nonPivotColumns);
|
|
109
|
+
}
|
|
110
|
+
if (pivotColumns.length === 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
columnsToUpdate = pivotColumns;
|
|
97
114
|
}
|
|
98
115
|
const columnsState = (0, _gridColumnsUtils.createColumnsState)({
|
|
99
116
|
apiRef,
|
|
100
|
-
columnsToUpsert:
|
|
117
|
+
columnsToUpsert: columnsToUpdate,
|
|
101
118
|
initialState: undefined,
|
|
102
119
|
keepOnlyColumnsToUpsert: false,
|
|
103
120
|
updateInitialVisibilityModel: true
|
|
@@ -262,7 +279,7 @@ function useGridColumns(apiRef, props) {
|
|
|
262
279
|
return initialValue;
|
|
263
280
|
}, [props.slots.columnsPanel, props.slotProps?.columnsPanel]);
|
|
264
281
|
const addColumnMenuItems = React.useCallback(columnMenuItems => {
|
|
265
|
-
const isPivotActive = (0,
|
|
282
|
+
const isPivotActive = (0, _gridPivotingSelectors.gridPivotActiveSelector)(apiRef);
|
|
266
283
|
if (props.disableColumnSelector || isPivotActive) {
|
|
267
284
|
return columnMenuItems;
|
|
268
285
|
}
|
|
@@ -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
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.gridVisibleRowsLookupSelector = exports.gridQuickFilterValuesSelector = exports.gridFilteredTopLevelRowCountSelector = exports.gridFilteredSortedTopLevelRowEntriesSelector = exports.gridFilteredSortedRowIdsSelector = exports.gridFilteredSortedRowEntriesSelector = exports.gridFilteredRowsLookupSelector = exports.gridFilteredRowCountSelector = exports.gridFilteredDescendantRowCountSelector = exports.gridFilteredDescendantCountLookupSelector = exports.gridFilteredChildrenCountLookupSelector = exports.gridFilterModelSelector = exports.gridFilterActiveItemsSelector = exports.gridFilterActiveItemsLookupSelector = exports.gridExpandedSortedRowTreeLevelPositionLookupSelector = exports.gridExpandedSortedRowIndexLookupSelector = exports.gridExpandedSortedRowIdsSelector = exports.gridExpandedSortedRowEntriesSelector = exports.gridExpandedRowCountSelector = void 0;
|
|
6
|
+
exports.gridVisibleRowsLookupSelector = exports.gridQuickFilterValuesSelector = exports.gridFilteredTopLevelRowCountSelector = exports.gridFilteredSortedTopLevelRowEntriesSelector = exports.gridFilteredSortedRowIdsSelector = exports.gridFilteredSortedRowEntriesSelector = exports.gridFilteredSortedDepthRowEntriesSelector = exports.gridFilteredRowsLookupSelector = exports.gridFilteredRowCountSelector = exports.gridFilteredDescendantRowCountSelector = exports.gridFilteredDescendantCountLookupSelector = exports.gridFilteredChildrenCountLookupSelector = exports.gridFilterModelSelector = exports.gridFilterActiveItemsSelector = exports.gridFilterActiveItemsLookupSelector = exports.gridExpandedSortedRowTreeLevelPositionLookupSelector = exports.gridExpandedSortedRowIndexLookupSelector = exports.gridExpandedSortedRowIdsSelector = exports.gridExpandedSortedRowEntriesSelector = exports.gridExpandedRowCountSelector = void 0;
|
|
7
7
|
var _isObjectEmpty = require("@mui/x-internals/isObjectEmpty");
|
|
8
8
|
var _createSelector = require("../../../utils/createSelector");
|
|
9
9
|
var _gridSortingSelector = require("../sorting/gridSortingSelector");
|
|
@@ -112,16 +112,33 @@ const gridExpandedSortedRowTreeLevelPositionLookupSelector = exports.gridExpande
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
|
-
* Get the id and the model of the
|
|
115
|
+
* Get the id and the model of the rows per depth level, accessible after the filtering process.
|
|
116
|
+
* Returns an array of arrays, where each array index contains the rows for the depth level equal to the index.
|
|
116
117
|
* @category Filtering
|
|
117
118
|
*/
|
|
118
|
-
const
|
|
119
|
+
const gridFilteredSortedDepthRowEntriesSelector = exports.gridFilteredSortedDepthRowEntriesSelector = (0, _createSelector.createSelectorMemoized)(gridFilteredSortedRowEntriesSelector, _gridRowsSelector.gridRowTreeSelector, _gridRowsSelector.gridRowMaximumTreeDepthSelector, (sortedRows, rowTree, rowTreeDepth) => {
|
|
119
120
|
if (rowTreeDepth < 2) {
|
|
120
|
-
return
|
|
121
|
+
return [sortedRows];
|
|
121
122
|
}
|
|
122
|
-
return
|
|
123
|
+
return sortedRows.reduce((acc, row) => {
|
|
124
|
+
const depth = rowTree[row.id]?.depth;
|
|
125
|
+
if (depth === undefined) {
|
|
126
|
+
return acc;
|
|
127
|
+
}
|
|
128
|
+
if (!acc[depth]) {
|
|
129
|
+
acc[depth] = [];
|
|
130
|
+
}
|
|
131
|
+
acc[depth].push(row);
|
|
132
|
+
return acc;
|
|
133
|
+
}, [[]]);
|
|
123
134
|
});
|
|
124
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Get the id and the model of the top level rows accessible after the filtering process.
|
|
138
|
+
* @category Filtering
|
|
139
|
+
*/
|
|
140
|
+
const gridFilteredSortedTopLevelRowEntriesSelector = exports.gridFilteredSortedTopLevelRowEntriesSelector = (0, _createSelector.createSelector)(gridFilteredSortedDepthRowEntriesSelector, filteredSortedDepthRows => filteredSortedDepthRows[0] ?? []);
|
|
141
|
+
|
|
125
142
|
/**
|
|
126
143
|
* Get the amount of rows accessible after the filtering process.
|
|
127
144
|
* @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 {};
|
|
@@ -92,7 +92,7 @@ const removeDiacritics = value => {
|
|
|
92
92
|
return value;
|
|
93
93
|
};
|
|
94
94
|
exports.removeDiacritics = removeDiacritics;
|
|
95
|
-
const getFilterCallbackFromItem = (filterItem, apiRef) => {
|
|
95
|
+
const getFilterCallbackFromItem = (filterItem, filterValueGetter, apiRef) => {
|
|
96
96
|
if (!filterItem.field || !filterItem.operator) {
|
|
97
97
|
return null;
|
|
98
98
|
}
|
|
@@ -132,7 +132,7 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
|
|
|
132
132
|
return {
|
|
133
133
|
item: newFilterItem,
|
|
134
134
|
fn: row => {
|
|
135
|
-
let value =
|
|
135
|
+
let value = filterValueGetter(row, column);
|
|
136
136
|
if (ignoreDiacritics) {
|
|
137
137
|
value = removeDiacritics(value);
|
|
138
138
|
}
|
|
@@ -143,16 +143,21 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
|
|
|
143
143
|
let filterItemsApplierId = 1;
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
|
+
* @name filterValueGetter
|
|
147
|
+
* @param {GridRowModel} row The row to get the value from.
|
|
148
|
+
* @param {GridColDef} column The column that the filter is applied on.
|
|
149
|
+
*
|
|
146
150
|
* Generates a method to easily check if a row is matching the current filter model.
|
|
147
151
|
* @param {GridFilterModel} filterModel The model with which we want to filter the rows.
|
|
152
|
+
* @param {FilterValueGetterFn} filterValueGetter The function to get the value to filter by.
|
|
148
153
|
* @param {RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
|
|
149
154
|
* @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.
|
|
150
155
|
*/
|
|
151
|
-
const buildAggregatedFilterItemsApplier = (filterModel, apiRef, disableEval) => {
|
|
156
|
+
const buildAggregatedFilterItemsApplier = (filterModel, filterValueGetter, apiRef, disableEval) => {
|
|
152
157
|
const {
|
|
153
158
|
items
|
|
154
159
|
} = filterModel;
|
|
155
|
-
const appliers = items.map(item => getFilterCallbackFromItem(item, apiRef)).filter(callback => !!callback);
|
|
160
|
+
const appliers = items.map(item => getFilterCallbackFromItem(item, filterValueGetter, apiRef)).filter(callback => !!callback);
|
|
156
161
|
if (appliers.length === 0) {
|
|
157
162
|
return null;
|
|
158
163
|
}
|
|
@@ -192,13 +197,18 @@ const shouldQuickFilterExcludeHiddenColumns = filterModel => {
|
|
|
192
197
|
};
|
|
193
198
|
|
|
194
199
|
/**
|
|
200
|
+
* @name filterValueGetter
|
|
201
|
+
* @param {GridRowModel} row The row to get the value from.
|
|
202
|
+
* @param {GridColDef} column The column that the filter is applied on.
|
|
203
|
+
*
|
|
195
204
|
* Generates a method to easily check if a row is matching the current quick filter.
|
|
196
205
|
* @param {any[]} filterModel The model with which we want to filter the rows.
|
|
206
|
+
* @param {FilterValueGetterFn} filterValueGetter The function to get the value to filter by.
|
|
197
207
|
* @param {RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
|
|
198
208
|
* @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.
|
|
199
209
|
*/
|
|
200
210
|
exports.shouldQuickFilterExcludeHiddenColumns = shouldQuickFilterExcludeHiddenColumns;
|
|
201
|
-
const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
211
|
+
const buildAggregatedQuickFilterApplier = (filterModel, filterValueGetter, apiRef) => {
|
|
202
212
|
const quickFilterValues = filterModel.quickFilterValues?.filter(Boolean) ?? [];
|
|
203
213
|
if (quickFilterValues.length === 0) {
|
|
204
214
|
return null;
|
|
@@ -251,7 +261,7 @@ const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
|
251
261
|
continue;
|
|
252
262
|
}
|
|
253
263
|
const applier = appliers[v];
|
|
254
|
-
let value =
|
|
264
|
+
let value = filterValueGetter(row, column);
|
|
255
265
|
if (applier.fn === null) {
|
|
256
266
|
continue;
|
|
257
267
|
}
|
|
@@ -269,9 +279,9 @@ const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
|
269
279
|
return result;
|
|
270
280
|
};
|
|
271
281
|
};
|
|
272
|
-
const buildAggregatedFilterApplier = (filterModel, apiRef, disableEval) => {
|
|
273
|
-
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(filterModel, apiRef, disableEval);
|
|
274
|
-
const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(filterModel, apiRef);
|
|
282
|
+
const buildAggregatedFilterApplier = (filterModel, filterValueGetter, apiRef, disableEval) => {
|
|
283
|
+
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(filterModel, filterValueGetter, apiRef, disableEval);
|
|
284
|
+
const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(filterModel, filterValueGetter, apiRef);
|
|
275
285
|
return function isRowMatchingFilters(row, shouldApplyFilter, result) {
|
|
276
286
|
result.passingFilterItems = isRowMatchingFilterItems?.(row, shouldApplyFilter) ?? null;
|
|
277
287
|
result.passingQuickFilterValues = isRowMatchingQuickFilter?.(row, shouldApplyFilter) ?? null;
|
|
@@ -279,14 +289,14 @@ const buildAggregatedFilterApplier = (filterModel, apiRef, disableEval) => {
|
|
|
279
289
|
};
|
|
280
290
|
exports.buildAggregatedFilterApplier = buildAggregatedFilterApplier;
|
|
281
291
|
const isNotNull = result => result != null;
|
|
282
|
-
const filterModelItems = (cache, apiRef, items) => {
|
|
292
|
+
const filterModelItems = (cache, filterValueGetter, apiRef, items) => {
|
|
283
293
|
if (!cache.cleanedFilterItems) {
|
|
284
|
-
cache.cleanedFilterItems = items.filter(item => getFilterCallbackFromItem(item, apiRef) !== null);
|
|
294
|
+
cache.cleanedFilterItems = items.filter(item => getFilterCallbackFromItem(item, filterValueGetter, apiRef) !== null);
|
|
285
295
|
}
|
|
286
296
|
return cache.cleanedFilterItems;
|
|
287
297
|
};
|
|
288
|
-
const passFilterLogic = (allFilterItemResults, allQuickFilterResults, filterModel, apiRef, cache) => {
|
|
289
|
-
const cleanedFilterItems = filterModelItems(cache, apiRef, filterModel.items);
|
|
298
|
+
const passFilterLogic = (allFilterItemResults, allQuickFilterResults, filterModel, filterValueGetter, apiRef, cache) => {
|
|
299
|
+
const cleanedFilterItems = filterModelItems(cache, filterValueGetter, apiRef, filterModel.items);
|
|
290
300
|
const cleanedFilterItemResults = allFilterItemResults.filter(isNotNull);
|
|
291
301
|
const cleanedQuickFilterResults = allQuickFilterResults.filter(isNotNull);
|
|
292
302
|
|
|
@@ -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;
|
|
@@ -54,7 +54,7 @@ function createMemoizedValues() {
|
|
|
54
54
|
* @requires useGridParamsApi (method)
|
|
55
55
|
* @requires useGridRows (event)
|
|
56
56
|
*/
|
|
57
|
-
const useGridFilter = (apiRef, props) => {
|
|
57
|
+
const useGridFilter = (apiRef, props, configuration) => {
|
|
58
58
|
const logger = (0, _useGridLogger.useGridLogger)(apiRef, 'useGridFilter');
|
|
59
59
|
apiRef.current.registerControlState({
|
|
60
60
|
stateId: 'filter',
|
|
@@ -204,15 +204,17 @@ const useGridFilter = (apiRef, props) => {
|
|
|
204
204
|
}, [apiRef, logger, props.disableMultipleColumnsFiltering]);
|
|
205
205
|
const getFilterState = React.useCallback(inputFilterModel => {
|
|
206
206
|
const filterModel = (0, _gridFilterUtils.sanitizeFilterModel)(inputFilterModel, props.disableMultipleColumnsFiltering, apiRef);
|
|
207
|
-
const
|
|
207
|
+
const filterValueGetter = configuration.hooks.useFilterValueGetter(apiRef, props);
|
|
208
|
+
const isRowMatchingFilters = props.filterMode === 'client' ? (0, _gridFilterUtils.buildAggregatedFilterApplier)(filterModel, filterValueGetter, apiRef, props.disableEval) : null;
|
|
208
209
|
const filterResult = apiRef.current.applyStrategyProcessor('filtering', {
|
|
209
210
|
isRowMatchingFilters,
|
|
210
|
-
filterModel: filterModel ?? (0, _gridFilterState.getDefaultGridFilterModel)()
|
|
211
|
+
filterModel: filterModel ?? (0, _gridFilterState.getDefaultGridFilterModel)(),
|
|
212
|
+
filterValueGetter
|
|
211
213
|
});
|
|
212
214
|
return (0, _extends2.default)({}, filterResult, {
|
|
213
215
|
filterModel
|
|
214
216
|
});
|
|
215
|
-
}, [
|
|
217
|
+
}, [apiRef, configuration.hooks, props]);
|
|
216
218
|
const filterApi = {
|
|
217
219
|
setFilterLogicOperator,
|
|
218
220
|
unstable_applyFilters: updateFilteredRows,
|
|
@@ -296,7 +298,7 @@ const useGridFilter = (apiRef, props) => {
|
|
|
296
298
|
const row = rows[i];
|
|
297
299
|
const id = getRowId ? getRowId(row) : row.id;
|
|
298
300
|
isRowMatchingFilters(row, undefined, result);
|
|
299
|
-
const isRowPassing = (0, _gridFilterUtils.passFilterLogic)([result.passingFilterItems], [result.passingQuickFilterValues], params.filterModel, apiRef, filterCache);
|
|
301
|
+
const isRowPassing = (0, _gridFilterUtils.passFilterLogic)([result.passingFilterItems], [result.passingQuickFilterValues], params.filterModel, params.filterValueGetter, apiRef, filterCache);
|
|
300
302
|
if (!isRowPassing) {
|
|
301
303
|
filteredRowsLookup[id] = isRowPassing;
|
|
302
304
|
}
|
|
@@ -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[];
|
|
@@ -12,8 +12,16 @@ const gridTopLevelRowCountSelector = exports.gridTopLevelRowCountSelector = (0,
|
|
|
12
12
|
|
|
13
13
|
// TODO rows v6: Rename
|
|
14
14
|
const gridRowsLookupSelector = exports.gridRowsLookupSelector = (0, _createSelector.createSelector)(gridRowsStateSelector, rows => rows.dataRowIdToModelLookup);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @category Rows
|
|
18
|
+
*/
|
|
15
19
|
const gridRowSelector = exports.gridRowSelector = (0, _createSelector.createSelector)(gridRowsLookupSelector, (rows, id) => rows[id]);
|
|
16
20
|
const gridRowTreeSelector = exports.gridRowTreeSelector = (0, _createSelector.createSelector)(gridRowsStateSelector, rows => rows.tree);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @category Rows
|
|
24
|
+
*/
|
|
17
25
|
const gridRowNodeSelector = exports.gridRowNodeSelector = (0, _createSelector.createSelector)(gridRowTreeSelector, (rowTree, rowId) => rowTree[rowId]);
|
|
18
26
|
const gridRowGroupsToFetchSelector = exports.gridRowGroupsToFetchSelector = (0, _createSelector.createSelector)(gridRowsStateSelector, rows => rows.groupsToFetch);
|
|
19
27
|
const gridRowGroupingNameSelector = exports.gridRowGroupingNameSelector = (0, _createSelector.createSelector)(gridRowsStateSelector, rows => rows.groupingName);
|
|
@@ -25,6 +33,10 @@ const gridRowMaximumTreeDepthSelector = exports.gridRowMaximumTreeDepthSelector
|
|
|
25
33
|
}
|
|
26
34
|
return (entries.filter(([, nodeCount]) => nodeCount > 0).map(([depth]) => Number(depth)).sort((a, b) => b - a)[0] ?? 0) + 1;
|
|
27
35
|
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @category Rows
|
|
39
|
+
*/
|
|
28
40
|
const gridDataRowIdsSelector = exports.gridDataRowIdsSelector = (0, _createSelector.createSelector)(gridRowsStateSelector, rows => rows.dataRowIds);
|
|
29
41
|
const gridDataRowsSelector = exports.gridDataRowsSelector = (0, _createSelector.createSelectorMemoized)(gridDataRowIdsSelector, gridRowsLookupSelector, (dataRowIds, rowsLookup) => dataRowIds.reduce((acc, id) => {
|
|
30
42
|
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";
|
|
@@ -14,6 +14,7 @@ var _exportNames = {
|
|
|
14
14
|
gridRowMaximumTreeDepthSelector: true,
|
|
15
15
|
gridDataRowIdsSelector: true,
|
|
16
16
|
gridRowNodeSelector: true,
|
|
17
|
+
gridRowSelector: true,
|
|
17
18
|
GRID_ROOT_GROUP_ID: true,
|
|
18
19
|
checkGridRowIdIsValid: true,
|
|
19
20
|
isAutogeneratedRow: true
|
|
@@ -60,6 +61,12 @@ Object.defineProperty(exports, "gridRowNodeSelector", {
|
|
|
60
61
|
return _gridRowsSelector.gridRowNodeSelector;
|
|
61
62
|
}
|
|
62
63
|
});
|
|
64
|
+
Object.defineProperty(exports, "gridRowSelector", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return _gridRowsSelector.gridRowSelector;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
63
70
|
Object.defineProperty(exports, "gridRowTreeDepthsSelector", {
|
|
64
71
|
enumerable: true,
|
|
65
72
|
get: function () {
|
|
@@ -46,10 +46,22 @@ function useGridParamsApi(apiRef, props) {
|
|
|
46
46
|
colDef,
|
|
47
47
|
hasFocus,
|
|
48
48
|
rowNode,
|
|
49
|
-
tabIndex
|
|
49
|
+
tabIndex,
|
|
50
|
+
value: forcedValue,
|
|
51
|
+
formattedValue: forcedFormattedValue
|
|
50
52
|
}) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
let value = row[field];
|
|
54
|
+
if (forcedValue !== undefined) {
|
|
55
|
+
value = forcedValue;
|
|
56
|
+
} else if (colDef?.valueGetter) {
|
|
57
|
+
value = colDef.valueGetter(value, row, colDef, apiRef);
|
|
58
|
+
}
|
|
59
|
+
let formattedValue = value;
|
|
60
|
+
if (forcedFormattedValue !== undefined) {
|
|
61
|
+
formattedValue = forcedFormattedValue;
|
|
62
|
+
} else if (colDef?.valueFormatter) {
|
|
63
|
+
formattedValue = colDef.valueFormatter(value, row, colDef, apiRef);
|
|
64
|
+
}
|
|
53
65
|
const params = {
|
|
54
66
|
id,
|
|
55
67
|
field,
|
|
@@ -60,13 +72,10 @@ function useGridParamsApi(apiRef, props) {
|
|
|
60
72
|
hasFocus,
|
|
61
73
|
tabIndex,
|
|
62
74
|
value,
|
|
63
|
-
formattedValue
|
|
75
|
+
formattedValue,
|
|
64
76
|
isEditable: false,
|
|
65
77
|
api: apiRef.current
|
|
66
78
|
};
|
|
67
|
-
if (colDef && colDef.valueFormatter) {
|
|
68
|
-
params.formattedValue = colDef.valueFormatter(value, row, colDef, apiRef);
|
|
69
|
-
}
|
|
70
79
|
params.isEditable = colDef && apiRef.current.isCellEditable(params);
|
|
71
80
|
return params;
|
|
72
81
|
}, [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;
|
|
@@ -27,12 +27,17 @@ exports.mergeStateWithSortModel = mergeStateWithSortModel;
|
|
|
27
27
|
const isDesc = direction => direction === 'desc';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
+
* @name sortValueGetter
|
|
31
|
+
* @param {GridRowId} id The id of the row.
|
|
32
|
+
* @param {string} field The field to sort by.
|
|
33
|
+
*
|
|
30
34
|
* Transform an item of the sorting model into a method comparing two rows.
|
|
31
35
|
* @param {GridSortItem} sortItem The sort item we want to apply.
|
|
36
|
+
* @param {Function} sortValueGetter A function to get the value to sort by.
|
|
32
37
|
* @param {RefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
33
38
|
* @returns {GridParsedSortItem | null} The parsed sort item. Returns `null` is the sort item is not valid.
|
|
34
39
|
*/
|
|
35
|
-
const parseSortItem = (sortItem, apiRef) => {
|
|
40
|
+
const parseSortItem = (sortItem, sortValueGetter, apiRef) => {
|
|
36
41
|
const column = apiRef.current.getColumn(sortItem.field);
|
|
37
42
|
if (!column || sortItem.sort === null) {
|
|
38
43
|
return null;
|
|
@@ -50,7 +55,7 @@ const parseSortItem = (sortItem, apiRef) => {
|
|
|
50
55
|
id,
|
|
51
56
|
field: column.field,
|
|
52
57
|
rowNode: (0, _gridRowsSelector.gridRowNodeSelector)(apiRef, id),
|
|
53
|
-
value:
|
|
58
|
+
value: sortValueGetter(id, column.field),
|
|
54
59
|
api: apiRef.current
|
|
55
60
|
});
|
|
56
61
|
return {
|
|
@@ -82,11 +87,12 @@ const compareRows = (parsedSortItems, row1, row2) => {
|
|
|
82
87
|
/**
|
|
83
88
|
* Generates a method to easily sort a list of rows according to the current sort model.
|
|
84
89
|
* @param {GridSortModel} sortModel The model with which we want to sort the rows.
|
|
90
|
+
* @param {Function} sortValueGetter A function to get the value to sort by.
|
|
85
91
|
* @param {RefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
86
92
|
* @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.
|
|
87
93
|
*/
|
|
88
|
-
const buildAggregatedSortingApplier = (sortModel, apiRef) => {
|
|
89
|
-
const comparatorList = sortModel.map(item => parseSortItem(item, apiRef)).filter(comparator => !!comparator);
|
|
94
|
+
const buildAggregatedSortingApplier = (sortModel, sortValueGetter, apiRef) => {
|
|
95
|
+
const comparatorList = sortModel.map(item => parseSortItem(item, sortValueGetter, apiRef)).filter(comparator => !!comparator);
|
|
90
96
|
if (comparatorList.length === 0) {
|
|
91
97
|
return null;
|
|
92
98
|
}
|
|
@@ -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;
|
|
@@ -35,7 +35,7 @@ const sortingStateInitializer = (state, props) => {
|
|
|
35
35
|
* @requires useGridColumns (event)
|
|
36
36
|
*/
|
|
37
37
|
exports.sortingStateInitializer = sortingStateInitializer;
|
|
38
|
-
const useGridSorting = (apiRef, props) => {
|
|
38
|
+
const useGridSorting = (apiRef, props, configuration) => {
|
|
39
39
|
const logger = (0, _useGridLogger.useGridLogger)(apiRef, 'useGridSorting');
|
|
40
40
|
apiRef.current.registerControlState({
|
|
41
41
|
stateId: 'sortModel',
|
|
@@ -88,6 +88,7 @@ const useGridSorting = (apiRef, props) => {
|
|
|
88
88
|
* API METHODS
|
|
89
89
|
*/
|
|
90
90
|
const applySorting = React.useCallback(() => {
|
|
91
|
+
const sortValueGetter = configuration.hooks.useSortValueGetter(apiRef);
|
|
91
92
|
apiRef.current.setState(state => {
|
|
92
93
|
if (props.sortingMode === 'server') {
|
|
93
94
|
logger.debug('Skipping sorting rows as sortingMode = server');
|
|
@@ -98,7 +99,7 @@ const useGridSorting = (apiRef, props) => {
|
|
|
98
99
|
});
|
|
99
100
|
}
|
|
100
101
|
const sortModel = (0, _gridSortingSelector.gridSortModelSelector)(apiRef);
|
|
101
|
-
const sortRowList = (0, _gridSortingUtils.buildAggregatedSortingApplier)(sortModel, apiRef);
|
|
102
|
+
const sortRowList = (0, _gridSortingUtils.buildAggregatedSortingApplier)(sortModel, sortValueGetter, apiRef);
|
|
102
103
|
const sortedRows = apiRef.current.applyStrategyProcessor('sorting', {
|
|
103
104
|
sortRowList
|
|
104
105
|
});
|
|
@@ -109,7 +110,7 @@ const useGridSorting = (apiRef, props) => {
|
|
|
109
110
|
});
|
|
110
111
|
});
|
|
111
112
|
apiRef.current.publishEvent('sortedRowsSet');
|
|
112
|
-
}, [apiRef, logger, props.sortingMode]);
|
|
113
|
+
}, [apiRef, logger, configuration, props.sortingMode]);
|
|
113
114
|
const setSortModel = React.useCallback(model => {
|
|
114
115
|
const currentModel = (0, _gridSortingSelector.gridSortModelSelector)(apiRef);
|
|
115
116
|
if (currentModel !== model) {
|
package/index.js
CHANGED
package/internals/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export { useGridPrintExport } from "../hooks/features/export/useGridPrintExport.
|
|
|
41
41
|
export { useGridFilter, filterStateInitializer } from "../hooks/features/filter/useGridFilter.js";
|
|
42
42
|
export { defaultGridFilterLookup } from "../hooks/features/filter/gridFilterState.js";
|
|
43
43
|
export { passFilterLogic } from "../hooks/features/filter/gridFilterUtils.js";
|
|
44
|
-
export { gridFilteredChildrenCountLookupSelector, gridExpandedSortedRowTreeLevelPositionLookupSelector, gridExpandedSortedRowIndexLookupSelector } from "../hooks/features/filter/gridFilterSelector.js";
|
|
44
|
+
export { gridFilteredChildrenCountLookupSelector, gridExpandedSortedRowTreeLevelPositionLookupSelector, gridExpandedSortedRowIndexLookupSelector, gridFilteredSortedDepthRowEntriesSelector } from "../hooks/features/filter/gridFilterSelector.js";
|
|
45
45
|
export { isSingleSelectColDef } from "../components/panel/filterPanel/filterPanelUtils.js";
|
|
46
46
|
export type { GridAggregatedFilterItemApplier, GridAggregatedFilterItemApplierResult } from "../hooks/features/filter/gridFilterState.js";
|
|
47
47
|
export { useGridFocus, focusStateInitializer } from "../hooks/features/focus/useGridFocus.js";
|