@mui/x-data-grid 6.4.0 → 6.5.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 +56 -0
- package/DataGrid/useDataGridProps.js +5 -12
- package/colDef/gridNumericOperators.js +0 -6
- package/components/cell/GridEditInputCell.js +4 -1
- package/components/panel/filterPanel/GridFilterInputBoolean.d.ts +15 -2
- package/components/panel/filterPanel/GridFilterInputBoolean.js +80 -36
- package/components/panel/filterPanel/GridFilterInputDate.d.ts +8 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +27 -6
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +8 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +55 -32
- package/components/panel/filterPanel/GridFilterInputValue.d.ts +11 -4
- package/components/panel/filterPanel/GridFilterInputValue.js +29 -6
- package/components/panel/filterPanel/GridFilterPanel.d.ts +2 -1
- package/components/panel/filterPanel/GridFilterPanel.js +1 -1
- package/components/panel/filterPanel/index.d.ts +3 -1
- package/components/panel/filterPanel/index.js +2 -1
- package/constants/localeTextConstants.js +26 -0
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +9 -2
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +4 -2
- package/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/hooks/features/editing/useGridEditing.js +0 -3
- package/hooks/features/focus/gridFocusState.d.ts +2 -0
- package/hooks/features/focus/gridFocusStateSelector.d.ts +2 -0
- package/hooks/features/focus/gridFocusStateSelector.js +6 -0
- package/hooks/features/focus/useGridFocus.js +55 -9
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +4 -0
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +5 -0
- package/hooks/features/headerFiltering/index.d.ts +1 -0
- package/hooks/features/headerFiltering/index.js +1 -0
- package/hooks/features/headerFiltering/useGridHeaderFiltering.d.ts +6 -0
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +91 -0
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +2 -1
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -1
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +113 -4
- package/hooks/features/rows/useGridRows.js +16 -1
- package/index.js +1 -1
- package/internals/index.d.ts +6 -1
- package/internals/index.js +4 -0
- package/internals/utils/index.d.ts +1 -0
- package/internals/utils/index.js +2 -1
- package/internals/utils/useProps.d.ts +8 -0
- package/internals/utils/useProps.js +13 -0
- package/legacy/DataGrid/useDataGridProps.js +8 -8
- package/legacy/colDef/gridNumericOperators.js +0 -6
- package/legacy/components/cell/GridEditInputCell.js +4 -1
- package/legacy/components/panel/filterPanel/GridFilterInputBoolean.js +79 -35
- package/legacy/components/panel/filterPanel/GridFilterInputDate.js +26 -5
- package/legacy/components/panel/filterPanel/GridFilterInputSingleSelect.js +54 -31
- package/legacy/components/panel/filterPanel/GridFilterInputValue.js +28 -5
- package/legacy/components/panel/filterPanel/GridFilterPanel.js +1 -1
- package/legacy/components/panel/filterPanel/index.js +2 -1
- package/legacy/constants/localeTextConstants.js +26 -0
- package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +5 -5
- package/legacy/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/legacy/hooks/features/editing/useGridEditing.js +0 -3
- package/legacy/hooks/features/focus/gridFocusStateSelector.js +10 -0
- package/legacy/hooks/features/focus/useGridFocus.js +58 -9
- package/legacy/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +11 -0
- package/legacy/hooks/features/headerFiltering/index.js +1 -0
- package/legacy/hooks/features/headerFiltering/useGridHeaderFiltering.js +93 -0
- package/legacy/hooks/features/index.js +2 -1
- package/legacy/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +113 -4
- package/legacy/hooks/features/rows/useGridRows.js +16 -1
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +4 -0
- package/legacy/internals/utils/index.js +2 -1
- package/legacy/internals/utils/useProps.js +11 -0
- package/legacy/locales/arSD.js +28 -0
- package/legacy/locales/beBY.js +28 -0
- package/legacy/locales/bgBG.js +28 -0
- package/legacy/locales/csCZ.js +36 -8
- package/legacy/locales/daDK.js +28 -0
- package/legacy/locales/deDE.js +28 -0
- package/legacy/locales/elGR.js +27 -0
- package/legacy/locales/esES.js +28 -0
- package/legacy/locales/faIR.js +28 -0
- package/legacy/locales/fiFI.js +28 -0
- package/legacy/locales/frFR.js +28 -0
- package/legacy/locales/heIL.js +30 -2
- package/legacy/locales/huHU.js +28 -0
- package/legacy/locales/itIT.js +28 -0
- package/legacy/locales/jaJP.js +28 -0
- package/legacy/locales/koKR.js +28 -0
- package/legacy/locales/nbNO.js +28 -0
- package/legacy/locales/nlNL.js +28 -0
- package/legacy/locales/plPL.js +28 -0
- package/legacy/locales/ptBR.js +28 -0
- package/legacy/locales/roRO.js +28 -0
- package/legacy/locales/ruRU.js +28 -0
- package/legacy/locales/skSK.js +28 -0
- package/legacy/locales/svSE.js +28 -0
- package/legacy/locales/trTR.js +28 -0
- package/legacy/locales/ukUA.js +28 -0
- package/legacy/locales/urPK.js +28 -0
- package/legacy/locales/viVN.js +27 -0
- package/legacy/locales/zhCN.js +28 -0
- package/legacy/locales/zhTW.js +28 -0
- package/legacy/material/index.js +2 -0
- package/legacy/models/api/gridHeaderFilteringApi.js +1 -0
- package/legacy/models/gridHeaderFilteringModel.js +1 -0
- package/legacy/models/index.js +0 -1
- package/locales/arSD.js +28 -0
- package/locales/beBY.js +28 -0
- package/locales/bgBG.js +28 -0
- package/locales/csCZ.js +36 -8
- package/locales/daDK.js +28 -0
- package/locales/deDE.js +28 -0
- package/locales/elGR.js +27 -0
- package/locales/esES.js +28 -0
- package/locales/faIR.js +28 -0
- package/locales/fiFI.js +28 -0
- package/locales/frFR.js +28 -0
- package/locales/heIL.js +30 -2
- package/locales/huHU.js +28 -0
- package/locales/itIT.js +28 -0
- package/locales/jaJP.js +28 -0
- package/locales/koKR.js +28 -0
- package/locales/nbNO.js +28 -0
- package/locales/nlNL.js +28 -0
- package/locales/plPL.js +28 -0
- package/locales/ptBR.js +28 -0
- package/locales/roRO.js +28 -0
- package/locales/ruRU.js +28 -0
- package/locales/skSK.js +28 -0
- package/locales/svSE.js +28 -0
- package/locales/trTR.js +28 -0
- package/locales/ukUA.js +28 -0
- package/locales/urPK.js +28 -0
- package/locales/viVN.js +27 -0
- package/locales/zhCN.js +28 -0
- package/locales/zhTW.js +28 -0
- package/material/index.d.ts +3 -66
- package/material/index.js +2 -0
- package/models/api/gridApiCommon.d.ts +3 -2
- package/models/api/gridCoreApi.d.ts +4 -0
- package/models/api/gridFocusApi.d.ts +6 -0
- package/models/api/gridHeaderFilteringApi.d.ts +30 -0
- package/models/api/gridHeaderFilteringApi.js +1 -0
- package/models/api/gridLocaleTextApi.d.ts +25 -0
- package/models/events/gridEventLookup.d.ts +27 -1
- package/models/gridFilterOperator.d.ts +4 -0
- package/models/gridHeaderFilteringModel.d.ts +5 -0
- package/models/gridHeaderFilteringModel.js +1 -0
- package/models/gridSlotsComponent.d.ts +16 -4
- package/models/gridStateCommunity.d.ts +2 -0
- package/models/index.d.ts +1 -1
- package/models/index.js +0 -1
- package/modern/DataGrid/useDataGridProps.js +5 -12
- package/modern/colDef/gridNumericOperators.js +0 -6
- package/modern/components/cell/GridEditInputCell.js +4 -1
- package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +80 -36
- package/modern/components/panel/filterPanel/GridFilterInputDate.js +27 -6
- package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +55 -32
- package/modern/components/panel/filterPanel/GridFilterInputValue.js +29 -6
- package/modern/components/panel/filterPanel/GridFilterPanel.js +1 -1
- package/modern/components/panel/filterPanel/index.js +2 -1
- package/modern/constants/localeTextConstants.js +26 -0
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +4 -2
- package/modern/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/modern/hooks/features/editing/useGridEditing.js +0 -3
- package/modern/hooks/features/focus/gridFocusStateSelector.js +6 -0
- package/modern/hooks/features/focus/useGridFocus.js +55 -9
- package/modern/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +5 -0
- package/modern/hooks/features/headerFiltering/index.js +1 -0
- package/modern/hooks/features/headerFiltering/useGridHeaderFiltering.js +90 -0
- package/modern/hooks/features/index.js +2 -1
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +113 -4
- package/modern/hooks/features/rows/useGridRows.js +16 -1
- package/modern/index.js +1 -1
- package/modern/internals/index.js +4 -0
- package/modern/internals/utils/index.js +2 -1
- package/modern/internals/utils/useProps.js +13 -0
- package/modern/locales/arSD.js +28 -0
- package/modern/locales/beBY.js +28 -0
- package/modern/locales/bgBG.js +28 -0
- package/modern/locales/csCZ.js +36 -8
- package/modern/locales/daDK.js +28 -0
- package/modern/locales/deDE.js +28 -0
- package/modern/locales/elGR.js +27 -0
- package/modern/locales/esES.js +28 -0
- package/modern/locales/faIR.js +28 -0
- package/modern/locales/fiFI.js +28 -0
- package/modern/locales/frFR.js +28 -0
- package/modern/locales/heIL.js +30 -2
- package/modern/locales/huHU.js +28 -0
- package/modern/locales/itIT.js +28 -0
- package/modern/locales/jaJP.js +28 -0
- package/modern/locales/koKR.js +28 -0
- package/modern/locales/nbNO.js +28 -0
- package/modern/locales/nlNL.js +28 -0
- package/modern/locales/plPL.js +28 -0
- package/modern/locales/ptBR.js +28 -0
- package/modern/locales/roRO.js +28 -0
- package/modern/locales/ruRU.js +28 -0
- package/modern/locales/skSK.js +28 -0
- package/modern/locales/svSE.js +28 -0
- package/modern/locales/trTR.js +28 -0
- package/modern/locales/ukUA.js +28 -0
- package/modern/locales/urPK.js +28 -0
- package/modern/locales/viVN.js +27 -0
- package/modern/locales/zhCN.js +28 -0
- package/modern/locales/zhTW.js +28 -0
- package/modern/material/index.js +2 -0
- package/modern/models/api/gridHeaderFilteringApi.js +1 -0
- package/modern/models/gridHeaderFilteringModel.js +1 -0
- package/modern/models/index.js +0 -1
- package/node/DataGrid/useDataGridProps.js +4 -11
- package/node/colDef/gridNumericOperators.js +0 -6
- package/node/components/cell/GridEditInputCell.js +4 -1
- package/node/components/panel/filterPanel/GridFilterInputBoolean.js +78 -35
- package/node/components/panel/filterPanel/GridFilterInputDate.js +27 -6
- package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +55 -32
- package/node/components/panel/filterPanel/GridFilterInputValue.js +29 -6
- package/node/components/panel/filterPanel/GridFilterPanel.js +2 -1
- package/node/components/panel/filterPanel/index.js +26 -8
- package/node/constants/localeTextConstants.js +26 -0
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +4 -2
- package/node/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/node/hooks/features/editing/useGridEditing.js +0 -3
- package/node/hooks/features/focus/gridFocusStateSelector.js +9 -1
- package/node/hooks/features/focus/useGridFocus.js +55 -9
- package/node/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +15 -0
- package/node/hooks/features/headerFiltering/index.js +16 -0
- package/node/hooks/features/headerFiltering/useGridHeaderFiltering.js +101 -0
- package/node/hooks/features/index.js +11 -0
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +113 -4
- package/node/hooks/features/rows/useGridRows.js +16 -1
- package/node/index.js +1 -1
- package/node/internals/index.js +46 -0
- package/node/internals/utils/index.js +11 -0
- package/node/internals/utils/useProps.js +22 -0
- package/node/locales/arSD.js +28 -0
- package/node/locales/beBY.js +28 -0
- package/node/locales/bgBG.js +28 -0
- package/node/locales/csCZ.js +36 -8
- package/node/locales/daDK.js +28 -0
- package/node/locales/deDE.js +28 -0
- package/node/locales/elGR.js +27 -0
- package/node/locales/esES.js +28 -0
- package/node/locales/faIR.js +28 -0
- package/node/locales/fiFI.js +28 -0
- package/node/locales/frFR.js +28 -0
- package/node/locales/heIL.js +30 -2
- package/node/locales/huHU.js +28 -0
- package/node/locales/itIT.js +28 -0
- package/node/locales/jaJP.js +28 -0
- package/node/locales/koKR.js +28 -0
- package/node/locales/nbNO.js +28 -0
- package/node/locales/nlNL.js +28 -0
- package/node/locales/plPL.js +28 -0
- package/node/locales/ptBR.js +28 -0
- package/node/locales/roRO.js +28 -0
- package/node/locales/ruRU.js +28 -0
- package/node/locales/skSK.js +28 -0
- package/node/locales/svSE.js +28 -0
- package/node/locales/trTR.js +28 -0
- package/node/locales/ukUA.js +28 -0
- package/node/locales/urPK.js +28 -0
- package/node/locales/viVN.js +27 -0
- package/node/locales/zhCN.js +28 -0
- package/node/locales/zhTW.js +28 -0
- package/node/material/index.js +2 -0
- package/node/models/api/gridHeaderFilteringApi.js +5 -0
- package/node/models/gridHeaderFilteringModel.js +5 -0
- package/node/models/index.js +0 -11
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "getOptionLabel", "getOptionValue"];
|
|
3
|
+
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "getOptionLabel", "getOptionValue", "placeholder", "tabIndex", "label", "headerFilterMenu", "isFilterActive", "clearButton"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { unstable_useId as useId } from '@mui/utils';
|
|
7
|
+
import { styled } from '@mui/material/styles';
|
|
7
8
|
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
|
|
8
9
|
import { getValueFromValueOptions, isSingleSelectColDef } from './filterPanelUtils';
|
|
9
10
|
import { createElement as _createElement } from "react";
|
|
@@ -33,6 +34,11 @@ const renderSingleSelectOptions = ({
|
|
|
33
34
|
}), label);
|
|
34
35
|
});
|
|
35
36
|
};
|
|
37
|
+
const SingleSelectOperatorContainer = styled('div')({
|
|
38
|
+
display: 'flex',
|
|
39
|
+
alignItems: 'flex-end',
|
|
40
|
+
width: '100%'
|
|
41
|
+
});
|
|
36
42
|
function GridFilterInputSingleSelect(props) {
|
|
37
43
|
const {
|
|
38
44
|
item,
|
|
@@ -41,7 +47,13 @@ function GridFilterInputSingleSelect(props) {
|
|
|
41
47
|
apiRef,
|
|
42
48
|
focusElementRef,
|
|
43
49
|
getOptionLabel: getOptionLabelProp,
|
|
44
|
-
getOptionValue: getOptionValueProp
|
|
50
|
+
getOptionValue: getOptionValueProp,
|
|
51
|
+
placeholder,
|
|
52
|
+
tabIndex,
|
|
53
|
+
label: labelProp,
|
|
54
|
+
headerFilterMenu,
|
|
55
|
+
isFilterActive,
|
|
56
|
+
clearButton
|
|
45
57
|
} = props,
|
|
46
58
|
others = _objectWithoutPropertiesLoose(props, _excluded);
|
|
47
59
|
const [filterValueState, setFilterValueState] = React.useState(item.value ?? '');
|
|
@@ -99,36 +111,40 @@ function GridFilterInputSingleSelect(props) {
|
|
|
99
111
|
if (!isSingleSelectColDef(resolvedColumn)) {
|
|
100
112
|
return null;
|
|
101
113
|
}
|
|
102
|
-
const label = apiRef.current.getLocaleText('filterPanelInputLabel');
|
|
103
|
-
return /*#__PURE__*/_jsxs(
|
|
104
|
-
children: [/*#__PURE__*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
114
|
+
const label = labelProp ?? apiRef.current.getLocaleText('filterPanelInputLabel');
|
|
115
|
+
return /*#__PURE__*/_jsxs(SingleSelectOperatorContainer, {
|
|
116
|
+
children: [/*#__PURE__*/_jsxs(rootProps.slots.baseFormControl, {
|
|
117
|
+
children: [/*#__PURE__*/_jsx(rootProps.slots.baseInputLabel, _extends({}, rootProps.slotProps?.baseInputLabel, {
|
|
118
|
+
id: labelId,
|
|
119
|
+
shrink: true,
|
|
120
|
+
variant: "standard",
|
|
121
|
+
children: label
|
|
122
|
+
})), /*#__PURE__*/_jsx(rootProps.slots.baseSelect, _extends({
|
|
123
|
+
id: id,
|
|
124
|
+
label: label,
|
|
125
|
+
labelId: labelId,
|
|
126
|
+
value: filterValueState,
|
|
127
|
+
onChange: onFilterChange,
|
|
128
|
+
startAdornment: isFilterActive ? headerFilterMenu : null,
|
|
129
|
+
variant: "standard",
|
|
130
|
+
type: type || 'text',
|
|
131
|
+
inputProps: {
|
|
132
|
+
tabIndex,
|
|
133
|
+
ref: focusElementRef,
|
|
134
|
+
placeholder: placeholder ?? apiRef.current.getLocaleText('filterPanelInputPlaceholder')
|
|
135
|
+
},
|
|
136
|
+
native: isSelectNative
|
|
137
|
+
}, others, rootProps.slotProps?.baseSelect, {
|
|
138
|
+
children: renderSingleSelectOptions({
|
|
139
|
+
column: resolvedColumn,
|
|
140
|
+
OptionComponent: rootProps.slots.baseSelectOption,
|
|
141
|
+
getOptionLabel,
|
|
142
|
+
getOptionValue,
|
|
143
|
+
isSelectNative,
|
|
144
|
+
baseSelectOptionProps: rootProps.slotProps?.baseSelectOption
|
|
145
|
+
})
|
|
146
|
+
}))]
|
|
147
|
+
}), clearButton]
|
|
132
148
|
});
|
|
133
149
|
}
|
|
134
150
|
process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes = {
|
|
@@ -140,6 +156,7 @@ process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes =
|
|
|
140
156
|
current: PropTypes.object.isRequired
|
|
141
157
|
}).isRequired,
|
|
142
158
|
applyValue: PropTypes.func.isRequired,
|
|
159
|
+
clearButton: PropTypes.node,
|
|
143
160
|
focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
|
|
144
161
|
/**
|
|
145
162
|
* Used to determine the label displayed for a given value option.
|
|
@@ -153,6 +170,12 @@ process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes =
|
|
|
153
170
|
* @returns {string} The value to be used.
|
|
154
171
|
*/
|
|
155
172
|
getOptionValue: PropTypes.func,
|
|
173
|
+
headerFilterMenu: PropTypes.node,
|
|
174
|
+
/**
|
|
175
|
+
* It is `true` if the filter either has a value or an operator with no value
|
|
176
|
+
* required is selected (e.g. `isEmpty`)
|
|
177
|
+
*/
|
|
178
|
+
isFilterActive: PropTypes.bool,
|
|
156
179
|
item: PropTypes.shape({
|
|
157
180
|
field: PropTypes.string.isRequired,
|
|
158
181
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef"];
|
|
3
|
+
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "tabIndex", "disabled", "headerFilterMenu", "isFilterActive", "clearButton", "InputProps"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { unstable_useId as useId } from '@mui/utils';
|
|
@@ -13,7 +13,13 @@ function GridFilterInputValue(props) {
|
|
|
13
13
|
applyValue,
|
|
14
14
|
type,
|
|
15
15
|
apiRef,
|
|
16
|
-
focusElementRef
|
|
16
|
+
focusElementRef,
|
|
17
|
+
tabIndex,
|
|
18
|
+
disabled,
|
|
19
|
+
headerFilterMenu,
|
|
20
|
+
isFilterActive,
|
|
21
|
+
clearButton,
|
|
22
|
+
InputProps
|
|
17
23
|
} = props,
|
|
18
24
|
others = _objectWithoutPropertiesLoose(props, _excluded);
|
|
19
25
|
const filterTimeout = React.useRef();
|
|
@@ -44,9 +50,6 @@ function GridFilterInputValue(props) {
|
|
|
44
50
|
const itemValue = item.value ?? '';
|
|
45
51
|
setFilterValueState(String(itemValue));
|
|
46
52
|
}, [item.value]);
|
|
47
|
-
const InputProps = applying ? {
|
|
48
|
-
endAdornment: /*#__PURE__*/_jsx(rootProps.slots.loadIcon, {})
|
|
49
|
-
} : others.InputProps;
|
|
50
53
|
return /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
|
|
51
54
|
id: id,
|
|
52
55
|
label: apiRef.current.getLocaleText('filterPanelInputLabel'),
|
|
@@ -55,7 +58,20 @@ function GridFilterInputValue(props) {
|
|
|
55
58
|
onChange: onFilterChange,
|
|
56
59
|
variant: "standard",
|
|
57
60
|
type: type || 'text',
|
|
58
|
-
InputProps:
|
|
61
|
+
InputProps: _extends({}, applying || clearButton ? {
|
|
62
|
+
endAdornment: applying ? /*#__PURE__*/_jsx(rootProps.slots.loadIcon, {
|
|
63
|
+
fontSize: "small",
|
|
64
|
+
color: "action"
|
|
65
|
+
}) : clearButton
|
|
66
|
+
} : {}, headerFilterMenu && isFilterActive ? {
|
|
67
|
+
startAdornment: headerFilterMenu
|
|
68
|
+
} : {}, {
|
|
69
|
+
disabled
|
|
70
|
+
}, InputProps, {
|
|
71
|
+
inputProps: _extends({
|
|
72
|
+
tabIndex
|
|
73
|
+
}, InputProps?.inputProps)
|
|
74
|
+
}),
|
|
59
75
|
InputLabelProps: {
|
|
60
76
|
shrink: true
|
|
61
77
|
},
|
|
@@ -71,7 +87,14 @@ process.env.NODE_ENV !== "production" ? GridFilterInputValue.propTypes = {
|
|
|
71
87
|
current: PropTypes.object.isRequired
|
|
72
88
|
}).isRequired,
|
|
73
89
|
applyValue: PropTypes.func.isRequired,
|
|
90
|
+
clearButton: PropTypes.node,
|
|
74
91
|
focusElementRef: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.func, PropTypes.object]),
|
|
92
|
+
headerFilterMenu: PropTypes.node,
|
|
93
|
+
/**
|
|
94
|
+
* It is `true` if the filter either has a value or an operator with no value
|
|
95
|
+
* required is selected (e.g. `isEmpty`)
|
|
96
|
+
*/
|
|
97
|
+
isFilterActive: PropTypes.bool,
|
|
75
98
|
item: PropTypes.shape({
|
|
76
99
|
field: PropTypes.string.isRequired,
|
|
77
100
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
@@ -205,4 +205,4 @@ process.env.NODE_ENV !== "production" ? GridFilterPanel.propTypes = {
|
|
|
205
205
|
*/
|
|
206
206
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
207
207
|
} : void 0;
|
|
208
|
-
export { GridFilterPanel };
|
|
208
|
+
export { GridFilterPanel, getGridFilter };
|
|
@@ -2,7 +2,8 @@ export * from './GridFilterForm';
|
|
|
2
2
|
export * from './GridFilterInputValue';
|
|
3
3
|
export * from './GridFilterInputDate';
|
|
4
4
|
export * from './GridFilterInputSingleSelect';
|
|
5
|
+
export * from './GridFilterInputBoolean';
|
|
5
6
|
export * from './GridFilterInputValueProps';
|
|
6
|
-
export
|
|
7
|
+
export { GridFilterPanel } from './GridFilterPanel';
|
|
7
8
|
export * from './GridFilterInputMultipleValue';
|
|
8
9
|
export * from './GridFilterInputMultipleSingleSelect';
|
|
@@ -58,6 +58,32 @@ export const GRID_DEFAULT_LOCALE_TEXT = {
|
|
|
58
58
|
filterOperatorIsEmpty: 'is empty',
|
|
59
59
|
filterOperatorIsNotEmpty: 'is not empty',
|
|
60
60
|
filterOperatorIsAnyOf: 'is any of',
|
|
61
|
+
'filterOperator=': '=',
|
|
62
|
+
'filterOperator!=': '!=',
|
|
63
|
+
'filterOperator>': '>',
|
|
64
|
+
'filterOperator>=': '>=',
|
|
65
|
+
'filterOperator<': '<',
|
|
66
|
+
'filterOperator<=': '<=',
|
|
67
|
+
// Header filter operators text
|
|
68
|
+
headerFilterOperatorContains: 'Contains',
|
|
69
|
+
headerFilterOperatorEquals: 'Equals',
|
|
70
|
+
headerFilterOperatorStartsWith: 'Starts with',
|
|
71
|
+
headerFilterOperatorEndsWith: 'Ends with',
|
|
72
|
+
headerFilterOperatorIs: 'Is',
|
|
73
|
+
headerFilterOperatorNot: 'Is not',
|
|
74
|
+
headerFilterOperatorAfter: 'Is after',
|
|
75
|
+
headerFilterOperatorOnOrAfter: 'Is on or after',
|
|
76
|
+
headerFilterOperatorBefore: 'Is before',
|
|
77
|
+
headerFilterOperatorOnOrBefore: 'Is on or before',
|
|
78
|
+
headerFilterOperatorIsEmpty: 'Is empty',
|
|
79
|
+
headerFilterOperatorIsNotEmpty: 'Is not empty',
|
|
80
|
+
headerFilterOperatorIsAnyOf: 'Is any of',
|
|
81
|
+
'headerFilterOperator=': 'Equals',
|
|
82
|
+
'headerFilterOperator!=': 'Not equals',
|
|
83
|
+
'headerFilterOperator>': 'Is greater than',
|
|
84
|
+
'headerFilterOperator>=': 'Is greater than or equal to',
|
|
85
|
+
'headerFilterOperator<': 'Is less than',
|
|
86
|
+
'headerFilterOperator<=': 'Is less than or equal to',
|
|
61
87
|
// Filter values text
|
|
62
88
|
filterValueAny: 'any',
|
|
63
89
|
filterValueTrue: 'true',
|
|
@@ -260,7 +260,7 @@ export const useGridColumnHeaders = props => {
|
|
|
260
260
|
const tabIndex = columnGroupHeaderTabIndexState !== null && columnGroupHeaderTabIndexState.depth === depth && columnFields.includes(columnGroupHeaderTabIndexState.field) ? 0 : -1;
|
|
261
261
|
const headerInfo = {
|
|
262
262
|
groupId,
|
|
263
|
-
width: columnFields.
|
|
263
|
+
width: columnFields.reduce((acc, field) => acc + apiRef.current.getColumn(field).computedWidth, 0),
|
|
264
264
|
fields: columnFields,
|
|
265
265
|
colIndex: columnIndex,
|
|
266
266
|
hasFocus,
|
|
@@ -316,6 +316,7 @@ export const useGridColumnHeaders = props => {
|
|
|
316
316
|
return {
|
|
317
317
|
renderContext,
|
|
318
318
|
getColumnHeaders,
|
|
319
|
+
getColumnsToRender,
|
|
319
320
|
getColumnGroupHeaders,
|
|
320
321
|
isDragging: !!dragCol,
|
|
321
322
|
getRootProps: (other = {}) => _extends({
|
|
@@ -324,6 +325,7 @@ export const useGridColumnHeaders = props => {
|
|
|
324
325
|
getInnerProps: () => ({
|
|
325
326
|
ref: handleInnerRef,
|
|
326
327
|
role: 'rowgroup'
|
|
327
|
-
})
|
|
328
|
+
}),
|
|
329
|
+
headerHeight
|
|
328
330
|
};
|
|
329
331
|
};
|
|
@@ -153,8 +153,8 @@ export function useGridDimensions(apiRef, props) {
|
|
|
153
153
|
if (!mainEl) {
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
|
-
const height = mainEl.
|
|
157
|
-
const width = mainEl.
|
|
156
|
+
const height = mainEl.clientHeight || 0;
|
|
157
|
+
const width = mainEl.clientWidth || 0;
|
|
158
158
|
const win = ownerWindow(mainEl);
|
|
159
159
|
const computedStyle = win.getComputedStyle(mainEl);
|
|
160
160
|
const paddingLeft = parseInt(computedStyle.paddingLeft, 10) || 0;
|
|
@@ -29,9 +29,6 @@ export const useGridEditing = (apiRef, props) => {
|
|
|
29
29
|
if (isCellEditableProp) {
|
|
30
30
|
return isCellEditableProp(params);
|
|
31
31
|
}
|
|
32
|
-
if (params.rowNode.type === 'pinnedRow') {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
32
|
return true;
|
|
36
33
|
}, [isCellEditableProp]);
|
|
37
34
|
const maybeDebounce = (id, field, debounceMs, callback) => {
|
|
@@ -3,11 +3,17 @@ export const gridFocusStateSelector = state => state.focus;
|
|
|
3
3
|
export const gridFocusCellSelector = createSelector(gridFocusStateSelector, focusState => focusState.cell);
|
|
4
4
|
export const gridFocusColumnHeaderSelector = createSelector(gridFocusStateSelector, focusState => focusState.columnHeader);
|
|
5
5
|
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const unstable_gridFocusColumnHeaderFilterSelector = createSelector(gridFocusStateSelector, focusState => focusState.columnHeaderFilter);
|
|
8
|
+
|
|
6
9
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
10
|
export const unstable_gridFocusColumnGroupHeaderSelector = createSelector(gridFocusStateSelector, focusState => focusState.columnGroupHeader);
|
|
8
11
|
export const gridTabIndexStateSelector = state => state.tabIndex;
|
|
9
12
|
export const gridTabIndexCellSelector = createSelector(gridTabIndexStateSelector, state => state.cell);
|
|
10
13
|
export const gridTabIndexColumnHeaderSelector = createSelector(gridTabIndexStateSelector, state => state.columnHeader);
|
|
11
14
|
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
16
|
+
export const unstable_gridTabIndexColumnHeaderFilterSelector = createSelector(gridTabIndexStateSelector, state => state.columnHeaderFilter);
|
|
17
|
+
|
|
12
18
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
19
|
export const unstable_gridTabIndexColumnGroupHeaderSelector = createSelector(gridTabIndexStateSelector, state => state.columnGroupHeader);
|
|
@@ -9,15 +9,18 @@ import { gridFocusCellSelector, unstable_gridFocusColumnGroupHeaderSelector } fr
|
|
|
9
9
|
import { gridVisibleColumnDefinitionsSelector } from '../columns/gridColumnsSelector';
|
|
10
10
|
import { getVisibleRows } from '../../utils/useGridVisibleRows';
|
|
11
11
|
import { clamp } from '../../../utils/utils';
|
|
12
|
+
import { gridPinnedRowsSelector } from '../rows/gridRowsSelector';
|
|
12
13
|
export const focusStateInitializer = state => _extends({}, state, {
|
|
13
14
|
focus: {
|
|
14
15
|
cell: null,
|
|
15
16
|
columnHeader: null,
|
|
17
|
+
columnHeaderFilter: null,
|
|
16
18
|
columnGroupHeader: null
|
|
17
19
|
},
|
|
18
20
|
tabIndex: {
|
|
19
21
|
cell: null,
|
|
20
22
|
columnHeader: null,
|
|
23
|
+
columnHeaderFilter: null,
|
|
21
24
|
columnGroupHeader: null
|
|
22
25
|
}
|
|
23
26
|
});
|
|
@@ -52,6 +55,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
52
55
|
field
|
|
53
56
|
},
|
|
54
57
|
columnHeader: null,
|
|
58
|
+
columnHeaderFilter: null,
|
|
55
59
|
columnGroupHeader: null
|
|
56
60
|
},
|
|
57
61
|
focus: {
|
|
@@ -60,6 +64,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
60
64
|
field
|
|
61
65
|
},
|
|
62
66
|
columnHeader: null,
|
|
67
|
+
columnHeaderFilter: null,
|
|
63
68
|
columnGroupHeader: null
|
|
64
69
|
}
|
|
65
70
|
});
|
|
@@ -87,6 +92,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
87
92
|
columnHeader: {
|
|
88
93
|
field
|
|
89
94
|
},
|
|
95
|
+
columnHeaderFilter: null,
|
|
90
96
|
cell: null,
|
|
91
97
|
columnGroupHeader: null
|
|
92
98
|
},
|
|
@@ -94,6 +100,33 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
94
100
|
columnHeader: {
|
|
95
101
|
field
|
|
96
102
|
},
|
|
103
|
+
columnHeaderFilter: null,
|
|
104
|
+
cell: null,
|
|
105
|
+
columnGroupHeader: null
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
apiRef.current.forceUpdate();
|
|
110
|
+
}, [apiRef, logger, publishCellFocusOut]);
|
|
111
|
+
const setColumnHeaderFilterFocus = React.useCallback((field, event = {}) => {
|
|
112
|
+
const cell = gridFocusCellSelector(apiRef);
|
|
113
|
+
publishCellFocusOut(cell, event);
|
|
114
|
+
apiRef.current.setState(state => {
|
|
115
|
+
logger.debug(`Focusing on column header filter with colIndex=${field}`);
|
|
116
|
+
return _extends({}, state, {
|
|
117
|
+
tabIndex: {
|
|
118
|
+
columnHeader: null,
|
|
119
|
+
columnHeaderFilter: {
|
|
120
|
+
field
|
|
121
|
+
},
|
|
122
|
+
cell: null,
|
|
123
|
+
columnGroupHeader: null
|
|
124
|
+
},
|
|
125
|
+
focus: {
|
|
126
|
+
columnHeader: null,
|
|
127
|
+
columnHeaderFilter: {
|
|
128
|
+
field
|
|
129
|
+
},
|
|
97
130
|
cell: null,
|
|
98
131
|
columnGroupHeader: null
|
|
99
132
|
}
|
|
@@ -114,6 +147,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
114
147
|
depth
|
|
115
148
|
},
|
|
116
149
|
columnHeader: null,
|
|
150
|
+
columnHeaderFilter: null,
|
|
117
151
|
cell: null
|
|
118
152
|
},
|
|
119
153
|
focus: {
|
|
@@ -122,6 +156,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
122
156
|
depth
|
|
123
157
|
},
|
|
124
158
|
columnHeader: null,
|
|
159
|
+
columnHeaderFilter: null,
|
|
125
160
|
cell: null
|
|
126
161
|
}
|
|
127
162
|
});
|
|
@@ -131,8 +166,16 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
131
166
|
const getColumnGroupHeaderFocus = React.useCallback(() => unstable_gridFocusColumnGroupHeaderSelector(apiRef), [apiRef]);
|
|
132
167
|
const moveFocusToRelativeCell = React.useCallback((id, field, direction) => {
|
|
133
168
|
let columnIndexToFocus = apiRef.current.getColumnIndex(field);
|
|
134
|
-
let rowIndexToFocus = apiRef.current.getRowIndexRelativeToVisibleRows(id);
|
|
135
169
|
const visibleColumns = gridVisibleColumnDefinitionsSelector(apiRef);
|
|
170
|
+
const currentPage = getVisibleRows(apiRef, {
|
|
171
|
+
pagination: props.pagination,
|
|
172
|
+
paginationMode: props.paginationMode
|
|
173
|
+
});
|
|
174
|
+
const pinnedRows = gridPinnedRowsSelector(apiRef);
|
|
175
|
+
|
|
176
|
+
// Include pinned rows as well
|
|
177
|
+
const currentPageRows = [].concat(pinnedRows.top || [], currentPage.rows, pinnedRows.bottom || []);
|
|
178
|
+
let rowIndexToFocus = currentPageRows.findIndex(row => row.id === id);
|
|
136
179
|
if (direction === 'right') {
|
|
137
180
|
columnIndexToFocus += 1;
|
|
138
181
|
} else if (direction === 'left') {
|
|
@@ -140,14 +183,10 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
140
183
|
} else {
|
|
141
184
|
rowIndexToFocus += 1;
|
|
142
185
|
}
|
|
143
|
-
const currentPage = getVisibleRows(apiRef, {
|
|
144
|
-
pagination: props.pagination,
|
|
145
|
-
paginationMode: props.paginationMode
|
|
146
|
-
});
|
|
147
186
|
if (columnIndexToFocus >= visibleColumns.length) {
|
|
148
187
|
// Go to next row if we are after the last column
|
|
149
188
|
rowIndexToFocus += 1;
|
|
150
|
-
if (rowIndexToFocus <
|
|
189
|
+
if (rowIndexToFocus < currentPageRows.length) {
|
|
151
190
|
// Go to first column of the next row if there's one more row
|
|
152
191
|
columnIndexToFocus = 0;
|
|
153
192
|
}
|
|
@@ -159,8 +198,11 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
159
198
|
columnIndexToFocus = visibleColumns.length - 1;
|
|
160
199
|
}
|
|
161
200
|
}
|
|
162
|
-
rowIndexToFocus = clamp(rowIndexToFocus, 0,
|
|
163
|
-
const rowToFocus =
|
|
201
|
+
rowIndexToFocus = clamp(rowIndexToFocus, 0, currentPageRows.length - 1);
|
|
202
|
+
const rowToFocus = currentPageRows[rowIndexToFocus];
|
|
203
|
+
if (!rowToFocus) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
164
206
|
const colSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowToFocus.id, columnIndexToFocus);
|
|
165
207
|
if (colSpanInfo && colSpanInfo.spannedByColSpan) {
|
|
166
208
|
if (direction === 'left' || direction === 'below') {
|
|
@@ -214,6 +256,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
214
256
|
focus: {
|
|
215
257
|
cell: null,
|
|
216
258
|
columnHeader: null,
|
|
259
|
+
columnHeaderFilter: null,
|
|
217
260
|
columnGroupHeader: null
|
|
218
261
|
}
|
|
219
262
|
}));
|
|
@@ -252,6 +295,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
252
295
|
focus: {
|
|
253
296
|
cell: null,
|
|
254
297
|
columnHeader: null,
|
|
298
|
+
columnHeaderFilter: null,
|
|
255
299
|
columnGroupHeader: null
|
|
256
300
|
}
|
|
257
301
|
}));
|
|
@@ -280,6 +324,7 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
280
324
|
focus: {
|
|
281
325
|
cell: null,
|
|
282
326
|
columnHeader: null,
|
|
327
|
+
columnHeaderFilter: null,
|
|
283
328
|
columnGroupHeader: null
|
|
284
329
|
}
|
|
285
330
|
}));
|
|
@@ -287,7 +332,8 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
287
332
|
}, [apiRef]);
|
|
288
333
|
const focusApi = {
|
|
289
334
|
setCellFocus,
|
|
290
|
-
setColumnHeaderFocus
|
|
335
|
+
setColumnHeaderFocus,
|
|
336
|
+
setColumnHeaderFilterFocus
|
|
291
337
|
};
|
|
292
338
|
const focusPrivateApi = {
|
|
293
339
|
moveFocusToRelativeCell,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import { createSelector } from '../../../utils/createSelector';
|
|
3
|
+
export const unstable_gridHeaderFilteringStateSelector = state => state.headerFiltering;
|
|
4
|
+
export const unstable_gridHeaderFilteringEditFieldSelector = createSelector(unstable_gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.editing);
|
|
5
|
+
export const unstable_gridHeaderFilteringMenuSelector = createSelector(unstable_gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.menuOpen);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './gridHeaderFilteringSelectors';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
|
+
import { useGridLogger } from '../../utils';
|
|
5
|
+
import { gridColumnLookupSelector, gridColumnVisibilityModelSelector, gridColumnFieldsSelector } from '../columns/gridColumnsSelector';
|
|
6
|
+
export const headerFilteringStateInitializer = state => _extends({}, state, {
|
|
7
|
+
headerFiltering: {
|
|
8
|
+
editing: null,
|
|
9
|
+
menuOpen: null
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
export const useGridHeaderFiltering = (apiRef, props) => {
|
|
13
|
+
const logger = useGridLogger(apiRef, 'useGridHeaderFiltering');
|
|
14
|
+
const setHeaderFilterState = React.useCallback(headerFilterState => {
|
|
15
|
+
apiRef.current.setState(state => {
|
|
16
|
+
// Safety check to avoid MIT users from using it
|
|
17
|
+
// This hook should ultimately be moved to the Pro package
|
|
18
|
+
if (props.signature === 'DataGrid') {
|
|
19
|
+
return state;
|
|
20
|
+
}
|
|
21
|
+
return _extends({}, state, {
|
|
22
|
+
headerFiltering: {
|
|
23
|
+
editing: headerFilterState.editing ?? null,
|
|
24
|
+
menuOpen: headerFilterState.menuOpen ?? null
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
apiRef.current.forceUpdate();
|
|
29
|
+
}, [apiRef, props.signature]);
|
|
30
|
+
const startHeaderFilterEditMode = React.useCallback(field => {
|
|
31
|
+
logger.debug(`Starting edit mode on header filter for field: ${field}`);
|
|
32
|
+
apiRef.current.setHeaderFilterState({
|
|
33
|
+
editing: field
|
|
34
|
+
});
|
|
35
|
+
}, [apiRef, logger]);
|
|
36
|
+
const stopHeaderFilterEditMode = React.useCallback(() => {
|
|
37
|
+
logger.debug(`Stopping edit mode on header filter`);
|
|
38
|
+
apiRef.current.setHeaderFilterState({
|
|
39
|
+
editing: null
|
|
40
|
+
});
|
|
41
|
+
}, [apiRef, logger]);
|
|
42
|
+
const showHeaderFilterMenu = React.useCallback(field => {
|
|
43
|
+
logger.debug(`Opening header filter menu for field: ${field}`);
|
|
44
|
+
apiRef.current.setHeaderFilterState({
|
|
45
|
+
menuOpen: field
|
|
46
|
+
});
|
|
47
|
+
}, [apiRef, logger]);
|
|
48
|
+
const hideHeaderFilterMenu = React.useCallback(() => {
|
|
49
|
+
logger.debug(`Hiding header filter menu for active field`);
|
|
50
|
+
let fieldToFocus = apiRef.current.state.headerFiltering.menuOpen;
|
|
51
|
+
if (fieldToFocus) {
|
|
52
|
+
const columnLookup = gridColumnLookupSelector(apiRef);
|
|
53
|
+
const columnVisibilityModel = gridColumnVisibilityModelSelector(apiRef);
|
|
54
|
+
const orderedFields = gridColumnFieldsSelector(apiRef);
|
|
55
|
+
|
|
56
|
+
// If the column was removed from the grid, we need to find the closest visible field
|
|
57
|
+
if (!columnLookup[fieldToFocus]) {
|
|
58
|
+
fieldToFocus = orderedFields[0];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// If the field to focus is hidden, we need to find the closest visible field
|
|
62
|
+
if (columnVisibilityModel[fieldToFocus] === false) {
|
|
63
|
+
// contains visible column fields + the field that was just hidden
|
|
64
|
+
const visibleOrderedFields = orderedFields.filter(field => {
|
|
65
|
+
if (field === fieldToFocus) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return columnVisibilityModel[field] !== false;
|
|
69
|
+
});
|
|
70
|
+
const fieldIndex = visibleOrderedFields.indexOf(fieldToFocus);
|
|
71
|
+
fieldToFocus = visibleOrderedFields[fieldIndex + 1] || visibleOrderedFields[fieldIndex - 1];
|
|
72
|
+
}
|
|
73
|
+
apiRef.current.setHeaderFilterState({
|
|
74
|
+
menuOpen: null
|
|
75
|
+
});
|
|
76
|
+
apiRef.current.setColumnHeaderFilterFocus(fieldToFocus);
|
|
77
|
+
}
|
|
78
|
+
}, [apiRef, logger]);
|
|
79
|
+
const headerFilterPrivateApi = {
|
|
80
|
+
setHeaderFilterState
|
|
81
|
+
};
|
|
82
|
+
const headerFilterApi = {
|
|
83
|
+
startHeaderFilterEditMode,
|
|
84
|
+
stopHeaderFilterEditMode,
|
|
85
|
+
showHeaderFilterMenu,
|
|
86
|
+
hideHeaderFilterMenu
|
|
87
|
+
};
|
|
88
|
+
useGridApiMethod(apiRef, headerFilterApi, 'public');
|
|
89
|
+
useGridApiMethod(apiRef, headerFilterPrivateApi, 'private');
|
|
90
|
+
};
|