@mui/x-data-grid 7.0.0-beta.7 → 7.1.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 +266 -12
- package/DataGrid/DataGrid.js +18 -17
- package/DataGrid/useDataGridProps.js +4 -5
- package/README.md +1 -1
- package/components/GridFooter.js +2 -3
- package/components/GridHeader.js +1 -2
- package/components/GridPagination.d.ts +6 -5
- package/components/GridPagination.js +12 -4
- package/components/GridRow.js +13 -17
- package/components/base/GridFooterPlaceholder.js +1 -2
- package/components/base/GridOverlays.js +3 -6
- package/components/cell/GridActionsCell.js +4 -6
- package/components/cell/GridActionsCellItem.d.ts +8 -25
- package/components/cell/GridActionsCellItem.js +8 -5
- package/components/cell/GridBooleanCell.d.ts +1 -0
- package/components/cell/GridBooleanCell.js +3 -2
- package/components/cell/GridCell.js +7 -8
- package/components/cell/GridEditBooleanCell.js +1 -2
- package/components/cell/GridEditDateCell.js +2 -3
- package/components/cell/GridEditInputCell.js +2 -2
- package/components/cell/GridEditSingleSelectCell.js +5 -8
- package/components/columnHeaders/ColumnHeaderMenuIcon.js +2 -3
- package/components/columnHeaders/GridColumnGroupHeader.js +4 -5
- package/components/columnHeaders/GridColumnHeaderFilterIconButton.js +2 -3
- package/components/columnHeaders/GridColumnHeaderItem.js +8 -7
- package/components/columnHeaders/GridColumnHeaderSortIcon.js +1 -2
- package/components/columnHeaders/GridColumnHeaderTitle.js +2 -3
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +4 -2
- package/components/columnSelection/GridCellCheckboxRenderer.js +3 -5
- package/components/columnSelection/GridHeaderCheckbox.js +1 -2
- package/components/columnsManagement/GridColumnsManagement.js +17 -21
- package/components/containers/GridRoot.js +3 -3
- package/components/menu/GridMenu.js +4 -6
- package/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +2 -3
- package/components/panel/GridColumnsPanel.js +1 -2
- package/components/panel/GridPanel.d.ts +1 -10
- package/components/panel/GridPanel.js +1 -2
- package/components/panel/GridPreferencesPanel.js +2 -3
- package/components/panel/filterPanel/GridFilterForm.js +24 -27
- package/components/panel/filterPanel/GridFilterInputBoolean.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputBoolean.js +6 -7
- package/components/panel/filterPanel/GridFilterInputDate.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +3 -4
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +11 -15
- package/components/panel/filterPanel/GridFilterInputMultipleValue.js +10 -14
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +10 -11
- package/components/panel/filterPanel/GridFilterInputValue.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputValue.js +5 -7
- package/components/panel/filterPanel/GridFilterPanel.js +5 -9
- package/components/panel/filterPanel/filterPanelUtils.js +1 -1
- package/components/toolbar/GridToolbarColumnsButton.js +3 -5
- package/components/toolbar/GridToolbarDensitySelector.js +8 -10
- package/components/toolbar/GridToolbarExport.js +2 -2
- package/components/toolbar/GridToolbarExportContainer.js +3 -5
- package/components/toolbar/GridToolbarFilterButton.js +3 -5
- package/components/toolbar/GridToolbarQuickFilter.js +21 -7
- package/components/virtualization/GridVirtualScrollerContent.js +1 -2
- package/components/virtualization/GridVirtualScrollerRenderZone.js +1 -2
- package/hooks/core/strategyProcessing/useGridStrategyProcessing.js +1 -2
- package/hooks/core/useGridApiInitialization.js +4 -6
- package/hooks/features/clipboard/useGridClipboard.js +6 -5
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -16
- package/hooks/features/columnGrouping/gridColumnGroupsUtils.js +4 -8
- package/hooks/features/columnGrouping/useGridColumnGrouping.js +12 -23
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +6 -8
- package/hooks/features/columnMenu/useGridColumnMenuSlots.js +2 -2
- package/hooks/features/columnResize/useGridColumnResize.js +9 -19
- package/hooks/features/columns/gridColumnsSelector.js +1 -2
- package/hooks/features/columns/gridColumnsUtils.d.ts +0 -9
- package/hooks/features/columns/gridColumnsUtils.js +2 -22
- package/hooks/features/columns/useGridColumnSpanning.js +1 -2
- package/hooks/features/columns/useGridColumns.js +11 -19
- package/hooks/features/density/densitySelector.d.ts +4 -2
- package/hooks/features/density/densitySelector.js +8 -2
- package/hooks/features/density/densityState.d.ts +1 -4
- package/hooks/features/density/useGridDensity.d.ts +2 -4
- package/hooks/features/density/useGridDensity.js +21 -29
- package/hooks/features/dimensions/useGridDimensions.d.ts +1 -1
- package/hooks/features/dimensions/useGridDimensions.js +6 -7
- package/hooks/features/editing/useGridCellEditing.js +4 -6
- package/hooks/features/editing/useGridEditing.js +1 -2
- package/hooks/features/editing/useGridRowEditing.js +17 -10
- package/hooks/features/export/serializers/csvSerializer.d.ts +2 -0
- package/hooks/features/export/serializers/csvSerializer.js +25 -16
- package/hooks/features/export/useGridCsvExport.js +9 -10
- package/hooks/features/export/useGridPrintExport.js +9 -15
- package/hooks/features/export/utils.js +2 -3
- package/hooks/features/filter/gridFilterSelector.js +15 -22
- package/hooks/features/filter/gridFilterUtils.js +10 -16
- package/hooks/features/filter/useGridFilter.js +9 -15
- package/hooks/features/focus/useGridFocus.js +5 -6
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +1 -4
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +12 -17
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -2
- package/hooks/features/pagination/gridPaginationSelector.js +1 -2
- package/hooks/features/pagination/useGridPagination.js +2 -3
- package/hooks/features/pagination/useGridPaginationModel.js +6 -11
- package/hooks/features/pagination/useGridRowCount.js +3 -6
- package/hooks/features/preferencesPanel/useGridPreferencesPanel.js +7 -12
- package/hooks/features/rowSelection/useGridRowSelection.js +11 -16
- package/hooks/features/rows/gridRowsSelector.js +11 -19
- package/hooks/features/rows/gridRowsUtils.js +7 -9
- package/hooks/features/rows/useGridParamsApi.js +1 -1
- package/hooks/features/rows/useGridRows.js +4 -13
- package/hooks/features/rows/useGridRowsMeta.js +7 -13
- package/hooks/features/scroll/useGridScroll.js +2 -3
- package/hooks/features/sorting/gridSortingSelector.js +4 -7
- package/hooks/features/sorting/useGridSorting.js +8 -14
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +220 -71
- package/hooks/utils/useGridApiEventHandler.js +5 -10
- package/hooks/utils/useGridNativeEventListener.js +1 -2
- package/index.js +1 -1
- package/internals/index.d.ts +2 -0
- package/internals/index.js +1 -0
- package/internals/utils/useProps.js +1 -2
- package/joy/joySlots.js +7 -13
- package/models/api/gridRowsMetaApi.d.ts +1 -1
- package/models/api/index.d.ts +1 -1
- package/models/api/index.js +0 -1
- package/models/events/gridEventLookup.d.ts +7 -0
- package/models/gridExport.d.ts +6 -0
- package/models/gridStateCommunity.d.ts +1 -0
- package/models/props/DataGridProps.d.ts +26 -25
- package/modern/DataGrid/DataGrid.js +18 -17
- package/modern/DataGrid/useDataGridProps.js +4 -5
- package/modern/components/GridPagination.js +11 -2
- package/modern/components/cell/GridActionsCell.js +1 -1
- package/modern/components/cell/GridActionsCellItem.js +4 -0
- package/modern/components/cell/GridBooleanCell.js +3 -2
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +3 -1
- package/modern/components/columnHeaders/GridGenericColumnHeaderItem.js +3 -1
- package/modern/components/containers/GridRoot.js +3 -3
- package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputDate.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputValue.js +1 -1
- package/modern/components/toolbar/GridToolbarDensitySelector.js +5 -5
- package/modern/components/toolbar/GridToolbarQuickFilter.js +17 -2
- package/modern/hooks/features/clipboard/useGridClipboard.js +4 -2
- package/modern/hooks/features/columnResize/useGridColumnResize.js +1 -1
- package/modern/hooks/features/columns/gridColumnsUtils.js +0 -19
- package/modern/hooks/features/density/densitySelector.js +8 -2
- package/modern/hooks/features/density/useGridDensity.js +21 -29
- package/modern/hooks/features/dimensions/useGridDimensions.js +3 -2
- package/modern/hooks/features/editing/useGridCellEditing.js +1 -1
- package/modern/hooks/features/editing/useGridRowEditing.js +14 -5
- package/modern/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/modern/hooks/features/export/useGridCsvExport.js +2 -1
- package/modern/hooks/features/filter/gridFilterUtils.js +1 -1
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +3 -2
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -0
- package/modern/models/api/index.js +0 -1
- package/modern/utils/createSelector.js +1 -1
- package/modern/utils/domUtils.js +1 -1
- package/modern/utils/keyboardUtils.js +1 -1
- package/modern/utils/throttle.js +19 -0
- package/node/DataGrid/DataGrid.js +18 -17
- package/node/DataGrid/useDataGridProps.js +4 -5
- package/node/components/GridPagination.js +9 -1
- package/node/components/cell/GridActionsCell.js +1 -1
- package/node/components/cell/GridActionsCellItem.js +4 -0
- package/node/components/cell/GridBooleanCell.js +3 -2
- package/node/components/columnHeaders/GridColumnHeaderItem.js +3 -1
- package/node/components/columnHeaders/GridGenericColumnHeaderItem.js +3 -1
- package/node/components/containers/GridRoot.js +2 -2
- package/node/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputDate.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputValue.js +1 -1
- package/node/components/toolbar/GridToolbarDensitySelector.js +4 -4
- package/node/components/toolbar/GridToolbarQuickFilter.js +17 -2
- package/node/hooks/features/clipboard/useGridClipboard.js +4 -2
- package/node/hooks/features/columnResize/useGridColumnResize.js +1 -1
- package/node/hooks/features/columns/gridColumnsUtils.js +0 -20
- package/node/hooks/features/density/densitySelector.js +9 -3
- package/node/hooks/features/density/useGridDensity.js +22 -30
- package/node/hooks/features/dimensions/useGridDimensions.js +2 -1
- package/node/hooks/features/editing/useGridCellEditing.js +1 -1
- package/node/hooks/features/editing/useGridRowEditing.js +14 -5
- package/node/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/node/hooks/features/export/useGridCsvExport.js +2 -1
- package/node/hooks/features/filter/gridFilterUtils.js +1 -1
- package/node/hooks/features/rowSelection/useGridRowSelection.js +2 -1
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- package/node/index.js +1 -1
- package/node/internals/index.js +12 -0
- package/node/models/api/index.js +0 -11
- package/node/utils/createSelector.js +1 -1
- package/node/utils/domUtils.js +1 -1
- package/node/utils/keyboardUtils.js +1 -1
- package/node/utils/throttle.js +25 -0
- package/package.json +4 -4
- package/utils/createSelector.js +9 -9
- package/utils/domUtils.js +4 -7
- package/utils/getGridLocalization.js +9 -12
- package/utils/keyboardUtils.js +1 -1
- package/utils/throttle.d.ts +4 -0
- package/utils/throttle.js +19 -0
|
@@ -87,9 +87,8 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
|
|
|
87
87
|
}
|
|
88
88
|
let parsedValue;
|
|
89
89
|
if (column.valueParser) {
|
|
90
|
-
var _filterItem$value;
|
|
91
90
|
const parser = column.valueParser;
|
|
92
|
-
parsedValue = Array.isArray(filterItem.value) ?
|
|
91
|
+
parsedValue = Array.isArray(filterItem.value) ? filterItem.value?.map(x => parser(x, undefined, column, apiRef)) : parser(filterItem.value, undefined, column, apiRef);
|
|
93
92
|
} else {
|
|
94
93
|
parsedValue = filterItem.value;
|
|
95
94
|
}
|
|
@@ -103,7 +102,7 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
|
|
|
103
102
|
value: parsedValue
|
|
104
103
|
});
|
|
105
104
|
const filterOperators = column.filterOperators;
|
|
106
|
-
if (!
|
|
105
|
+
if (!filterOperators?.length) {
|
|
107
106
|
throw new Error(`MUI X: No filter operators found for column '${column.field}'.`);
|
|
108
107
|
}
|
|
109
108
|
const filterOperator = filterOperators.find(operator => operator.value === newFilterItem.operator);
|
|
@@ -157,7 +156,7 @@ const buildAggregatedFilterItemsApplier = (filterModel, apiRef, disableEval) =>
|
|
|
157
156
|
}
|
|
158
157
|
|
|
159
158
|
// We generate a new function with `new Function()` to avoid expensive patterns for JS engines
|
|
160
|
-
// such as a dynamic object assignment,
|
|
159
|
+
// such as a dynamic object assignment, for example `{ [dynamicKey]: value }`.
|
|
161
160
|
const filterItemCore = new Function('appliers', 'row', 'shouldApplyFilter', `"use strict";
|
|
162
161
|
${appliers.map((applier, i) => `const shouldApply${i} = !shouldApplyFilter || shouldApplyFilter(${JSON.stringify(applier.item.field)});`).join('\n')}
|
|
163
162
|
|
|
@@ -173,8 +172,7 @@ return result$$;`.replaceAll('$$', String(filterItemsApplierId)));
|
|
|
173
172
|
return filterItem;
|
|
174
173
|
};
|
|
175
174
|
export const shouldQuickFilterExcludeHiddenColumns = filterModel => {
|
|
176
|
-
|
|
177
|
-
return (_filterModel$quickFil = filterModel.quickFilterExcludeHiddenColumns) != null ? _filterModel$quickFil : true;
|
|
175
|
+
return filterModel.quickFilterExcludeHiddenColumns ?? true;
|
|
178
176
|
};
|
|
179
177
|
|
|
180
178
|
/**
|
|
@@ -184,8 +182,7 @@ export const shouldQuickFilterExcludeHiddenColumns = filterModel => {
|
|
|
184
182
|
* @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.
|
|
185
183
|
*/
|
|
186
184
|
const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
187
|
-
|
|
188
|
-
const quickFilterValues = (_filterModel$quickFil2 = (_filterModel$quickFil3 = filterModel.quickFilterValues) == null ? void 0 : _filterModel$quickFil3.filter(Boolean)) != null ? _filterModel$quickFil2 : [];
|
|
185
|
+
const quickFilterValues = filterModel.quickFilterValues?.filter(Boolean) ?? [];
|
|
189
186
|
if (quickFilterValues.length === 0) {
|
|
190
187
|
return null;
|
|
191
188
|
}
|
|
@@ -197,7 +194,7 @@ const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
|
|
|
197
194
|
const publicApiRef = getPublicApiRef(apiRef);
|
|
198
195
|
columnFields.forEach(field => {
|
|
199
196
|
const column = apiRef.current.getColumn(field);
|
|
200
|
-
const getApplyQuickFilterFn = column
|
|
197
|
+
const getApplyQuickFilterFn = column?.getApplyQuickFilterFn;
|
|
201
198
|
if (getApplyQuickFilterFn) {
|
|
202
199
|
appliersPerField.push({
|
|
203
200
|
column,
|
|
@@ -252,9 +249,8 @@ export const buildAggregatedFilterApplier = (filterModel, apiRef, disableEval) =
|
|
|
252
249
|
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(filterModel, apiRef, disableEval);
|
|
253
250
|
const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(filterModel, apiRef);
|
|
254
251
|
return function isRowMatchingFilters(row, shouldApplyFilter, result) {
|
|
255
|
-
|
|
256
|
-
result.
|
|
257
|
-
result.passingQuickFilterValues = (_isRowMatchingQuickFi = isRowMatchingQuickFilter == null ? void 0 : isRowMatchingQuickFilter(row, shouldApplyFilter)) != null ? _isRowMatchingQuickFi : null;
|
|
252
|
+
result.passingFilterItems = isRowMatchingFilterItems?.(row, shouldApplyFilter) ?? null;
|
|
253
|
+
result.passingQuickFilterValues = isRowMatchingQuickFilter?.(row, shouldApplyFilter) ?? null;
|
|
258
254
|
};
|
|
259
255
|
};
|
|
260
256
|
const isNotNull = result => result != null;
|
|
@@ -271,12 +267,11 @@ export const passFilterLogic = (allFilterItemResults, allQuickFilterResults, fil
|
|
|
271
267
|
|
|
272
268
|
// get result for filter items model
|
|
273
269
|
if (cleanedFilterItemResults.length > 0) {
|
|
274
|
-
var _filterModel$logicOpe;
|
|
275
270
|
// Return true if the item pass with one of the rows
|
|
276
271
|
const filterItemPredicate = item => {
|
|
277
272
|
return cleanedFilterItemResults.some(filterItemResult => filterItemResult[item.id]);
|
|
278
273
|
};
|
|
279
|
-
const logicOperator =
|
|
274
|
+
const logicOperator = filterModel.logicOperator ?? getDefaultGridFilterModel().logicOperator;
|
|
280
275
|
if (logicOperator === GridLogicOperator.And) {
|
|
281
276
|
const passesAllFilters = cleanedFilterItems.every(filterItemPredicate);
|
|
282
277
|
if (!passesAllFilters) {
|
|
@@ -292,12 +287,11 @@ export const passFilterLogic = (allFilterItemResults, allQuickFilterResults, fil
|
|
|
292
287
|
|
|
293
288
|
// get result for quick filter model
|
|
294
289
|
if (cleanedQuickFilterResults.length > 0 && filterModel.quickFilterValues != null) {
|
|
295
|
-
var _filterModel$quickFil4;
|
|
296
290
|
// Return true if the item pass with one of the rows
|
|
297
291
|
const quickFilterValuePredicate = value => {
|
|
298
292
|
return cleanedQuickFilterResults.some(quickFilterValueResult => quickFilterValueResult[value]);
|
|
299
293
|
};
|
|
300
|
-
const quickFilterLogicOperator =
|
|
294
|
+
const quickFilterLogicOperator = filterModel.quickFilterLogicOperator ?? getDefaultGridFilterModel().quickFilterLogicOperator;
|
|
301
295
|
if (quickFilterLogicOperator === GridLogicOperator.And) {
|
|
302
296
|
const passesAllQuickFilterValues = filterModel.quickFilterValues.every(quickFilterValuePredicate);
|
|
303
297
|
if (!passesAllQuickFilterValues) {
|
|
@@ -18,8 +18,7 @@ import { buildAggregatedFilterApplier, sanitizeFilterModel, mergeStateWithFilter
|
|
|
18
18
|
import { isDeepEqual } from '../../../utils/utils';
|
|
19
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
20
|
export const filterStateInitializer = (state, props, apiRef) => {
|
|
21
|
-
|
|
22
|
-
const filterModel = (_ref = (_props$filterModel = props.filterModel) != null ? _props$filterModel : (_props$initialState = props.initialState) == null || (_props$initialState = _props$initialState.filter) == null ? void 0 : _props$initialState.filterModel) != null ? _ref : getDefaultGridFilterModel();
|
|
21
|
+
const filterModel = props.filterModel ?? props.initialState?.filter?.filterModel ?? getDefaultGridFilterModel();
|
|
23
22
|
return _extends({}, state, {
|
|
24
23
|
filter: {
|
|
25
24
|
filterModel: sanitizeFilterModel(filterModel, props.disableMultipleColumnsFiltering, apiRef),
|
|
@@ -49,7 +48,6 @@ function createMemoizedValues() {
|
|
|
49
48
|
* @requires useGridRows (event)
|
|
50
49
|
*/
|
|
51
50
|
export const useGridFilter = (apiRef, props) => {
|
|
52
|
-
var _props$initialState3, _props$slotProps2;
|
|
53
51
|
const logger = useGridLogger(apiRef, 'useGridFilter');
|
|
54
52
|
apiRef.current.registerControlState({
|
|
55
53
|
stateId: 'filter',
|
|
@@ -64,7 +62,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
64
62
|
const isRowMatchingFilters = props.filterMode === 'client' ? buildAggregatedFilterApplier(filterModel, apiRef, props.disableEval) : null;
|
|
65
63
|
const filteringResult = apiRef.current.applyStrategyProcessor('filtering', {
|
|
66
64
|
isRowMatchingFilters,
|
|
67
|
-
filterModel: filterModel
|
|
65
|
+
filterModel: filterModel ?? getDefaultGridFilterModel()
|
|
68
66
|
});
|
|
69
67
|
const newState = _extends({}, state, {
|
|
70
68
|
filter: _extends({}, state.filter, filteringResult)
|
|
@@ -133,7 +131,6 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
133
131
|
if (targetColumnField) {
|
|
134
132
|
const filterModel = gridFilterModelSelector(apiRef);
|
|
135
133
|
const filterItemsWithValue = filterModel.items.filter(item => {
|
|
136
|
-
var _column$filterOperato;
|
|
137
134
|
if (item.value !== undefined) {
|
|
138
135
|
// Some filters like `isAnyOf` support array as `item.value`.
|
|
139
136
|
// If array is empty, we want to remove it from the filter model.
|
|
@@ -143,8 +140,8 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
143
140
|
return true;
|
|
144
141
|
}
|
|
145
142
|
const column = apiRef.current.getColumn(item.field);
|
|
146
|
-
const filterOperator =
|
|
147
|
-
const requiresFilterValue = typeof
|
|
143
|
+
const filterOperator = column.filterOperators?.find(operator => operator.value === item.operator);
|
|
144
|
+
const requiresFilterValue = typeof filterOperator?.requiresFilterValue === 'undefined' ? true : filterOperator?.requiresFilterValue;
|
|
148
145
|
|
|
149
146
|
// Operators like `isEmpty` don't have and don't require `item.value`.
|
|
150
147
|
// So we don't want to remove them from the filter model if `item.value === undefined`.
|
|
@@ -224,7 +221,6 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
224
221
|
* PRE-PROCESSING
|
|
225
222
|
*/
|
|
226
223
|
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
227
|
-
var _props$initialState2;
|
|
228
224
|
const filterModelToExport = gridFilterModelSelector(apiRef);
|
|
229
225
|
const shouldExportFilterModel =
|
|
230
226
|
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
@@ -232,7 +228,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
232
228
|
// Always export if the model is controlled
|
|
233
229
|
props.filterModel != null ||
|
|
234
230
|
// Always export if the model has been initialized
|
|
235
|
-
|
|
231
|
+
props.initialState?.filter?.filterModel != null ||
|
|
236
232
|
// Export if the model is not equal to the default value
|
|
237
233
|
!isDeepEqual(filterModelToExport, getDefaultGridFilterModel());
|
|
238
234
|
if (!shouldExportFilterModel) {
|
|
@@ -243,10 +239,9 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
243
239
|
filterModel: filterModelToExport
|
|
244
240
|
}
|
|
245
241
|
});
|
|
246
|
-
}, [apiRef, props.filterModel,
|
|
242
|
+
}, [apiRef, props.filterModel, props.initialState?.filter?.filterModel]);
|
|
247
243
|
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
248
|
-
|
|
249
|
-
const filterModel = (_context$stateToResto = context.stateToRestore.filter) == null ? void 0 : _context$stateToResto.filterModel;
|
|
244
|
+
const filterModel = context.stateToRestore.filter?.filterModel;
|
|
250
245
|
if (filterModel == null) {
|
|
251
246
|
return params;
|
|
252
247
|
}
|
|
@@ -257,12 +252,11 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
257
252
|
}, [apiRef, props.disableMultipleColumnsFiltering]);
|
|
258
253
|
const preferencePanelPreProcessing = React.useCallback((initialValue, value) => {
|
|
259
254
|
if (value === GridPreferencePanelsValue.filters) {
|
|
260
|
-
var _props$slotProps;
|
|
261
255
|
const FilterPanel = props.slots.filterPanel;
|
|
262
|
-
return /*#__PURE__*/_jsx(FilterPanel, _extends({},
|
|
256
|
+
return /*#__PURE__*/_jsx(FilterPanel, _extends({}, props.slotProps?.filterPanel));
|
|
263
257
|
}
|
|
264
258
|
return initialValue;
|
|
265
|
-
}, [props.slots.filterPanel,
|
|
259
|
+
}, [props.slots.filterPanel, props.slotProps?.filterPanel]);
|
|
266
260
|
const {
|
|
267
261
|
getRowId
|
|
268
262
|
} = props;
|
|
@@ -44,7 +44,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
44
44
|
}, [apiRef]);
|
|
45
45
|
const setCellFocus = React.useCallback((id, field) => {
|
|
46
46
|
const focusedCell = gridFocusCellSelector(apiRef);
|
|
47
|
-
if (
|
|
47
|
+
if (focusedCell?.id === id && focusedCell?.field === field) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
apiRef.current.setState(state => {
|
|
@@ -252,8 +252,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
252
252
|
apiRef.current.setColumnGroupHeaderFocus(fields[0], depth, event);
|
|
253
253
|
}, [apiRef]);
|
|
254
254
|
const handleBlur = React.useCallback((_, event) => {
|
|
255
|
-
|
|
256
|
-
if ((_event$relatedTarget = event.relatedTarget) != null && _event$relatedTarget.className.includes(gridClasses.columnHeader)) {
|
|
255
|
+
if (event.relatedTarget?.className.includes(gridClasses.columnHeader)) {
|
|
257
256
|
return;
|
|
258
257
|
}
|
|
259
258
|
logger.debug(`Clearing focus`);
|
|
@@ -286,11 +285,11 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
286
285
|
}
|
|
287
286
|
return;
|
|
288
287
|
}
|
|
289
|
-
if (
|
|
288
|
+
if (cellParams?.id === focusedCell.id && cellParams?.field === focusedCell.field) {
|
|
290
289
|
return;
|
|
291
290
|
}
|
|
292
291
|
const cellElement = apiRef.current.getCellElement(focusedCell.id, focusedCell.field);
|
|
293
|
-
if (cellElement
|
|
292
|
+
if (cellElement?.contains(event.target)) {
|
|
294
293
|
return;
|
|
295
294
|
}
|
|
296
295
|
if (cellParams) {
|
|
@@ -316,7 +315,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
316
315
|
return;
|
|
317
316
|
}
|
|
318
317
|
const cell = gridFocusCellSelector(apiRef);
|
|
319
|
-
if (
|
|
318
|
+
if (cell?.id !== params.id || cell?.field !== params.field) {
|
|
320
319
|
apiRef.current.setCellFocus(params.id, params.field);
|
|
321
320
|
}
|
|
322
321
|
}, [apiRef]);
|
|
@@ -2,9 +2,6 @@ import { createSelector } from '../../../utils/createSelector';
|
|
|
2
2
|
export const gridHeaderFilteringStateSelector = state => state.headerFiltering;
|
|
3
3
|
export const gridHeaderFilteringEnabledSelector = createSelector(gridHeaderFilteringStateSelector,
|
|
4
4
|
// No initialization in MIT, so we need to default to false to be used by `getTotalHeaderHeight`
|
|
5
|
-
headerFilteringState =>
|
|
6
|
-
var _headerFilteringState;
|
|
7
|
-
return (_headerFilteringState = headerFilteringState == null ? void 0 : headerFilteringState.enabled) != null ? _headerFilteringState : false;
|
|
8
|
-
});
|
|
5
|
+
headerFilteringState => headerFilteringState?.enabled ?? false);
|
|
9
6
|
export const gridHeaderFilteringEditFieldSelector = createSelector(gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.editing);
|
|
10
7
|
export const gridHeaderFilteringMenuSelector = createSelector(gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.menuOpen);
|
|
@@ -3,25 +3,20 @@ import * as React from 'react';
|
|
|
3
3
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
4
|
import { useGridLogger } from '../../utils';
|
|
5
5
|
import { gridColumnLookupSelector, gridColumnVisibilityModelSelector, gridColumnFieldsSelector } from '../columns/gridColumnsSelector';
|
|
6
|
-
export const headerFilteringStateInitializer = (state, props) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
};
|
|
6
|
+
export const headerFilteringStateInitializer = (state, props) => _extends({}, state, {
|
|
7
|
+
// @ts-expect-error Access `Pro` prop in MIT
|
|
8
|
+
headerFiltering: {
|
|
9
|
+
enabled: props.headerFilters ?? false,
|
|
10
|
+
editing: null,
|
|
11
|
+
menuOpen: null
|
|
12
|
+
}
|
|
13
|
+
});
|
|
17
14
|
export const useGridHeaderFiltering = (apiRef, props) => {
|
|
18
|
-
var _props$headerFilters2;
|
|
19
15
|
const logger = useGridLogger(apiRef, 'useGridHeaderFiltering');
|
|
20
16
|
// @ts-expect-error Access `Pro` prop in MIT
|
|
21
|
-
const isHeaderFilteringEnabled =
|
|
17
|
+
const isHeaderFilteringEnabled = props.headerFilters ?? false;
|
|
22
18
|
const setHeaderFilterState = React.useCallback(headerFilterState => {
|
|
23
19
|
apiRef.current.setState(state => {
|
|
24
|
-
var _headerFilterState$ed, _headerFilterState$me;
|
|
25
20
|
// Safety check to avoid MIT users from using it
|
|
26
21
|
// This hook should ultimately be moved to the Pro package
|
|
27
22
|
if (props.signature === 'DataGrid') {
|
|
@@ -29,9 +24,9 @@ export const useGridHeaderFiltering = (apiRef, props) => {
|
|
|
29
24
|
}
|
|
30
25
|
return _extends({}, state, {
|
|
31
26
|
headerFiltering: {
|
|
32
|
-
enabled: isHeaderFilteringEnabled
|
|
33
|
-
editing:
|
|
34
|
-
menuOpen:
|
|
27
|
+
enabled: isHeaderFilteringEnabled ?? false,
|
|
28
|
+
editing: headerFilterState.editing ?? null,
|
|
29
|
+
menuOpen: headerFilterState.menuOpen ?? null
|
|
35
30
|
}
|
|
36
31
|
});
|
|
37
32
|
});
|
|
@@ -127,8 +127,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
127
127
|
apiRef.current.setColumnGroupHeaderFocus(field, depth, event);
|
|
128
128
|
}, [apiRef, logger]);
|
|
129
129
|
const getRowIdFromIndex = React.useCallback(rowIndex => {
|
|
130
|
-
|
|
131
|
-
return (_currentPageRows$rowI = currentPageRows[rowIndex]) == null ? void 0 : _currentPageRows$rowI.id;
|
|
130
|
+
return currentPageRows[rowIndex]?.id;
|
|
132
131
|
}, [currentPageRows]);
|
|
133
132
|
const handleColumnHeaderKeyDown = React.useCallback((params, event) => {
|
|
134
133
|
const headerTitleNode = event.currentTarget.querySelector(`.${gridClasses.columnHeaderTitleContainerContent}`);
|
|
@@ -66,9 +66,8 @@ export const gridPaginationRowRangeSelector = createSelectorMemoized(gridPaginat
|
|
|
66
66
|
let lastRowIndex = firstRowIndex;
|
|
67
67
|
let topLevelRowAdded = 0;
|
|
68
68
|
while (lastRowIndex < visibleSortedRowEntries.length && topLevelRowAdded <= topLevelRowsInCurrentPageCount) {
|
|
69
|
-
var _rowTree$row$id;
|
|
70
69
|
const row = visibleSortedRowEntries[lastRowIndex];
|
|
71
|
-
const depth =
|
|
70
|
+
const depth = rowTree[row.id]?.depth;
|
|
72
71
|
if (depth === undefined) {
|
|
73
72
|
lastRowIndex += 1;
|
|
74
73
|
} else {
|
|
@@ -3,10 +3,9 @@ import { throwIfPageSizeExceedsTheLimit, getDefaultGridPaginationModel } from '.
|
|
|
3
3
|
import { useGridPaginationModel } from './useGridPaginationModel';
|
|
4
4
|
import { useGridRowCount } from './useGridRowCount';
|
|
5
5
|
export const paginationStateInitializer = (state, props) => {
|
|
6
|
-
|
|
7
|
-
const paginationModel = _extends({}, getDefaultGridPaginationModel(props.autoPageSize), (_props$paginationMode = props.paginationModel) != null ? _props$paginationMode : (_props$initialState = props.initialState) == null || (_props$initialState = _props$initialState.pagination) == null ? void 0 : _props$initialState.paginationModel);
|
|
6
|
+
const paginationModel = _extends({}, getDefaultGridPaginationModel(props.autoPageSize), props.paginationModel ?? props.initialState?.pagination?.paginationModel);
|
|
8
7
|
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, props.signature);
|
|
9
|
-
const rowCount =
|
|
8
|
+
const rowCount = props.rowCount ?? props.initialState?.pagination?.rowCount;
|
|
10
9
|
return _extends({}, state, {
|
|
11
10
|
pagination: {
|
|
12
11
|
paginationModel,
|
|
@@ -6,12 +6,11 @@ import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
|
6
6
|
import { gridPageCountSelector, gridPaginationModelSelector } from './gridPaginationSelector';
|
|
7
7
|
import { getPageCount, defaultPageSize, throwIfPageSizeExceedsTheLimit, getDefaultGridPaginationModel, getValidPage } from './gridPaginationUtils';
|
|
8
8
|
export const getDerivedPaginationModel = (paginationState, signature, paginationModelProp) => {
|
|
9
|
-
var _paginationModelProp$;
|
|
10
9
|
let paginationModel = paginationState.paginationModel;
|
|
11
10
|
const rowCount = paginationState.rowCount;
|
|
12
|
-
const pageSize =
|
|
11
|
+
const pageSize = paginationModelProp?.pageSize ?? paginationModel.pageSize;
|
|
13
12
|
const pageCount = getPageCount(rowCount, pageSize);
|
|
14
|
-
if (paginationModelProp && (
|
|
13
|
+
if (paginationModelProp && (paginationModelProp?.page !== paginationModel.page || paginationModelProp?.pageSize !== paginationModel.pageSize)) {
|
|
15
14
|
paginationModel = paginationModelProp;
|
|
16
15
|
}
|
|
17
16
|
const validPage = getValidPage(paginationModel.page, pageCount);
|
|
@@ -29,7 +28,6 @@ export const getDerivedPaginationModel = (paginationState, signature, pagination
|
|
|
29
28
|
* @requires useGridDimensions (event) - can be after
|
|
30
29
|
*/
|
|
31
30
|
export const useGridPaginationModel = (apiRef, props) => {
|
|
32
|
-
var _props$initialState2;
|
|
33
31
|
const logger = useGridLogger(apiRef, 'useGridPaginationModel');
|
|
34
32
|
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
35
33
|
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
@@ -89,7 +87,6 @@ export const useGridPaginationModel = (apiRef, props) => {
|
|
|
89
87
|
* PRE-PROCESSING
|
|
90
88
|
*/
|
|
91
89
|
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
92
|
-
var _props$initialState;
|
|
93
90
|
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
94
91
|
const shouldExportPaginationModel =
|
|
95
92
|
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
@@ -97,7 +94,7 @@ export const useGridPaginationModel = (apiRef, props) => {
|
|
|
97
94
|
// Always export if the `paginationModel` is controlled
|
|
98
95
|
props.paginationModel != null ||
|
|
99
96
|
// Always export if the `paginationModel` has been initialized
|
|
100
|
-
|
|
97
|
+
props.initialState?.pagination?.paginationModel != null ||
|
|
101
98
|
// Export if `page` or `pageSize` is not equal to the default value
|
|
102
99
|
paginationModel.page !== 0 && paginationModel.pageSize !== defaultPageSize(props.autoPageSize);
|
|
103
100
|
if (!shouldExportPaginationModel) {
|
|
@@ -108,10 +105,9 @@ export const useGridPaginationModel = (apiRef, props) => {
|
|
|
108
105
|
paginationModel
|
|
109
106
|
})
|
|
110
107
|
});
|
|
111
|
-
}, [apiRef, props.paginationModel,
|
|
108
|
+
}, [apiRef, props.paginationModel, props.initialState?.pagination?.paginationModel, props.autoPageSize]);
|
|
112
109
|
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
113
|
-
|
|
114
|
-
const paginationModel = (_context$stateToResto = context.stateToRestore.pagination) != null && _context$stateToResto.paginationModel ? _extends({}, getDefaultGridPaginationModel(props.autoPageSize), (_context$stateToResto2 = context.stateToRestore.pagination) == null ? void 0 : _context$stateToResto2.paginationModel) : gridPaginationModelSelector(apiRef);
|
|
110
|
+
const paginationModel = context.stateToRestore.pagination?.paginationModel ? _extends({}, getDefaultGridPaginationModel(props.autoPageSize), context.stateToRestore.pagination?.paginationModel) : gridPaginationModelSelector(apiRef);
|
|
115
111
|
apiRef.current.setState(state => _extends({}, state, {
|
|
116
112
|
pagination: _extends({}, state.pagination, {
|
|
117
113
|
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, paginationModel)
|
|
@@ -126,9 +122,8 @@ export const useGridPaginationModel = (apiRef, props) => {
|
|
|
126
122
|
* EVENTS
|
|
127
123
|
*/
|
|
128
124
|
const handlePaginationModelChange = () => {
|
|
129
|
-
var _apiRef$current$virtu;
|
|
130
125
|
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
131
|
-
if (
|
|
126
|
+
if (apiRef.current.virtualScrollerRef?.current) {
|
|
132
127
|
apiRef.current.scrollToIndexes({
|
|
133
128
|
rowIndex: paginationModel.page * paginationModel.pageSize
|
|
134
129
|
});
|
|
@@ -11,7 +11,6 @@ import { noRowCountInServerMode } from './gridPaginationUtils';
|
|
|
11
11
|
* @requires useGridDimensions (event) - can be after
|
|
12
12
|
*/
|
|
13
13
|
export const useGridRowCount = (apiRef, props) => {
|
|
14
|
-
var _props$initialState2;
|
|
15
14
|
const logger = useGridLogger(apiRef, 'useGridRowCount');
|
|
16
15
|
const visibleTopLevelRowCount = useGridSelector(apiRef, gridFilteredTopLevelRowCountSelector);
|
|
17
16
|
const rowCount = useGridSelector(apiRef, gridPaginationRowCountSelector);
|
|
@@ -46,7 +45,6 @@ export const useGridRowCount = (apiRef, props) => {
|
|
|
46
45
|
* PRE-PROCESSING
|
|
47
46
|
*/
|
|
48
47
|
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
49
|
-
var _props$initialState;
|
|
50
48
|
const exportedRowCount = gridPaginationRowCountSelector(apiRef);
|
|
51
49
|
const shouldExportRowCount =
|
|
52
50
|
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
@@ -54,7 +52,7 @@ export const useGridRowCount = (apiRef, props) => {
|
|
|
54
52
|
// Always export if the `rowCount` is controlled
|
|
55
53
|
props.rowCount != null ||
|
|
56
54
|
// Always export if the `rowCount` has been initialized
|
|
57
|
-
|
|
55
|
+
props.initialState?.pagination?.rowCount != null;
|
|
58
56
|
if (!shouldExportRowCount) {
|
|
59
57
|
return prevState;
|
|
60
58
|
}
|
|
@@ -63,10 +61,9 @@ export const useGridRowCount = (apiRef, props) => {
|
|
|
63
61
|
rowCount: exportedRowCount
|
|
64
62
|
})
|
|
65
63
|
});
|
|
66
|
-
}, [apiRef, props.rowCount,
|
|
64
|
+
}, [apiRef, props.rowCount, props.initialState?.pagination?.rowCount]);
|
|
67
65
|
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
68
|
-
|
|
69
|
-
const restoredRowCount = (_context$stateToResto = context.stateToRestore.pagination) != null && _context$stateToResto.rowCount ? context.stateToRestore.pagination.rowCount : gridPaginationRowCountSelector(apiRef);
|
|
66
|
+
const restoredRowCount = context.stateToRestore.pagination?.rowCount ? context.stateToRestore.pagination.rowCount : gridPaginationRowCountSelector(apiRef);
|
|
70
67
|
apiRef.current.setState(state => _extends({}, state, {
|
|
71
68
|
pagination: _extends({}, state.pagination, {
|
|
72
69
|
rowCount: restoredRowCount
|
|
@@ -4,20 +4,16 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
4
4
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
5
5
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
6
6
|
import { gridPreferencePanelStateSelector } from './gridPreferencePanelSelector';
|
|
7
|
-
export const preferencePanelStateInitializer = (state, props) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
};
|
|
7
|
+
export const preferencePanelStateInitializer = (state, props) => _extends({}, state, {
|
|
8
|
+
preferencePanel: props.initialState?.preferencePanel ?? {
|
|
9
|
+
open: false
|
|
10
|
+
}
|
|
11
|
+
});
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* TODO: Add a single `setPreferencePanel` method to avoid multiple `setState`
|
|
18
15
|
*/
|
|
19
16
|
export const useGridPreferencesPanel = (apiRef, props) => {
|
|
20
|
-
var _props$initialState3;
|
|
21
17
|
const logger = useGridLogger(apiRef, 'useGridPreferencesPanel');
|
|
22
18
|
const hideTimeout = React.useRef();
|
|
23
19
|
const immediateTimeout = React.useRef();
|
|
@@ -77,13 +73,12 @@ export const useGridPreferencesPanel = (apiRef, props) => {
|
|
|
77
73
|
* PRE-PROCESSING
|
|
78
74
|
*/
|
|
79
75
|
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
80
|
-
var _props$initialState2;
|
|
81
76
|
const preferencePanelToExport = gridPreferencePanelStateSelector(apiRef.current.state);
|
|
82
77
|
const shouldExportPreferencePanel =
|
|
83
78
|
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
84
79
|
!context.exportOnlyDirtyModels ||
|
|
85
80
|
// Always export if the panel was initialized
|
|
86
|
-
|
|
81
|
+
props.initialState?.preferencePanel != null ||
|
|
87
82
|
// Always export if the panel is opened
|
|
88
83
|
preferencePanelToExport.open;
|
|
89
84
|
if (!shouldExportPreferencePanel) {
|
|
@@ -92,7 +87,7 @@ export const useGridPreferencesPanel = (apiRef, props) => {
|
|
|
92
87
|
return _extends({}, prevState, {
|
|
93
88
|
preferencePanel: preferencePanelToExport
|
|
94
89
|
});
|
|
95
|
-
}, [apiRef,
|
|
90
|
+
}, [apiRef, props.initialState?.preferencePanel]);
|
|
96
91
|
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
97
92
|
const preferencePanel = context.stateToRestore.preferencePanel;
|
|
98
93
|
if (preferencePanel != null) {
|
|
@@ -7,7 +7,7 @@ import { gridRowsLookupSelector } from '../rows/gridRowsSelector';
|
|
|
7
7
|
import { gridRowSelectionStateSelector, selectedGridRowsSelector, selectedIdsLookupSelector } from './gridRowSelectionSelector';
|
|
8
8
|
import { gridPaginatedVisibleSortedGridRowIdsSelector } from '../pagination';
|
|
9
9
|
import { gridFocusCellSelector } from '../focus/gridFocusStateSelector';
|
|
10
|
-
import { gridExpandedSortedRowIdsSelector } from '../filter/gridFilterSelector';
|
|
10
|
+
import { gridExpandedSortedRowIdsSelector, gridFilterModelSelector } from '../filter/gridFilterSelector';
|
|
11
11
|
import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_ACTIONS_COLUMN_TYPE } from '../../../colDef';
|
|
12
12
|
import { GridCellModes } from '../../../models/gridEditRowModel';
|
|
13
13
|
import { isKeyboardEvent, isNavigationKey } from '../../../utils/keyboardUtils';
|
|
@@ -28,12 +28,9 @@ const getSelectionModelPropValue = (selectionModelProp, prevSelectionModel) => {
|
|
|
28
28
|
}
|
|
29
29
|
return [selectionModelProp];
|
|
30
30
|
};
|
|
31
|
-
export const rowSelectionStateInitializer = (state, props) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
rowSelection: props.rowSelection ? (_getSelectionModelPro = getSelectionModelPropValue(props.rowSelectionModel)) != null ? _getSelectionModelPro : [] : []
|
|
35
|
-
});
|
|
36
|
-
};
|
|
31
|
+
export const rowSelectionStateInitializer = (state, props) => _extends({}, state, {
|
|
32
|
+
rowSelection: props.rowSelection ? getSelectionModelPropValue(props.rowSelectionModel) ?? [] : []
|
|
33
|
+
});
|
|
37
34
|
|
|
38
35
|
/**
|
|
39
36
|
* @requires useGridRows (state, method) - can be after
|
|
@@ -67,9 +64,8 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
67
64
|
const canHaveMultipleSelection = isMultipleRowSelectionEnabled(props);
|
|
68
65
|
const visibleRows = useGridVisibleRows(apiRef, props);
|
|
69
66
|
const expandMouseRowRangeSelection = React.useCallback(id => {
|
|
70
|
-
var _lastRowToggled$curre;
|
|
71
67
|
let endId = id;
|
|
72
|
-
const startId =
|
|
68
|
+
const startId = lastRowToggled.current ?? id;
|
|
73
69
|
const isSelected = apiRef.current.isRowSelected(id);
|
|
74
70
|
if (isSelected) {
|
|
75
71
|
const visibleRowIds = gridExpandedSortedRowIdsSelector(apiRef);
|
|
@@ -113,7 +109,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
113
109
|
return false;
|
|
114
110
|
}
|
|
115
111
|
const rowNode = apiRef.current.getRowNode(id);
|
|
116
|
-
if (
|
|
112
|
+
if (rowNode?.type === 'footer' || rowNode?.type === 'pinnedRow') {
|
|
117
113
|
return false;
|
|
118
114
|
}
|
|
119
115
|
return true;
|
|
@@ -235,11 +231,10 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
235
231
|
}
|
|
236
232
|
}, [apiRef, canHaveMultipleSelection, checkboxSelection]);
|
|
237
233
|
const handleRowClick = React.useCallback((params, event) => {
|
|
238
|
-
var _closest;
|
|
239
234
|
if (disableRowSelectionOnClick) {
|
|
240
235
|
return;
|
|
241
236
|
}
|
|
242
|
-
const field =
|
|
237
|
+
const field = event.target.closest(`.${gridClasses.cell}`)?.getAttribute('data-field');
|
|
243
238
|
if (field === GRID_CHECKBOX_SELECTION_COL_DEF.field) {
|
|
244
239
|
// click on checkbox should not trigger row selection
|
|
245
240
|
return;
|
|
@@ -250,7 +245,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
250
245
|
}
|
|
251
246
|
if (field) {
|
|
252
247
|
const column = apiRef.current.getColumn(field);
|
|
253
|
-
if (
|
|
248
|
+
if (column?.type === GRID_ACTIONS_COLUMN_TYPE) {
|
|
254
249
|
return;
|
|
255
250
|
}
|
|
256
251
|
}
|
|
@@ -266,8 +261,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
266
261
|
}, [disableRowSelectionOnClick, canHaveMultipleSelection, apiRef, expandMouseRowRangeSelection, handleSingleRowSelection]);
|
|
267
262
|
const preventSelectionOnShift = React.useCallback((params, event) => {
|
|
268
263
|
if (canHaveMultipleSelection && event.shiftKey) {
|
|
269
|
-
|
|
270
|
-
(_window$getSelection = window.getSelection()) == null || _window$getSelection.removeAllRanges();
|
|
264
|
+
window.getSelection()?.removeAllRanges();
|
|
271
265
|
}
|
|
272
266
|
}, [canHaveMultipleSelection]);
|
|
273
267
|
const handleRowSelectionCheckboxChange = React.useCallback((params, event) => {
|
|
@@ -280,7 +274,8 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
280
274
|
const handleHeaderSelectionCheckboxChange = React.useCallback(params => {
|
|
281
275
|
const shouldLimitSelectionToCurrentPage = props.checkboxSelectionVisibleOnly && props.pagination;
|
|
282
276
|
const rowsToBeSelected = shouldLimitSelectionToCurrentPage ? gridPaginatedVisibleSortedGridRowIdsSelector(apiRef) : gridExpandedSortedRowIdsSelector(apiRef);
|
|
283
|
-
apiRef
|
|
277
|
+
const filterModel = gridFilterModelSelector(apiRef);
|
|
278
|
+
apiRef.current.selectRows(rowsToBeSelected, params.value, filterModel?.items.length > 0);
|
|
284
279
|
}, [apiRef, props.checkboxSelectionVisibleOnly, props.pagination]);
|
|
285
280
|
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
286
281
|
// Get the most recent cell mode because it may have been changed by another listener
|
|
@@ -22,29 +22,22 @@ export const gridDataRowIdsSelector = createSelector(gridRowsStateSelector, rows
|
|
|
22
22
|
/**
|
|
23
23
|
* @ignore - do not document.
|
|
24
24
|
*/
|
|
25
|
-
export const gridAdditionalRowGroupsSelector = createSelector(gridRowsStateSelector, rows => rows
|
|
25
|
+
export const gridAdditionalRowGroupsSelector = createSelector(gridRowsStateSelector, rows => rows?.additionalRowGroups);
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @ignore - do not document.
|
|
29
29
|
*/
|
|
30
30
|
export const gridPinnedRowsSelector = createSelectorMemoized(gridAdditionalRowGroupsSelector, additionalRowGroups => {
|
|
31
|
-
|
|
32
|
-
const rawPinnedRows = additionalRowGroups == null ? void 0 : additionalRowGroups.pinnedRows;
|
|
31
|
+
const rawPinnedRows = additionalRowGroups?.pinnedRows;
|
|
33
32
|
return {
|
|
34
|
-
bottom:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var _rowEntry$model2;
|
|
43
|
-
return {
|
|
44
|
-
id: rowEntry.id,
|
|
45
|
-
model: (_rowEntry$model2 = rowEntry.model) != null ? _rowEntry$model2 : {}
|
|
46
|
-
};
|
|
47
|
-
})) != null ? _rawPinnedRows$top$ma : []
|
|
33
|
+
bottom: rawPinnedRows?.bottom?.map(rowEntry => ({
|
|
34
|
+
id: rowEntry.id,
|
|
35
|
+
model: rowEntry.model ?? {}
|
|
36
|
+
})) ?? [],
|
|
37
|
+
top: rawPinnedRows?.top?.map(rowEntry => ({
|
|
38
|
+
id: rowEntry.id,
|
|
39
|
+
model: rowEntry.model ?? {}
|
|
40
|
+
})) ?? []
|
|
48
41
|
};
|
|
49
42
|
});
|
|
50
43
|
|
|
@@ -52,6 +45,5 @@ export const gridPinnedRowsSelector = createSelectorMemoized(gridAdditionalRowGr
|
|
|
52
45
|
* @ignore - do not document.
|
|
53
46
|
*/
|
|
54
47
|
export const gridPinnedRowsCountSelector = createSelector(gridPinnedRowsSelector, pinnedRows => {
|
|
55
|
-
|
|
56
|
-
return ((pinnedRows == null || (_pinnedRows$top = pinnedRows.top) == null ? void 0 : _pinnedRows$top.length) || 0) + ((pinnedRows == null || (_pinnedRows$bottom = pinnedRows.bottom) == null ? void 0 : _pinnedRows$bottom.length) || 0);
|
|
48
|
+
return (pinnedRows?.top?.length || 0) + (pinnedRows?.bottom?.length || 0);
|
|
57
49
|
});
|