@mui/x-data-grid 6.17.0 → 6.18.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/DataGrid/DataGrid.js +6 -0
  3. package/DataGrid/useDataGridProps.js +1 -0
  4. package/colDef/gridStringOperators.js +1 -2
  5. package/components/containers/GridRootStyles.js +2 -1
  6. package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +6 -2
  7. package/hooks/core/useGridInitialization.d.ts +1 -1
  8. package/hooks/core/useGridInitialization.js +3 -0
  9. package/hooks/features/filter/gridFilterUtils.d.ts +8 -25
  10. package/hooks/features/filter/gridFilterUtils.js +55 -24
  11. package/hooks/features/filter/useGridFilter.js +2 -2
  12. package/index.js +1 -1
  13. package/legacy/DataGrid/DataGrid.js +6 -0
  14. package/legacy/DataGrid/useDataGridProps.js +1 -0
  15. package/legacy/colDef/gridStringOperators.js +1 -2
  16. package/legacy/components/containers/GridRootStyles.js +2 -1
  17. package/legacy/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +6 -2
  18. package/legacy/hooks/core/useGridInitialization.js +3 -0
  19. package/legacy/hooks/features/filter/gridFilterUtils.js +40 -17
  20. package/legacy/hooks/features/filter/useGridFilter.js +2 -2
  21. package/legacy/index.js +1 -1
  22. package/models/api/gridApiCommon.d.ts +3 -2
  23. package/models/api/gridApiCommunity.d.ts +2 -1
  24. package/models/api/gridCoreApi.d.ts +7 -1
  25. package/models/api/gridFilterApi.d.ts +1 -1
  26. package/models/api/gridLocaleTextApi.d.ts +3 -2
  27. package/models/props/DataGridProps.d.ts +6 -0
  28. package/modern/DataGrid/DataGrid.js +6 -0
  29. package/modern/DataGrid/useDataGridProps.js +1 -0
  30. package/modern/colDef/gridStringOperators.js +1 -2
  31. package/modern/components/containers/GridRootStyles.js +2 -1
  32. package/modern/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +6 -2
  33. package/modern/hooks/core/useGridInitialization.js +3 -0
  34. package/modern/hooks/features/filter/gridFilterUtils.js +55 -24
  35. package/modern/hooks/features/filter/useGridFilter.js +2 -2
  36. package/modern/index.js +1 -1
  37. package/node/DataGrid/DataGrid.js +6 -0
  38. package/node/DataGrid/useDataGridProps.js +1 -0
  39. package/node/colDef/gridStringOperators.js +1 -2
  40. package/node/components/containers/GridRootStyles.js +2 -1
  41. package/node/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +6 -2
  42. package/node/hooks/core/useGridInitialization.js +3 -0
  43. package/node/hooks/features/filter/gridFilterUtils.js +56 -27
  44. package/node/hooks/features/filter/useGridFilter.js +2 -2
  45. package/node/index.js +1 -1
  46. package/package.json +2 -2
@@ -198,7 +198,8 @@ const GridRootStyles = exports.GridRootStyles = (0, _styles.styled)('div', {
198
198
  overflow: 'visible !important'
199
199
  },
200
200
  [`& .${_gridClasses.gridClasses.cell} > *`]: {
201
- overflow: 'visible !important'
201
+ overflow: 'visible !important',
202
+ whiteSpace: 'nowrap'
202
203
  }
203
204
  },
204
205
  [`& .${_gridClasses.gridClasses['virtualScrollerContent--overflowed']} .${_gridClasses.gridClasses['row--lastVisible']} .${_gridClasses.gridClasses.cell}`]: {
@@ -41,6 +41,10 @@ function GridColumnMenuSortItem(props) {
41
41
  if (!colDef || !colDef.sortable || !sortingOrder.some(item => !!item)) {
42
42
  return null;
43
43
  }
44
+ const getLabel = key => {
45
+ const label = apiRef.current.getLocaleText(key);
46
+ return typeof label === 'function' ? label(colDef) : label;
47
+ };
44
48
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
45
49
  children: [sortingOrder.includes('asc') && sortDirection !== 'asc' ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
46
50
  onClick: onSortMenuItemClick,
@@ -50,7 +54,7 @@ function GridColumnMenuSortItem(props) {
50
54
  fontSize: "small"
51
55
  })
52
56
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
53
- children: apiRef.current.getLocaleText('columnMenuSortAsc')
57
+ children: getLabel('columnMenuSortAsc')
54
58
  })]
55
59
  }) : null, sortingOrder.includes('desc') && sortDirection !== 'desc' ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
