@mui/x-data-grid 9.8.0 → 9.9.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 (180) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/DataGrid/DataGrid.js +7 -0
  3. package/DataGrid/DataGrid.mjs +7 -0
  4. package/components/GridColumnSortButton.d.mts +1 -1
  5. package/components/GridColumnSortButton.d.ts +1 -1
  6. package/components/GridColumnUnsortedIcon.d.mts +2 -1
  7. package/components/GridColumnUnsortedIcon.d.ts +2 -1
  8. package/components/GridHeader.d.mts +2 -1
  9. package/components/GridHeader.d.ts +2 -1
  10. package/components/GridHeaders.d.mts +1 -1
  11. package/components/GridHeaders.d.ts +1 -1
  12. package/components/GridPagination.d.mts +2 -1
  13. package/components/GridPagination.d.ts +2 -1
  14. package/components/GridRowDragAndDropOverlay.d.mts +1 -1
  15. package/components/GridRowDragAndDropOverlay.d.ts +1 -1
  16. package/components/GridScrollArea.d.mts +2 -1
  17. package/components/GridScrollArea.d.ts +2 -1
  18. package/components/GridScrollShadows.d.mts +2 -1
  19. package/components/GridScrollShadows.d.ts +2 -1
  20. package/components/GridScrollbarFillerCell.d.mts +1 -1
  21. package/components/GridScrollbarFillerCell.d.ts +1 -1
  22. package/components/base/GridFooterPlaceholder.d.mts +1 -1
  23. package/components/base/GridFooterPlaceholder.d.ts +1 -1
  24. package/components/base/GridFooterPlaceholder.js +1 -1
  25. package/components/base/GridFooterPlaceholder.mjs +1 -1
  26. package/components/base/GridOverlays.d.mts +1 -1
  27. package/components/base/GridOverlays.d.ts +1 -1
  28. package/components/cell/GridActionsCell.d.mts +2 -2
  29. package/components/cell/GridActionsCell.d.ts +2 -2
  30. package/components/cell/GridActionsCellItem.js +1 -58
  31. package/components/cell/GridActionsCellItem.mjs +1 -58
  32. package/components/cell/GridBooleanCell.d.mts +1 -1
  33. package/components/cell/GridBooleanCell.d.ts +1 -1
  34. package/components/cell/GridEditBooleanCell.d.mts +2 -2
  35. package/components/cell/GridEditBooleanCell.d.ts +2 -2
  36. package/components/cell/GridEditDateCell.d.mts +2 -2
  37. package/components/cell/GridEditDateCell.d.ts +2 -2
  38. package/components/cell/GridEditInputCell.d.mts +1 -1
  39. package/components/cell/GridEditInputCell.d.ts +1 -1
  40. package/components/cell/GridEditLongTextCell.d.mts +2 -2
  41. package/components/cell/GridEditLongTextCell.d.ts +2 -2
  42. package/components/cell/GridEditSingleSelectCell.d.mts +3 -2
  43. package/components/cell/GridEditSingleSelectCell.d.ts +3 -2
  44. package/components/cell/GridFooterCell.d.mts +1 -1
  45. package/components/cell/GridFooterCell.d.ts +1 -1
  46. package/components/cell/GridLongTextCell.d.mts +2 -2
  47. package/components/cell/GridLongTextCell.d.ts +2 -2
  48. package/components/cell/GridSkeletonCell.d.mts +1 -1
  49. package/components/cell/GridSkeletonCell.d.ts +1 -1
  50. package/components/columnHeaders/ColumnHeaderMenuIcon.d.mts +1 -1
  51. package/components/columnHeaders/ColumnHeaderMenuIcon.d.ts +1 -1
  52. package/components/columnHeaders/GridColumnGroupHeader.d.mts +1 -1
  53. package/components/columnHeaders/GridColumnGroupHeader.d.ts +1 -1
  54. package/components/columnHeaders/GridColumnHeaderFilterIconButton.d.mts +1 -1
  55. package/components/columnHeaders/GridColumnHeaderFilterIconButton.d.ts +1 -1
  56. package/components/columnHeaders/GridColumnHeaderItem.d.mts +1 -1
  57. package/components/columnHeaders/GridColumnHeaderItem.d.ts +1 -1
  58. package/components/columnHeaders/GridColumnHeaderSeparator.d.mts +1 -1
  59. package/components/columnHeaders/GridColumnHeaderSeparator.d.ts +1 -1
  60. package/components/columnHeaders/GridColumnHeaderSortIcon.d.mts +1 -1
  61. package/components/columnHeaders/GridColumnHeaderSortIcon.d.ts +1 -1
  62. package/components/columnHeaders/GridColumnHeaderTitle.d.mts +1 -1
  63. package/components/columnHeaders/GridColumnHeaderTitle.d.ts +1 -1
  64. package/components/columnsManagement/GridColumnsManagement.d.mts +2 -1
  65. package/components/columnsManagement/GridColumnsManagement.d.ts +2 -1
  66. package/components/menu/GridMenu.d.mts +1 -1
  67. package/components/menu/GridMenu.d.ts +1 -1
  68. package/components/menu/columnMenu/GridColumnHeaderMenu.d.mts +1 -1
  69. package/components/menu/columnMenu/GridColumnHeaderMenu.d.ts +1 -1
  70. package/components/menu/columnMenu/menuItems/GridColumnMenuColumnsItem.d.mts +2 -1
  71. package/components/menu/columnMenu/menuItems/GridColumnMenuColumnsItem.d.ts +2 -1
  72. package/components/menu/columnMenu/menuItems/GridColumnMenuFilterItem.d.mts +2 -1
  73. package/components/menu/columnMenu/menuItems/GridColumnMenuFilterItem.d.ts +2 -1
  74. package/components/menu/columnMenu/menuItems/GridColumnMenuHideItem.d.mts +2 -1
  75. package/components/menu/columnMenu/menuItems/GridColumnMenuHideItem.d.ts +2 -1
  76. package/components/menu/columnMenu/menuItems/GridColumnMenuManageItem.d.mts +2 -1
  77. package/components/menu/columnMenu/menuItems/GridColumnMenuManageItem.d.ts +2 -1
  78. package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.d.mts +2 -1
  79. package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.d.ts +2 -1
  80. package/components/panel/GridColumnsPanel.d.mts +1 -1
  81. package/components/panel/GridColumnsPanel.d.ts +1 -1
  82. package/components/panel/GridPanelContent.d.mts +1 -1
  83. package/components/panel/GridPanelContent.d.ts +1 -1
  84. package/components/panel/GridPanelContext.d.mts +1 -1
  85. package/components/panel/GridPanelContext.d.ts +1 -1
  86. package/components/panel/GridPanelFooter.d.mts +1 -1
  87. package/components/panel/GridPanelFooter.d.ts +1 -1
  88. package/components/panel/GridPanelHeader.d.mts +1 -1
  89. package/components/panel/GridPanelHeader.d.ts +1 -1
  90. package/components/panel/GridPreferencesPanel.d.mts +1 -1
  91. package/components/panel/GridPreferencesPanel.d.ts +1 -1
  92. package/components/panel/filterPanel/GridFilterForm.d.mts +1 -98
  93. package/components/panel/filterPanel/GridFilterForm.d.ts +1 -98
  94. package/components/panel/filterPanel/GridFilterForm.js +9 -355
  95. package/components/panel/filterPanel/GridFilterForm.mjs +8 -354
  96. package/components/panel/filterPanel/GridFilterFormBase.d.mts +119 -0
  97. package/components/panel/filterPanel/GridFilterFormBase.d.ts +119 -0
  98. package/components/panel/filterPanel/GridFilterFormBase.js +497 -0
  99. package/components/panel/filterPanel/GridFilterFormBase.mjs +491 -0
  100. package/components/panel/filterPanel/GridFilterInputBoolean.d.mts +2 -1
  101. package/components/panel/filterPanel/GridFilterInputBoolean.d.ts +2 -1
  102. package/components/panel/filterPanel/GridFilterInputBoolean.js +6 -1
  103. package/components/panel/filterPanel/GridFilterInputBoolean.mjs +6 -1
  104. package/components/panel/filterPanel/GridFilterInputDate.d.mts +2 -1
  105. package/components/panel/filterPanel/GridFilterInputDate.d.ts +2 -1
  106. package/components/panel/filterPanel/GridFilterInputDate.js +21 -9
  107. package/components/panel/filterPanel/GridFilterInputDate.mjs +21 -9
  108. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.mts +2 -1
  109. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +2 -1
  110. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -1
  111. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.mjs +6 -1
  112. package/components/panel/filterPanel/GridFilterInputMultipleValue.d.mts +2 -1
  113. package/components/panel/filterPanel/GridFilterInputMultipleValue.d.ts +2 -1
  114. package/components/panel/filterPanel/GridFilterInputMultipleValue.js +6 -1
  115. package/components/panel/filterPanel/GridFilterInputMultipleValue.mjs +6 -1
  116. package/components/panel/filterPanel/GridFilterInputSingleSelect.d.mts +2 -1
  117. package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +2 -1
  118. package/components/panel/filterPanel/GridFilterInputSingleSelect.js +6 -1
  119. package/components/panel/filterPanel/GridFilterInputSingleSelect.mjs +6 -1
  120. package/components/panel/filterPanel/GridFilterInputValue.d.mts +2 -1
  121. package/components/panel/filterPanel/GridFilterInputValue.d.ts +2 -1
  122. package/components/panel/filterPanel/GridFilterInputValue.js +19 -8
  123. package/components/panel/filterPanel/GridFilterInputValue.mjs +19 -8
  124. package/components/panel/filterPanel/GridFilterPanel.d.mts +3 -40
  125. package/components/panel/filterPanel/GridFilterPanel.d.ts +3 -40
  126. package/components/panel/filterPanel/GridFilterPanel.js +19 -174
  127. package/components/panel/filterPanel/GridFilterPanel.mjs +14 -173
  128. package/components/panel/filterPanel/GridFilterPanelBase.d.mts +79 -0
  129. package/components/panel/filterPanel/GridFilterPanelBase.d.ts +79 -0
  130. package/components/panel/filterPanel/GridFilterPanelBase.js +304 -0
  131. package/components/panel/filterPanel/GridFilterPanelBase.mjs +297 -0
  132. package/components/panel/filterPanel/index.d.mts +3 -1
  133. package/components/panel/filterPanel/index.d.ts +3 -1
  134. package/components/panel/filterPanel/index.js +9 -1
  135. package/components/panel/filterPanel/index.mjs +3 -0
  136. package/components/quickFilter/QuickFilter.d.mts +1 -1
  137. package/components/quickFilter/QuickFilter.d.ts +1 -1
  138. package/components/toolbar/GridToolbarExport.d.mts +2 -2
  139. package/components/toolbar/GridToolbarExport.d.ts +2 -2
  140. package/components/toolbar/GridToolbarQuickFilter.d.mts +1 -1
  141. package/components/toolbar/GridToolbarQuickFilter.d.ts +1 -1
  142. package/components/toolbarV8/GridToolbar.d.mts +3 -3
  143. package/components/toolbarV8/GridToolbar.d.ts +3 -3
  144. package/components/virtualization/GridBottomContainer.d.mts +1 -1
  145. package/components/virtualization/GridBottomContainer.d.ts +1 -1
  146. package/components/virtualization/GridTopContainer.d.mts +1 -1
  147. package/components/virtualization/GridTopContainer.d.ts +1 -1
  148. package/components/virtualization/GridVirtualScroller.d.mts +1 -1
  149. package/components/virtualization/GridVirtualScroller.d.ts +1 -1
  150. package/components/virtualization/GridVirtualScrollerFiller.d.mts +2 -1
  151. package/components/virtualization/GridVirtualScrollerFiller.d.ts +2 -1
  152. package/constants/dataGridPropsDefaultValues.js +1 -0
  153. package/constants/dataGridPropsDefaultValues.mjs +1 -0
  154. package/context/GridContextProvider.d.mts +1 -1
  155. package/context/GridContextProvider.d.ts +1 -1
  156. package/hooks/features/columnHeaders/useGridColumnHeaders.d.mts +2 -2
  157. package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +2 -2
  158. package/hooks/features/dataSource/useGridDataSourceBase.d.mts +1 -1
  159. package/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
  160. package/hooks/features/dataSource/useGridDataSourceBase.js +39 -10
  161. package/hooks/features/dataSource/useGridDataSourceBase.mjs +39 -10
  162. package/hooks/features/filter/gridFilterUtils.d.mts +12 -0
  163. package/hooks/features/filter/gridFilterUtils.d.ts +12 -0
  164. package/hooks/features/filter/gridFilterUtils.js +56 -1
  165. package/hooks/features/filter/gridFilterUtils.mjs +52 -0
  166. package/hooks/features/filter/useGridFilter.js +4 -35
  167. package/hooks/features/filter/useGridFilter.mjs +5 -36
  168. package/index.js +1 -1
  169. package/index.mjs +1 -1
  170. package/internals/demo/TailwindDemoContainer.d.mts +1 -1
  171. package/internals/demo/TailwindDemoContainer.d.ts +1 -1
  172. package/models/gridFilterInputComponent.d.mts +5 -0
  173. package/models/gridFilterInputComponent.d.ts +5 -0
  174. package/models/gridSlotsComponentsProps.d.mts +1 -1
  175. package/models/gridSlotsComponentsProps.d.ts +1 -1
  176. package/models/props/DataGridProps.d.mts +7 -0
  177. package/models/props/DataGridProps.d.ts +7 -0
  178. package/package.json +4 -4
  179. package/utils/css/context.d.mts +3 -3
  180. package/utils/css/context.d.ts +3 -3