56
60
  onClick: onSortMenuItemClick,
@@ -60,7 +64,7 @@ function GridColumnMenuSortItem(props) {
60
64
  fontSize: "small"
61
65
  })
62
66
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
63
- children: apiRef.current.getLocaleText('columnMenuSortDesc')
67
+ children: getLabel('columnMenuSortDesc')
64
68
  })]
65
69
  }) : null, sortingOrder.includes(null) && sortDirection != null ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
66
70
  onClick: onSortMenuItemClick,
@@ -20,6 +20,9 @@ const useGridInitialization = (inputApiRef, props) => {
20
20
  (0, _pipeProcessing.useGridPipeProcessing)(privateApiRef);
21
21
  (0, _strategyProcessing.useGridStrategyProcessing)(privateApiRef);
22
22
  (0, _useGridLocaleText.useGridLocaleText)(privateApiRef, props);
23
+ privateApiRef.current.register('private', {
24
+ rootProps: props
25
+ });
23
26
  return privateApiRef;
24
27
  };
25
28
  exports.useGridInitialization = useGridInitialization;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.sanitizeFilterModel = exports.passFilterLogic = exports.mergeStateWithFilterModel = exports.cleanFilterItem = exports.buildAggregatedQuickFilterApplier = exports.buildAggregatedFilterItemsApplier = exports.buildAggregatedFilterApplier = void 0;
7
+ exports.sanitizeFilterModel = exports.passFilterLogic = exports.mergeStateWithFilterModel = exports.cleanFilterItem = exports.buildAggregatedFilterApplier = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _models = require("../../../models");
10
10
  var _utils = require("../../../colDef/utils");
@@ -23,7 +23,7 @@ try {
23
23
  /**
24
24
  * Adds default values to the optional fields of a filter items.
25
25
  * @param {GridFilterItem} item The raw filter item.
26
- * @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
26
+ * @param {React.MutableRefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
27
27
  * @return {GridFilterItem} The clean filter item with an uniq ID and an always-defined operator.
28
28
  * TODO: Make the typing reflect the different between GridFilterInputItem and GridFilterItem.
29
29
  */
@@ -78,6 +78,12 @@ const mergeStateWithFilterModel = (filterModel, disableMultipleColumnsFiltering,
78
78
  filterModel: sanitizeFilterModel(filterModel, disableMultipleColumnsFiltering, apiRef)
79
79
  });
80
80
  exports.mergeStateWithFilterModel = mergeStateWithFilterModel;
81
+ const removeDiacritics = value => {
82
+ if (typeof value === 'string') {
83
+ return value.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
84
+ }
85
+ return value;
86
+ };
81
87
  const getFilterCallbackFromItem = (filterItem, apiRef) => {
82
88
  if (!filterItem.field || !filterItem.operator) {
83
89
  return null;
@@ -93,6 +99,12 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
93
99
  } else {
94
100
  parsedValue = filterItem.value;
95
101
  }
102
+ const {
103
+ ignoreDiacritics
104
+ } = apiRef.current.rootProps;
105
+ if (ignoreDiacritics) {
106
+ parsedValue = removeDiacritics(parsedValue);
107
+ }
96
108
  const newFilterItem = (0, _extends2.default)({}, filterItem, {
97
109
  value: parsedValue
98
110
  });
@@ -115,7 +127,10 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
115
127
  v7: true,
116
128
  item: newFilterItem,
117
129
  fn: row => {
118
- const value = apiRef.current.getRowValue(row, column);
130
+ let value = apiRef.current.getRowValue(row, column);
131
+ if (ignoreDiacritics) {
132
+ value = removeDiacritics(value);
133
+ }
119
134
  return applyFilterOnRow(value, row, column, apiRef);
120
135
  }
121
136
  };
@@ -130,6 +145,9 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
130
145
  fn: rowId => {
131
146
  const params = apiRef.current.getCellParams(rowId, newFilterItem.field);
132
147
  _utils.GLOBAL_API_REF.current = apiRef;
148
+ if (ignoreDiacritics) {
149
+ params.value = removeDiacritics(params.value);
150
+ }
133
151
  const result = applyFilterOnRow(params);
134
152
  _utils.GLOBAL_API_REF.current = null;
135
153
  return result;
@@ -140,12 +158,11 @@ let filterItemsApplierId = 1;
140
158
 
141
159
  /**
142
160
  * Generates a method to easily check if a row is matching the current filter model.
143
- * @param {GridRowIdGetter | undefined} getRowId The getter for row's id.
144
161
  * @param {GridFilterModel} filterModel The model with which we want to filter the rows.
145
- * @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
162
+ * @param {React.MutableRefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
146
163
  * @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.
147
164
  */
148
- const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disableEval) => {
165
+ const buildAggregatedFilterItemsApplier = (filterModel, apiRef, disableEval) => {
149
166
  const {
150
167
  items
151
168
  } = filterModel;
@@ -160,7 +177,7 @@ const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disabl
160
177
  for (let i = 0; i < appliers.length; i += 1) {
161
178
  const applier = appliers[i];
162
179
  if (!shouldApplyFilter || shouldApplyFilter(applier.item.field)) {
163
- resultPerItemId[applier.item.id] = applier.v7 ? applier.fn(row) : applier.fn(getRowId ? getRowId(row) : row.id);
180
+ resultPerItemId[applier.item.id] = applier.v7 ? applier.fn(row) : applier.fn(apiRef.current.getRowId(row));
164
181
  }
165
182
  }
166
183
  return resultPerItemId;
@@ -176,14 +193,14 @@ const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disabl
176
193
  ${appliers.map((applier, i) => `${JSON.stringify(String(applier.item.id))}:
177
194
  !shouldApply${i} ?
178
195
  false :
179
- ${applier.v7 ? `appliers[${i}].fn(row)` : `appliers[${i}].fn(${getRowId ? 'getRowId(row)' : 'row.id'})`},
196
+ ${applier.v7 ? `appliers[${i}].fn(row)` : `appliers[${i}].fn(getRowId(row))`},
180
197
  `).join('\n')}};
181
198
 
182
199
  return result$$;
183
200
  })`;
184
201
  const filterItemCore = evalCode(filterItemTemplate.replaceAll('$$', String(filterItemsApplierId)));
185
202
  const filterItem = (row, shouldApplyItem) => {
186
- return filterItemCore(getRowId, appliers, row, shouldApplyItem);
203
+ return filterItemCore(apiRef.current.getRowId, appliers, row, shouldApplyItem);
187
204
  };
188
205
  filterItemsApplierId += 1;
189
206
  return filterItem;
@@ -191,13 +208,11 @@ const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disabl
191
208
 
192
209
  /**
193
210
  * Generates a method to easily check if a row is matching the current quick filter.
194
- * @param {GridRowIdGetter | undefined} getRowId The getter for row's id.
195
211
  * @param {any[]} filterModel The model with which we want to filter the rows.
196
- * @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
212
+ * @param {React.MutableRefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
197
213
  * @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.
198
214
  */
199
- exports.buildAggregatedFilterItemsApplier = buildAggregatedFilterItemsApplier;
200
- const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
215
+ const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
201
216
  const quickFilterValues = filterModel.quickFilterValues?.filter(Boolean) ?? [];
202
217
  if (quickFilterValues.length === 0) {
203
218
  return null;
@@ -205,6 +220,9 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
205
220
  const quickFilterExcludeHiddenColumns = filterModel.quickFilterExcludeHiddenColumns ?? false;
206
221
  const columnFields = quickFilterExcludeHiddenColumns ? (0, _columns.gridVisibleColumnFieldsSelector)(apiRef) : (0, _columns.gridColumnFieldsSelector)(apiRef);
207
222
  const appliersPerField = [];
223
+ const {
224
+ ignoreDiacritics
225
+ } = apiRef.current.rootProps;
208
226
  columnFields.forEach(field => {
209
227
  const column = apiRef.current.getColumn(field);
210
228
  const getApplyQuickFilterFn = column?.getApplyQuickFilterFn;
@@ -214,18 +232,24 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
214
232
  if (getApplyQuickFilterFnV7 && !(hasUserFunctionLegacy && !hasUserFunctionV7)) {
215
233
  appliersPerField.push({
216
234
  column,
217
- appliers: quickFilterValues.map(value => ({
218
- v7: true,
219
- fn: getApplyQuickFilterFnV7(value, column, apiRef)
220
- }))
235
+ appliers: quickFilterValues.map(quickFilterValue => {
236
+ const value = ignoreDiacritics ? removeDiacritics(quickFilterValue) : quickFilterValue;
237
+ return {
238
+ v7: true,
239
+ fn: getApplyQuickFilterFnV7(value, column, apiRef)
240
+ };
241
+ })
221
242
  });
222
243
  } else if (getApplyQuickFilterFn) {
223
244
  appliersPerField.push({
224
245
  column,
225
- appliers: quickFilterValues.map(value => ({
226
- v7: false,
227
- fn: getApplyQuickFilterFn(value, column, apiRef)
228
- }))
246
+ appliers: quickFilterValues.map(quickFilterValue => {
247
+ const value = ignoreDiacritics ? removeDiacritics(quickFilterValue) : quickFilterValue;
248
+ return {
249
+ v7: false,
250
+ fn: getApplyQuickFilterFn(value, column, apiRef)
251
+ };
252
+ })
229
253
  });
230
254
  }
231
255
  });
@@ -248,18 +272,24 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
248
272
  continue;
249
273
  }
250
274
  const applier = appliers[v];
251
- const value = apiRef.current.getRowValue(row, column);
275
+ let value = apiRef.current.getRowFormattedValue(row, column);
252
276
  if (applier.fn === null) {
253
277
  continue;
254
278
  }
255
279
  if (applier.v7) {
280
+ if (ignoreDiacritics) {
281
+ value = removeDiacritics(value);
282
+ }
256
283
  const isMatching = applier.fn(value, row, column, apiRef);
257
284
  if (isMatching) {
258
285
  result[filterValue] = true;
259
286
  continue outer;
260
287
  }
261
288
  } else {
262
- const cellParams = usedCellParams[field] ?? apiRef.current.getCellParams(getRowId ? getRowId(row) : row.id, field);
289
+ const cellParams = usedCellParams[field] ?? apiRef.current.getCellParams(apiRef.current.getRowId(row), field);
290
+ if (ignoreDiacritics) {
291
+ cellParams.value = removeDiacritics(cellParams.value);
292
+ }
263
293
  usedCellParams[field] = cellParams;
264
294
  const isMatching = applier.fn(cellParams);
265
295
  if (isMatching) {
@@ -275,10 +305,9 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
275
305
  return result;
276
306
  };
277
307
  };
278
- exports.buildAggregatedQuickFilterApplier = buildAggregatedQuickFilterApplier;
279
- const buildAggregatedFilterApplier = (getRowId, filterModel, apiRef, disableEval) => {
280
- const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(getRowId, filterModel, apiRef, disableEval);
281
- const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(getRowId, filterModel, apiRef);
308
+ const buildAggregatedFilterApplier = (filterModel, apiRef, disableEval) => {
309
+ const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(filterModel, apiRef, disableEval);
310
+ const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(filterModel, apiRef);
282
311
  return function isRowMatchingFilters(row, shouldApplyFilter, result) {
283
312
  result.passingFilterItems = isRowMatchingFilterItems?.(row, shouldApplyFilter) ?? null;
284
313
  result.passingQuickFilterValues = isRowMatchingQuickFilter?.(row, shouldApplyFilter) ?? null;
@@ -69,7 +69,7 @@ const useGridFilter = (apiRef, props) => {
69
69
  const updateFilteredRows = React.useCallback(() => {
70
70
  apiRef.current.setState(state => {
71
71
  const filterModel = (0, _gridFilterSelector.gridFilterModelSelector)(state, apiRef.current.instanceId);
72
- const isRowMatchingFilters = props.filterMode === 'client' ? (0, _gridFilterUtils.buildAggregatedFilterApplier)(props.getRowId, filterModel, apiRef, props.disableEval) : null;
72
+ const isRowMatchingFilters = props.filterMode === 'client' ? (0, _gridFilterUtils.buildAggregatedFilterApplier)(filterModel, apiRef, props.disableEval) : null;
73
73
  const filteringResult = apiRef.current.applyStrategyProcessor('filtering', {
74
74
  isRowMatchingFilters,
75
75
  filterModel: filterModel ?? (0, _gridFilterState.getDefaultGridFilterModel)()
@@ -83,7 +83,7 @@ const useGridFilter = (apiRef, props) => {
83
83
  });
84
84
  });
85
85
  apiRef.current.publishEvent('filteredRowsSet');
86
- }, [apiRef, props.filterMode, props.getRowId, props.disableEval]);
86
+ }, [apiRef, props.filterMode, props.disableEval]);
87
87
  const addColumnMenuItem = React.useCallback((columnMenuItems, colDef) => {
88
88
  if (colDef == null || colDef.filterable === false || props.disableColumnFilter) {
89
89
  return columnMenuItems;
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.17.0
2
+ * @mui/x-data-grid v6.18.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-data-grid",
3
- "version": "6.17.0",
3
+ "version": "6.18.0",
4
4
  "description": "The community edition of the data grid component (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@babel/runtime": "^7.23.2",
39
- "@mui/utils": "^5.14.14",
39
+ "@mui/utils": "^5.14.16",
40
40
  "clsx": "^2.0.0",
41
41
  "prop-types": "^15.8.1",
42
42
  "reselect": "^4.1.8"