@@ -1,367 +1,21 @@
1
1
  'use client';
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
6
- const _excluded = ["item", "hasMultipleFilters", "deleteFilter", "applyFilterChanges", "showMultiFilterOperators", "disableMultiFilterOperator", "applyMultiFilterOperatorChanges", "focusElementRef", "logicOperators", "columnsSort", "filterColumns", "deleteIconProps", "logicOperatorInputProps", "operatorInputProps", "columnInputProps", "valueInputProps", "readOnly", "children"],
7
- _excluded2 = ["InputComponentProps"];
8
4
  import * as React from 'react';
9
5
  import PropTypes from 'prop-types';
10
- import clsx from 'clsx';
11
- import composeClasses from '@mui/utils/composeClasses';
12
- import useId from '@mui/utils/useId';
13
- import capitalize from '@mui/utils/capitalize';
14
- import { styled } from '@mui/material/styles';
15
6
  import { forwardRef } from '@mui/x-internals/forwardRef';
16
- import { vars } from "../../../constants/cssVariables.mjs";
17
- import { gridFilterableColumnDefinitionsSelector, gridColumnLookupSelector } from "../../../hooks/features/columns/gridColumnsSelector.mjs";
18
- import { gridFilterModelSelector } from "../../../hooks/features/filter/gridFilterSelector.mjs";
19
- import { useGridSelector } from "../../../hooks/utils/useGridSelector.mjs";
20
- import { GridLogicOperator } from "../../../models/gridFilterItem.mjs";
21
7
  import { useGridApiContext } from "../../../hooks/utils/useGridApiContext.mjs";
22
- import { useGridRootProps } from "../../../hooks/utils/useGridRootProps.mjs";
23
- import { getDataGridUtilityClass } from "../../../constants/gridClasses.mjs";
24
- import { getValueFromValueOptions, getValueOptions } from "./filterPanelUtils.mjs";
25
- import { gridPivotActiveSelector, gridPivotInitialColumnsSelector } from "../../../hooks/features/pivoting/index.mjs";
26
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
27
- import { createElement as _createElement } from "react";
28
- const useUtilityClasses = ownerState => {
29
- const {
30
- classes
31
- } = ownerState;
32
- const slots = {
33
- root: ['filterForm'],
34
- deleteIcon: ['filterFormDeleteIcon'],
35
- logicOperatorInput: ['filterFormLogicOperatorInput'],
36
- columnInput: ['filterFormColumnInput'],
37
- operatorInput: ['filterFormOperatorInput'],
38
- valueInput: ['filterFormValueInput']
39
- };
40
- return composeClasses(slots, getDataGridUtilityClass, classes);
41
- };
42
- const GridFilterFormRoot = styled('div', {
43
- name: 'MuiDataGrid',
44
- slot: 'FilterForm'
45
- })({
46
- display: 'flex',
47
- gap: vars.spacing(1.5)
48
- });
49
- const FilterFormDeleteIcon = styled('div', {
50
- name: 'MuiDataGrid',
51
- slot: 'FilterFormDeleteIcon'
52
- })({
53
- flexShrink: 0,
54
- display: 'flex',
55
- justifyContent: 'center',
56
- alignItems: 'center'
57
- });
58
- const FilterFormLogicOperatorInput = styled('div', {
59
- name: 'MuiDataGrid',
60
- slot: 'FilterFormLogicOperatorInput'
61
- })({
62
- minWidth: 75,
63
- justifyContent: 'end'
64
- });
65
- const FilterFormColumnInput = styled('div', {
66
- name: 'MuiDataGrid',
67
- slot: 'FilterFormColumnInput'
68
- })({
69
- width: 150
70
- });
71
- const FilterFormOperatorInput = styled('div', {
72
- name: 'MuiDataGrid',
73
- slot: 'FilterFormOperatorInput'
74
- })({
75
- width: 150
76
- });
77
- const FilterFormValueInput = styled('div', {
78
- name: 'MuiDataGrid',
79
- slot: 'FilterFormValueInput'
80
- })({
81
- width: 190
82
- });
83
- const getLogicOperatorLocaleKey = logicOperator => {
84
- switch (logicOperator) {
85
- case GridLogicOperator.And:
86
- return 'filterPanelOperatorAnd';
87
- case GridLogicOperator.Or:
88
- return 'filterPanelOperatorOr';
89
- default:
90
- throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X: Invalid `logicOperator` property in the `GridFilterPanel`.' : _formatErrorMessage(71));
91
- }
92
- };
93
- const getColumnLabel = col => col.headerName || col.field;
94
- const collator = new Intl.Collator();
8
+ import { useGridSelector } from "../../../hooks/utils/useGridSelector.mjs";
9
+ import { gridFilterModelSelector } from "../../../hooks/features/filter/gridFilterSelector.mjs";
10
+ import { GridFilterFormBase } from "./GridFilterFormBase.mjs";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
95
12
  const GridFilterForm = forwardRef(function GridFilterForm(props, ref) {
96
- const {
97
- item,
98
- hasMultipleFilters,
99
- deleteFilter,
100
- applyFilterChanges,
101
- showMultiFilterOperators,
102
- disableMultiFilterOperator,
103
- applyMultiFilterOperatorChanges,
104
- focusElementRef,
105
- logicOperators = [GridLogicOperator.And, GridLogicOperator.Or],
106
- columnsSort,
107
- filterColumns,
108
- deleteIconProps = {},
109
- logicOperatorInputProps = {},
110
- operatorInputProps = {},
111
- columnInputProps = {},
112
- valueInputProps = {},
113
- readOnly
114
- } = props,
115
- other = _objectWithoutPropertiesLoose(props, _excluded);
116
13
  const apiRef = useGridApiContext();
117
- const columnLookup = useGridSelector(apiRef, gridColumnLookupSelector);
118
- const filterableColumns = useGridSelector(apiRef, gridFilterableColumnDefinitionsSelector);
119
14
  const filterModel = useGridSelector(apiRef, gridFilterModelSelector);
120
- const columnSelectId = useId();
121
- const columnSelectLabelId = useId();
122
- const operatorSelectId = useId();
123
- const operatorSelectLabelId = useId();
124
- const rootProps = useGridRootProps();
125
- const classes = useUtilityClasses(rootProps);
126
- const valueRef = React.useRef(null);
127
- const filterSelectorRef = React.useRef(null);
128
- const multiFilterOperator = filterModel.logicOperator ?? GridLogicOperator.And;
129
- const hasLogicOperatorColumn = hasMultipleFilters && logicOperators.length > 0;
130
- const baseSelectProps = rootProps.slotProps?.baseSelect || {};
131
- const isBaseSelectNative = baseSelectProps.native ?? false;
132
- const baseSelectOptionProps = rootProps.slotProps?.baseSelectOption || {};
133
- const {
134
- InputComponentProps
135
- } = valueInputProps,
136
- valueInputPropsOther = _objectWithoutPropertiesLoose(valueInputProps, _excluded2);
137
- const pivotActive = useGridSelector(apiRef, gridPivotActiveSelector);
138
- const initialColumns = useGridSelector(apiRef, gridPivotInitialColumnsSelector);
139
- const {
140
- filteredColumns,
141
- selectedField
142
- } = React.useMemo(() => {
143
- let itemField = item.field;
144
-
145
- // Yields a valid value if the current filter belongs to a column that is not filterable
146
- const selectedNonFilterableColumn = columnLookup[item.field].filterable === false ? columnLookup[item.field] : null;
147
- if (selectedNonFilterableColumn) {
148
- return {
149
- filteredColumns: [selectedNonFilterableColumn],
150
- selectedField: itemField
151
- };
152
- }
153
- if (pivotActive) {
154
- return {
155
- filteredColumns: filterableColumns.filter(column => initialColumns.get(column.field) !== undefined),
156
- selectedField: itemField
157
- };
158
- }
159
- if (filterColumns === undefined || typeof filterColumns !== 'function') {
160
- return {
161
- filteredColumns: filterableColumns,
162
- selectedField: itemField
163
- };
164
- }
165
- const filteredFields = filterColumns({
166
- field: item.field,
167
- columns: filterableColumns,
168
- currentFilters: filterModel?.items || []
169
- });
170
- return {
171
- filteredColumns: filterableColumns.filter(column => {
172
- const isFieldIncluded = filteredFields.includes(column.field);
173
- if (column.field === item.field && !isFieldIncluded) {
174
- itemField = undefined;
175
- }
176
- return isFieldIncluded;
177
- }),
178
- selectedField: itemField
179
- };
180
- }, [item.field, columnLookup, pivotActive, filterColumns, filterableColumns, filterModel?.items, initialColumns]);
181
- const sortedFilteredColumns = React.useMemo(() => {
182
- switch (columnsSort) {
183
- case 'asc':
184
- return filteredColumns.sort((a, b) => collator.compare(getColumnLabel(a), getColumnLabel(b)));
185
- case 'desc':
186
- return filteredColumns.sort((a, b) => -collator.compare(getColumnLabel(a), getColumnLabel(b)));
187
- default:
188
- return filteredColumns;
189
- }
190
- }, [filteredColumns, columnsSort]);
191
- const currentColumn = item.field ? apiRef.current.getColumn(item.field) : null;
192
- const currentOperator = React.useMemo(() => {
193
- if (!item.operator || !currentColumn) {
194
- return null;
195
- }
196
- return currentColumn.filterOperators?.find(operator => operator.value === item.operator);
197
- }, [item, currentColumn]);
198
- const changeColumn = React.useCallback(event => {
199
- const field = event.target.value;
200
- const column = apiRef.current.getColumn(field);
201
- if (column.field === currentColumn.field) {
202
- // column did not change
203
- return;
204
- }
205
-
206
- // try to keep the same operator when column change
207
- const newOperator = column.filterOperators.find(operator => operator.value === item.operator) || column.filterOperators[0];
208
-
209
- // Erase filter value if the input component or filtered column type is modified
210
- const eraseFilterValue = !newOperator.InputComponent || newOperator.InputComponent !== currentOperator?.InputComponent || column.type !== currentColumn.type;
211
- let filterValue = eraseFilterValue ? undefined : item.value;
212
-
213
- // Check filter value against the new valueOptions
214
- if (column.type === 'singleSelect' && filterValue !== undefined) {
215
- const colDef = column;
216
- const valueOptions = getValueOptions(colDef);
217
- if (Array.isArray(filterValue)) {
218
- filterValue = filterValue.filter(val => {
219
- return (
220
- // Only keep values that are in the new value options
221
- getValueFromValueOptions(val, valueOptions, colDef?.getOptionValue) !== undefined
222
- );
223
- });
224
- } else if (getValueFromValueOptions(item.value, valueOptions, colDef?.getOptionValue) === undefined) {
225
- // Reset the filter value if it is not in the new value options
226
- filterValue = undefined;
227
- }
228
- }
229
- applyFilterChanges(_extends({}, item, {
230
- field,
231
- operator: newOperator.value,
232
- value: filterValue
233
- }));
234
- }, [apiRef, applyFilterChanges, item, currentColumn, currentOperator]);
235
- const changeOperator = React.useCallback(event => {
236
- const operator = event.target.value;
237
- const newOperator = currentColumn?.filterOperators.find(op => op.value === operator);
238
- const eraseItemValue = !newOperator?.InputComponent || newOperator?.InputComponent !== currentOperator?.InputComponent;
239
- applyFilterChanges(_extends({}, item, {
240
- operator,
241
- value: eraseItemValue ? undefined : item.value
242
- }));
243
- }, [applyFilterChanges, item, currentColumn, currentOperator]);
244
- const changeLogicOperator = React.useCallback(event => {
245
- const logicOperator = event.target.value === GridLogicOperator.And.toString() ? GridLogicOperator.And : GridLogicOperator.Or;
246
- applyMultiFilterOperatorChanges(logicOperator);
247
- }, [applyMultiFilterOperatorChanges]);
248
- const handleDeleteFilter = () => {
249
- deleteFilter(item);
250
- };
251
- React.useImperativeHandle(focusElementRef, () => ({
252
- focus: () => {
253
- if (currentOperator?.InputComponent) {
254
- valueRef?.current?.focus();
255
- } else {
256
- filterSelectorRef.current.focus();
257
- }
258
- }
259
- }), [currentOperator]);
260
- return /*#__PURE__*/_jsxs(GridFilterFormRoot, _extends({
261
- className: classes.root,
262
- "data-id": item.id,
263
- ownerState: rootProps
264
- }, other, {
265
- ref: ref,
266
- children: [/*#__PURE__*/_jsx(FilterFormDeleteIcon, _extends({}, deleteIconProps, {
267
- className: clsx(classes.deleteIcon, deleteIconProps.className),
268
- ownerState: rootProps,
269
- children: /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, _extends({
270
- "aria-label": apiRef.current.getLocaleText('filterPanelDeleteIconLabel'),
271
- title: apiRef.current.getLocaleText('filterPanelDeleteIconLabel'),
272
- onClick: handleDeleteFilter,
273
- size: "small",
274
- disabled: readOnly
275
- }, rootProps.slotProps?.baseIconButton, {
276
- children: /*#__PURE__*/_jsx(rootProps.slots.filterPanelDeleteIcon, {
277
- fontSize: "small"
278
- })
279
- }))
280
- })), /*#__PURE__*/_jsx(FilterFormLogicOperatorInput, _extends({
281
- as: rootProps.slots.baseSelect,
282
- sx: [hasLogicOperatorColumn ? {
283
- display: 'flex'
284
- } : {
285
- display: 'none'
286
- }, showMultiFilterOperators ? {
287
- visibility: 'visible'
288
- } : {
289
- visibility: 'hidden'
290
- }, logicOperatorInputProps.sx],
291
- className: clsx(classes.logicOperatorInput, logicOperatorInputProps.className),
292
- ownerState: rootProps
293
- }, logicOperatorInputProps, {
294
- size: "small",
295
- slotProps: {
296
- htmlInput: {
297
- 'aria-label': apiRef.current.getLocaleText('filterPanelLogicOperator')
298
- }
299
- },
300
- value: multiFilterOperator ?? '',
301
- onChange: changeLogicOperator,
302
- disabled: !!disableMultiFilterOperator || logicOperators.length === 1,
303
- native: isBaseSelectNative
304
- }, rootProps.slotProps?.baseSelect, {
305
- children: logicOperators.map(logicOperator => /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
306
- native: isBaseSelectNative,
307
- key: logicOperator.toString(),
308
- value: logicOperator.toString()
309
- }), apiRef.current.getLocaleText(getLogicOperatorLocaleKey(logicOperator))))
310
- })), /*#__PURE__*/_jsx(FilterFormColumnInput, _extends({
311
- as: rootProps.slots.baseSelect
312
- }, columnInputProps, {
313
- className: clsx(classes.columnInput, columnInputProps.className),
314
- ownerState: rootProps,
315
- size: "small",
316
- labelId: columnSelectLabelId,
317
- id: columnSelectId,
318
- label: apiRef.current.getLocaleText('filterPanelColumn'),
319
- value: selectedField ?? '',
320
- onChange: changeColumn,
321
- native: isBaseSelectNative,
322
- disabled: readOnly
323
- }, rootProps.slotProps?.baseSelect, {
324
- children: sortedFilteredColumns.map(col => /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
325
- native: isBaseSelectNative,
326
- key: col.field,
327
- value: col.field
328
- }), getColumnLabel(col)))
329
- })), /*#__PURE__*/_jsx(FilterFormOperatorInput, _extends({
330
- as: rootProps.slots.baseSelect,
331
- size: "small"
332
- }, operatorInputProps, {
333
- className: clsx(classes.operatorInput, operatorInputProps.className),
334
- ownerState: rootProps,
335
- labelId: operatorSelectLabelId,
336
- label: apiRef.current.getLocaleText('filterPanelOperator'),
337
- id: operatorSelectId,
338
- value: item.operator,
339
- onChange: changeOperator,
340
- native: isBaseSelectNative,
341
- inputRef: filterSelectorRef,
342
- disabled: readOnly
343
- }, rootProps.slotProps?.baseSelect, {
344
- children: currentColumn?.filterOperators?.map(operator => /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
345
- native: isBaseSelectNative,
346
- key: operator.value,
347
- value: operator.value
348
- }), operator.label || apiRef.current.getLocaleText(`filterOperator${capitalize(operator.value)}`)))
349
- })), /*#__PURE__*/_jsx(FilterFormValueInput, _extends({}, valueInputPropsOther, {
350
- className: clsx(classes.valueInput, valueInputPropsOther.className),
351
- ownerState: rootProps,
352
- children: currentOperator?.InputComponent ? /*#__PURE__*/_jsx(currentOperator.InputComponent, _extends({
353
- apiRef: apiRef,
354
- item: item,
355
- applyValue: applyFilterChanges,
356
- focusElementRef: valueRef,
357
- disabled: readOnly,
358
- slotProps: {
359
- root: {
360
- size: 'small'
361
- }
362
- }
363
- }, currentOperator.InputComponentProps, InputComponentProps), item.field) : null
364
- }))]
15
+ return /*#__PURE__*/_jsx(GridFilterFormBase, _extends({
16
+ filterModel: filterModel
17
+ }, props, {
18
+ ref: ref
365
19
  }));
366
20
  });
367
21
  if (process.env.NODE_ENV !== "production") GridFilterForm.displayName = "GridFilterForm";
@@ -0,0 +1,119 @@
1
+ import * as React from 'react';
2
+ import { GridLogicOperator } from "../../../models/gridFilterItem.mjs";
3
+ import type { GridFilterItem } from "../../../models/gridFilterItem.mjs";
4
+ import type { GridFilterModel } from "../../../models/gridFilterModel.mjs";
5
+ import type { GridColDef, GridStateColDef } from "../../../models/colDef/gridColDef.mjs";
6
+ export interface FilterColumnsArgs {
7
+ field: GridColDef['field'];
8
+ columns: GridStateColDef[];
9
+ currentFilters: GridFilterItem[];
10
+ }
11
+ export interface GridFilterFormProps {
12
+ /**
13
+ * The [[GridFilterItem]] representing this form.
14
+ */
15
+ item: GridFilterItem;
16
+ /**
17
+ * If `true`, the logic operator field is rendered.
18
+ * The field will be invisible if `showMultiFilterOperators` is also `true`.
19
+ */
20
+ hasMultipleFilters: boolean;
21
+ /**
22
+ * If `true`, the logic operator field is visible.
23
+ */
24
+ showMultiFilterOperators?: boolean;
25
+ /**
26
+ * If `true`, disables the logic operator field but still renders it.
27
+ */
28
+ disableMultiFilterOperator?: boolean;
29
+ /**
30
+ * A ref allowing to set imperative focus.
31
+ * It can be passed to the el
32
+ */
33
+ focusElementRef?: React.Ref<any>;
34
+ /**
35
+ * Callback called when the operator, column field or value is changed.
36
+ * @param {GridFilterItem} item The updated [[GridFilterItem]].
37
+ */
38
+ applyFilterChanges: (item: GridFilterItem) => void;
39
+ /**
40
+ * Callback called when the logic operator is changed.
41
+ * @param {GridLogicOperator} operator The new logic operator.
42
+ */
43
+ applyMultiFilterOperatorChanges: (operator: GridLogicOperator) => void;
44
+ /**
45
+ * Callback called when the delete button is clicked.
46
+ * @param {GridFilterItem} item The deleted [[GridFilterItem]].
47
+ */
48
+ deleteFilter: (item: GridFilterItem) => void;
49
+ /**
50
+ * Allows to filter the columns displayed in the filter form.
51
+ * @param {FilterColumnsArgs} args The columns of the grid and name of field.
52
+ * @returns {GridColDef['field'][]} The filtered fields array.
53
+ */
54
+ filterColumns?: (args: FilterColumnsArgs) => GridColDef['field'][];
55
+ /**
56
+ * Sets the available logic operators.
57
+ * @default [GridLogicOperator.And, GridLogicOperator.Or]
58
+ */
59
+ logicOperators?: GridLogicOperator[];
60
+ /**
61
+ * Changes how the options in the columns selector should be ordered.
62
+ * If not specified, the order is derived from the `columns` prop.
63
+ */
64
+ columnsSort?: 'asc' | 'desc';
65
+ /**
66
+ * Props passed to the delete icon.
67
+ * @default {}
68
+ */
69
+ deleteIconProps?: any;
70
+ /**
71
+ * Props passed to the logic operator input component.
72
+ * @default {}
73
+ */
74
+ logicOperatorInputProps?: any;
75
+ /**
76
+ * Props passed to the operator input component.
77
+ * @default {}
78
+ */
79
+ operatorInputProps?: any;
80
+ /**
81
+ * Props passed to the column input component.
82
+ * @default {}
83
+ */
84
+ columnInputProps?: any;
85
+ /**
86
+ * `true` if the filter is disabled/read only.
87
+ * i.e. `colDef.fiterable = false` but passed in `filterModel`
88
+ * @default false
89
+ */
90
+ readOnly?: boolean;
91
+ /**
92
+ * Props passed to the value input component.
93
+ * @default {}
94
+ */
95
+ valueInputProps?: any;
96
+ /**
97
+ * @ignore - do not document.
98
+ */
99
+ children?: React.ReactNode;
100
+ }
101
+ export interface GridFilterFormBaseProps extends GridFilterFormProps {
102
+ /**
103
+ * @default false
104
+ */
105
+ disableDebounce?: boolean;
106
+ /**
107
+ * The filter model that populates the form.
108
+ * Its `logicOperator` drives the logic operator field and its `items` are used to compute the
109
+ * columns available in the column selector (e.g. via the `filterColumns` callback).
110
+ */
111
+ filterModel: GridFilterModel;
112
+ }
113
+ declare const GridFilterFormBase: React.ForwardRefExoticComponent<GridFilterFormBaseProps> | React.ForwardRefExoticComponent<GridFilterFormBaseProps & React.RefAttributes<HTMLDivElement>>;
114
+ /**
115
+ * The lower-level filter form rendered by `GridFilterForm` and `GridFilterPanelBase`.
116
+ * It is controlled through the `filterModel` prop instead of reading the grid filter state.
117
+ * This is an internal component that is not part of the public API.
118
+ */
119
+ export { GridFilterFormBase };
@@ -0,0 +1,119 @@
1
+ import * as React from 'react';
2
+ import { GridLogicOperator } from "../../../models/gridFilterItem.js";
3
+ import type { GridFilterItem } from "../../../models/gridFilterItem.js";
4
+ import type { GridFilterModel } from "../../../models/gridFilterModel.js";
5
+ import type { GridColDef, GridStateColDef } from "../../../models/colDef/gridColDef.js";
6
+ export interface FilterColumnsArgs {
7
+ field: GridColDef['field'];
8
+ columns: GridStateColDef[];
9
+ currentFilters: GridFilterItem[];
10
+ }
11
+ export interface GridFilterFormProps {
12
+ /**
13
+ * The [[GridFilterItem]] representing this form.
14
+ */
15
+ item: GridFilterItem;
16
+ /**
17
+ * If `true`, the logic operator field is rendered.
18
+ * The field will be invisible if `showMultiFilterOperators` is also `true`.
19
+ */
20
+ hasMultipleFilters: boolean;
21
+ /**
22
+ * If `true`, the logic operator field is visible.
23
+ */
24
+ showMultiFilterOperators?: boolean;
25
+ /**
26
+ * If `true`, disables the logic operator field but still renders it.
27
+ */
28
+ disableMultiFilterOperator?: boolean;
29
+ /**
30
+ * A ref allowing to set imperative focus.
31
+ * It can be passed to the el
32
+ */
33
+ focusElementRef?: React.Ref<any>;
34
+ /**
35
+ * Callback called when the operator, column field or value is changed.
36
+ * @param {GridFilterItem} item The updated [[GridFilterItem]].
37
+ */
38
+ applyFilterChanges: (item: GridFilterItem) => void;
39
+ /**
40
+ * Callback called when the logic operator is changed.
41
+ * @param {GridLogicOperator} operator The new logic operator.
42
+ */
43
+ applyMultiFilterOperatorChanges: (operator: GridLogicOperator) => void;
44
+ /**
45
+ * Callback called when the delete button is clicked.
46
+ * @param {GridFilterItem} item The deleted [[GridFilterItem]].
47
+ */
48
+ deleteFilter: (item: GridFilterItem) => void;
49
+ /**
50
+ * Allows to filter the columns displayed in the filter form.
51
+ * @param {FilterColumnsArgs} args The columns of the grid and name of field.
52
+ * @returns {GridColDef['field'][]} The filtered fields array.
53
+ */
54
+ filterColumns?: (args: FilterColumnsArgs) => GridColDef['field'][];
55
+ /**
56
+ * Sets the available logic operators.
57
+ * @default [GridLogicOperator.And, GridLogicOperator.Or]
58
+ */
59
+ logicOperators?: GridLogicOperator[];
60
+ /**
61
+ * Changes how the options in the columns selector should be ordered.
62
+ * If not specified, the order is derived from the `columns` prop.
63
+ */
64
+ columnsSort?: 'asc' | 'desc';
65
+ /**
66
+ * Props passed to the delete icon.
67
+ * @default {}
68
+ */
69
+ deleteIconProps?: any;
70
+ /**
71
+ * Props passed to the logic operator input component.
72
+ * @default {}
73
+ */
74
+ logicOperatorInputProps?: any;
75
+ /**
76
+ * Props passed to the operator input component.
77
+ * @default {}
78
+ */
79
+ operatorInputProps?: any;
80
+ /**
81
+ * Props passed to the column input component.
82
+ * @default {}
83
+ */
84
+ columnInputProps?: any;
85
+ /**
86
+ * `true` if the filter is disabled/read only.
87
+ * i.e. `colDef.fiterable = false` but passed in `filterModel`
88
+ * @default false
89
+ */
90
+ readOnly?: boolean;
91
+ /**
92
+ * Props passed to the value input component.
93
+ * @default {}
94
+ */
95
+ valueInputProps?: any;
96
+ /**
97
+ * @ignore - do not document.
98
+ */
99
+ children?: React.ReactNode;
100
+ }
101
+ export interface GridFilterFormBaseProps extends GridFilterFormProps {
102
+ /**
103
+ * @default false
104
+ */
105
+ disableDebounce?: boolean;
106
+ /**
107
+ * The filter model that populates the form.
108
+ * Its `logicOperator` drives the logic operator field and its `items` are used to compute the
109
+ * columns available in the column selector (e.g. via the `filterColumns` callback).
110
+ */
111
+ filterModel: GridFilterModel;
112
+ }
113
+ declare const GridFilterFormBase: React.ForwardRefExoticComponent<GridFilterFormBaseProps> | React.ForwardRefExoticComponent<GridFilterFormBaseProps & React.RefAttributes<HTMLDivElement>>;
114
+ /**
115
+ * The lower-level filter form rendered by `GridFilterForm` and `GridFilterPanelBase`.
116
+ * It is controlled through the `filterModel` prop instead of reading the grid filter state.
117
+ * This is an internal component that is not part of the public API.
118
+ */
119
+ export { GridFilterFormBase };