@mui/x-data-grid 6.11.1 → 6.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +154 -31
- package/DataGrid/DataGrid.d.ts +10 -0
- package/DataGrid/DataGrid.js +24 -1
- package/DataGrid/useDataGridProps.js +2 -0
- package/README.md +1 -1
- package/components/cell/GridActionsCell.js +1 -1
- package/components/cell/GridEditSingleSelectCell.js +1 -1
- package/components/columnHeaders/GridColumnGroupHeader.js +1 -1
- package/components/columnHeaders/GridColumnHeaderItem.js +1 -1
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +1 -1
- package/components/columnSelection/GridCellCheckboxRenderer.js +1 -1
- package/components/panel/GridPanel.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterForm.js +1 -1
- package/components/panel/filterPanel/GridFilterInputDate.d.ts +0 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +5 -11
- package/components/panel/filterPanel/GridFilterInputValue.d.ts +0 -1
- package/components/panel/filterPanel/GridFilterInputValue.js +16 -18
- package/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/components/toolbar/GridToolbarColumnsButton.js +1 -1
- package/components/toolbar/GridToolbarDensitySelector.js +1 -1
- package/components/toolbar/GridToolbarExport.js +2 -2
- package/components/toolbar/GridToolbarExportContainer.js +1 -1
- package/components/toolbar/GridToolbarFilterButton.js +1 -1
- package/components/toolbar/GridToolbarQuickFilter.d.ts +1 -1
- package/components/toolbar/GridToolbarQuickFilter.js +5 -5
- package/hooks/features/export/useGridPrintExport.js +11 -8
- package/hooks/features/export/utils.js +7 -1
- package/hooks/features/filter/gridFilterUtils.d.ts +2 -2
- package/hooks/features/filter/gridFilterUtils.js +23 -19
- package/hooks/features/filter/useGridFilter.d.ts +1 -1
- package/hooks/features/filter/useGridFilter.js +2 -2
- package/hooks/features/pagination/useGridPagination.d.ts +5 -0
- package/hooks/features/pagination/useGridPagination.js +1 -1
- package/hooks/features/rowSelection/useGridRowSelection.js +1 -1
- package/hooks/features/rows/useGridRows.js +11 -0
- package/hooks/features/rows/useGridRowsMeta.js +2 -2
- package/hooks/utils/useGridApiEventHandler.js +5 -5
- package/hooks/utils/useLazyRef.js +2 -0
- package/hooks/utils/useTimeout.d.ts +9 -0
- package/hooks/utils/useTimeout.js +28 -0
- package/index.js +1 -1
- package/joy/joySlots.js +2 -2
- package/legacy/DataGrid/DataGrid.js +24 -1
- package/legacy/DataGrid/useDataGridProps.js +2 -0
- package/legacy/components/cell/GridActionsCell.js +1 -1
- package/legacy/components/cell/GridEditSingleSelectCell.js +1 -1
- package/legacy/components/columnHeaders/GridColumnGroupHeader.js +1 -1
- package/legacy/components/columnHeaders/GridColumnHeaderItem.js +1 -1
- package/legacy/components/columnHeaders/GridGenericColumnHeaderItem.js +1 -1
- package/legacy/components/columnSelection/GridCellCheckboxRenderer.js +1 -1
- package/legacy/components/panel/filterPanel/GridFilterForm.js +1 -1
- package/legacy/components/panel/filterPanel/GridFilterInputDate.js +5 -11
- package/legacy/components/panel/filterPanel/GridFilterInputValue.js +16 -18
- package/legacy/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/legacy/components/toolbar/GridToolbarColumnsButton.js +1 -1
- package/legacy/components/toolbar/GridToolbarDensitySelector.js +1 -1
- package/legacy/components/toolbar/GridToolbarExport.js +2 -2
- package/legacy/components/toolbar/GridToolbarExportContainer.js +1 -1
- package/legacy/components/toolbar/GridToolbarFilterButton.js +1 -1
- package/legacy/components/toolbar/GridToolbarQuickFilter.js +5 -5
- package/legacy/hooks/features/export/useGridPrintExport.js +12 -9
- package/legacy/hooks/features/export/utils.js +8 -6
- package/legacy/hooks/features/filter/gridFilterUtils.js +23 -19
- package/legacy/hooks/features/filter/useGridFilter.js +2 -2
- package/legacy/hooks/features/pagination/useGridPagination.js +1 -1
- package/legacy/hooks/features/rowSelection/useGridRowSelection.js +1 -1
- package/legacy/hooks/features/rows/useGridRows.js +11 -0
- package/legacy/hooks/features/rows/useGridRowsMeta.js +2 -2
- package/legacy/hooks/utils/useGridApiEventHandler.js +5 -5
- package/legacy/hooks/utils/useLazyRef.js +2 -0
- package/legacy/hooks/utils/useTimeout.js +38 -0
- package/legacy/index.js +1 -1
- package/legacy/joy/joySlots.js +2 -2
- package/legacy/locales/esES.js +26 -28
- package/legacy/locales/ukUA.js +25 -27
- package/legacy/locales/zhCN.js +25 -27
- package/legacy/locales/zhTW.js +34 -38
- package/legacy/utils/createSelector.js +1 -1
- package/locales/esES.js +26 -28
- package/locales/ukUA.js +25 -27
- package/locales/zhCN.js +25 -27
- package/locales/zhTW.js +34 -38
- package/models/api/gridRowApi.d.ts +6 -0
- package/models/props/DataGridProps.d.ts +11 -0
- package/modern/DataGrid/DataGrid.js +24 -1
- package/modern/DataGrid/useDataGridProps.js +2 -0
- package/modern/components/panel/filterPanel/GridFilterInputDate.js +5 -11
- package/modern/components/panel/filterPanel/GridFilterInputValue.js +15 -17
- package/modern/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/modern/components/toolbar/GridToolbarQuickFilter.js +5 -5
- package/modern/hooks/features/export/useGridPrintExport.js +9 -6
- package/modern/hooks/features/export/utils.js +7 -1
- package/modern/hooks/features/filter/gridFilterUtils.js +23 -19
- package/modern/hooks/features/filter/useGridFilter.js +2 -2
- package/modern/hooks/features/pagination/useGridPagination.js +1 -1
- package/modern/hooks/features/rows/useGridRows.js +11 -0
- package/modern/hooks/utils/useLazyRef.js +2 -0
- package/modern/hooks/utils/useTimeout.js +28 -0
- package/modern/index.js +1 -1
- package/modern/locales/esES.js +26 -28
- package/modern/locales/ukUA.js +25 -27
- package/modern/locales/zhCN.js +25 -27
- package/modern/locales/zhTW.js +34 -38
- package/node/DataGrid/DataGrid.js +26 -1
- package/node/DataGrid/useDataGridProps.js +2 -0
- package/node/components/panel/filterPanel/GridFilterInputDate.js +5 -13
- package/node/components/panel/filterPanel/GridFilterInputValue.js +15 -19
- package/node/components/panel/filterPanel/GridFilterPanel.js +1 -3
- package/node/components/toolbar/GridToolbarQuickFilter.js +5 -5
- package/node/hooks/features/export/useGridPrintExport.js +9 -6
- package/node/hooks/features/export/utils.js +7 -1
- package/node/hooks/features/filter/gridFilterUtils.js +23 -19
- package/node/hooks/features/filter/useGridFilter.js +2 -2
- package/node/hooks/features/pagination/useGridPagination.js +2 -1
- package/node/hooks/features/rows/useGridRows.js +11 -0
- package/node/hooks/utils/useLazyRef.js +2 -0
- package/node/hooks/utils/useTimeout.js +34 -0
- package/node/index.js +1 -1
- package/node/locales/esES.js +26 -28
- package/node/locales/ukUA.js +25 -27
- package/node/locales/zhCN.js +25 -27
- package/node/locales/zhTW.js +34 -38
- package/package.json +3 -3
- package/utils/createSelector.js +1 -1
|
@@ -4,9 +4,9 @@ const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "t
|
|
|
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 { useTimeout } from '../../../hooks/utils/useTimeout';
|
|
7
8
|
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
export const SUBMIT_FILTER_STROKE_TIME = 500;
|
|
10
10
|
function GridFilterInputValue(props) {
|
|
11
11
|
var _item$value, _rootProps$slotProps;
|
|
12
12
|
const {
|
|
@@ -21,7 +21,7 @@ function GridFilterInputValue(props) {
|
|
|
21
21
|
InputProps
|
|
22
22
|
} = props,
|
|
23
23
|
others = _objectWithoutPropertiesLoose(props, _excluded);
|
|
24
|
-
const filterTimeout =
|
|
24
|
+
const filterTimeout = useTimeout();
|
|
25
25
|
const [filterValueState, setFilterValueState] = React.useState((_item$value = item.value) != null ? _item$value : '');
|
|
26
26
|
const [applying, setIsApplying] = React.useState(false);
|
|
27
27
|
const id = useId();
|
|
@@ -30,26 +30,24 @@ function GridFilterInputValue(props) {
|
|
|
30
30
|
const {
|
|
31
31
|
value
|
|
32
32
|
} = event.target;
|
|
33
|
-
clearTimeout(filterTimeout.current);
|
|
34
33
|
setFilterValueState(String(value));
|
|
35
34
|
setIsApplying(true);
|
|
36
|
-
filterTimeout.
|
|
37
|
-
|
|
38
|
-
value
|
|
39
|
-
|
|
35
|
+
filterTimeout.start(rootProps.filterDebounceMs, () => {
|
|
36
|
+
const newItem = _extends({}, item, {
|
|
37
|
+
value,
|
|
38
|
+
fromInput: id
|
|
39
|
+
});
|
|
40
|
+
applyValue(newItem);
|
|
40
41
|
setIsApplying(false);
|
|
41
|
-
}
|
|
42
|
-
}, [applyValue, item]);
|
|
42
|
+
});
|
|
43
|
+
}, [id, applyValue, item, rootProps.filterDebounceMs, filterTimeout]);
|
|
43
44
|
React.useEffect(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const itemValue = (_item$value2 = item.value) != null ? _item$value2 : '';
|
|
51
|
-
setFilterValueState(String(itemValue));
|
|
52
|
-
}, [item.value]);
|
|
45
|
+
const itemPlusTag = item;
|
|
46
|
+
if (itemPlusTag.fromInput !== id) {
|
|
47
|
+
var _item$value2;
|
|
48
|
+
setFilterValueState(String((_item$value2 = item.value) != null ? _item$value2 : ''));
|
|
49
|
+
}
|
|
50
|
+
}, [id, item]);
|
|
53
51
|
return /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
|
|
54
52
|
id: id,
|
|
55
53
|
label: apiRef.current.getLocaleText('filterPanelInputLabel'),
|
|
@@ -37,9 +37,7 @@ const GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(p
|
|
|
37
37
|
disableRemoveAllButton = false
|
|
38
38
|
} = props,
|
|
39
39
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
40
|
-
const applyFilter =
|
|
41
|
-
apiRef.current.upsertFilterItem(item);
|
|
42
|
-
}, [apiRef]);
|
|
40
|
+
const applyFilter = apiRef.current.upsertFilterItem;
|
|
43
41
|
const applyFilterLogicOperator = React.useCallback(operator => {
|
|
44
42
|
apiRef.current.setFilterLogicOperator(operator);
|
|
45
43
|
}, [apiRef]);
|
|
@@ -26,7 +26,7 @@ export const GridToolbarColumnsButton = /*#__PURE__*/React.forwardRef(function G
|
|
|
26
26
|
} else {
|
|
27
27
|
apiRef.current.showPreferences(GridPreferencePanelsValue.columns, columnPanelId, columnButtonId);
|
|
28
28
|
}
|
|
29
|
-
onClick == null
|
|
29
|
+
onClick == null || onClick(event);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
// Disable the button if the corresponding is disabled
|
|
@@ -54,7 +54,7 @@ export const GridToolbarDensitySelector = /*#__PURE__*/React.forwardRef(function
|
|
|
54
54
|
}, [densityValue, rootProps]);
|
|
55
55
|
const handleDensitySelectorOpen = event => {
|
|
56
56
|
setOpen(prevOpen => !prevOpen);
|
|
57
|
-
onClick == null
|
|
57
|
+
onClick == null || onClick(event);
|
|
58
58
|
};
|
|
59
59
|
const handleDensitySelectorClickAway = event => {
|
|
60
60
|
var _buttonRef$current;
|
|
@@ -19,7 +19,7 @@ export function GridCsvExportMenuItem(props) {
|
|
|
19
19
|
return /*#__PURE__*/_jsx(MenuItem, _extends({
|
|
20
20
|
onClick: () => {
|
|
21
21
|
apiRef.current.exportDataAsCsv(options);
|
|
22
|
-
hideMenu == null
|
|
22
|
+
hideMenu == null || hideMenu();
|
|
23
23
|
}
|
|
24
24
|
}, other, {
|
|
25
25
|
children: apiRef.current.getLocaleText('toolbarExportCSV')
|
|
@@ -35,7 +35,7 @@ export function GridPrintExportMenuItem(props) {
|
|
|
35
35
|
return /*#__PURE__*/_jsx(MenuItem, _extends({
|
|
36
36
|
onClick: () => {
|
|
37
37
|
apiRef.current.exportDataAsPrint(options);
|
|
38
|
-
hideMenu == null
|
|
38
|
+
hideMenu == null || hideMenu();
|
|
39
39
|
}
|
|
40
40
|
}, other, {
|
|
41
41
|
children: apiRef.current.getLocaleText('toolbarExportPrint')
|
|
@@ -27,7 +27,7 @@ export const GridToolbarExportContainer = /*#__PURE__*/React.forwardRef(function
|
|
|
27
27
|
const handleRef = useForkRef(ref, buttonRef);
|
|
28
28
|
const handleMenuOpen = event => {
|
|
29
29
|
setOpen(prevOpen => !prevOpen);
|
|
30
|
-
onClick == null
|
|
30
|
+
onClick == null || onClick(event);
|
|
31
31
|
};
|
|
32
32
|
const handleMenuClose = () => setOpen(false);
|
|
33
33
|
const handleListKeyDown = event => {
|
|
@@ -89,7 +89,7 @@ const GridToolbarFilterButton = /*#__PURE__*/React.forwardRef(function GridToolb
|
|
|
89
89
|
} else {
|
|
90
90
|
apiRef.current.showPreferences(GridPreferencePanelsValue.filters, filterPanelId, filterButtonId);
|
|
91
91
|
}
|
|
92
|
-
(_buttonProps$onClick = buttonProps.onClick) == null
|
|
92
|
+
(_buttonProps$onClick = buttonProps.onClick) == null || _buttonProps$onClick.call(buttonProps, event);
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
// Disable the button if the corresponding is disabled
|
|
@@ -16,7 +16,7 @@ export type GridToolbarQuickFilterProps = TextFieldProps & {
|
|
|
16
16
|
quickFilterFormatter?: (values: NonNullable<GridFilterModel['quickFilterValues']>) => string;
|
|
17
17
|
/**
|
|
18
18
|
* The debounce time in milliseconds.
|
|
19
|
-
* @default
|
|
19
|
+
* @default 150
|
|
20
20
|
*/
|
|
21
21
|
debounceMs?: number;
|
|
22
22
|
};
|
|
@@ -46,15 +46,15 @@ const defaultSearchValueParser = searchText => searchText.split(' ').filter(word
|
|
|
46
46
|
const defaultSearchValueFormatter = values => values.join(' ');
|
|
47
47
|
function GridToolbarQuickFilter(props) {
|
|
48
48
|
var _rootProps$slotProps, _rootProps$slotProps2;
|
|
49
|
+
const apiRef = useGridApiContext();
|
|
50
|
+
const rootProps = useGridRootProps();
|
|
51
|
+
const quickFilterValues = useGridSelector(apiRef, gridQuickFilterValuesSelector);
|
|
49
52
|
const {
|
|
50
53
|
quickFilterParser = defaultSearchValueParser,
|
|
51
54
|
quickFilterFormatter = defaultSearchValueFormatter,
|
|
52
|
-
debounceMs =
|
|
55
|
+
debounceMs = rootProps.filterDebounceMs
|
|
53
56
|
} = props,
|
|
54
57
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
55
|
-
const apiRef = useGridApiContext();
|
|
56
|
-
const rootProps = useGridRootProps();
|
|
57
|
-
const quickFilterValues = useGridSelector(apiRef, gridQuickFilterValuesSelector);
|
|
58
58
|
const [searchValue, setSearchValue] = React.useState(() => quickFilterFormatter(quickFilterValues != null ? quickFilterValues : []));
|
|
59
59
|
const prevQuickFilterValuesRef = React.useRef(quickFilterValues);
|
|
60
60
|
React.useEffect(() => {
|
|
@@ -117,7 +117,7 @@ process.env.NODE_ENV !== "production" ? GridToolbarQuickFilter.propTypes = {
|
|
|
117
117
|
// ----------------------------------------------------------------------
|
|
118
118
|
/**
|
|
119
119
|
* The debounce time in milliseconds.
|
|
120
|
-
* @default
|
|
120
|
+
* @default 150
|
|
121
121
|
*/
|
|
122
122
|
debounceMs: PropTypes.number,
|
|
123
123
|
/**
|
|
@@ -8,6 +8,7 @@ import { gridClasses } from '../../../constants/gridClasses';
|
|
|
8
8
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
9
9
|
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
|
|
10
10
|
import { getColumnsToExport } from './utils';
|
|
11
|
+
import { mergeStateWithPaginationModel } from '../pagination/useGridPagination';
|
|
11
12
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
12
13
|
import { GridPrintExportMenuItem } from '../../../components/toolbar/GridToolbarExport';
|
|
13
14
|
import { getTotalHeaderHeight } from '../columns/gridColumnsUtils';
|
|
@@ -46,11 +47,6 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
46
47
|
// Returns a promise because updateColumns triggers state update and
|
|
47
48
|
// the new state needs to be in place before the grid can be sized correctly
|
|
48
49
|
const updateGridColumnsForPrint = React.useCallback((fields, allColumns) => new Promise(resolve => {
|
|
49
|
-
// TODO remove unused Promise
|
|
50
|
-
if (!fields && !allColumns) {
|
|
51
|
-
resolve();
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
50
|
const exportedColumnFields = getColumnsToExport({
|
|
55
51
|
apiRef,
|
|
56
52
|
options: {
|
|
@@ -94,12 +90,12 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
94
90
|
let gridFooterElementHeight = ((_querySelector2 = gridRootElement.querySelector(`.${gridClasses.footerContainer}`)) == null ? void 0 : _querySelector2.offsetHeight) || 0;
|
|
95
91
|
if (normalizeOptions.hideToolbar) {
|
|
96
92
|
var _gridClone$querySelec;
|
|
97
|
-
(_gridClone$querySelec = gridClone.querySelector(`.${gridClasses.toolbarContainer}`)) == null
|
|
93
|
+
(_gridClone$querySelec = gridClone.querySelector(`.${gridClasses.toolbarContainer}`)) == null || _gridClone$querySelec.remove();
|
|
98
94
|
gridToolbarElementHeight = 0;
|
|
99
95
|
}
|
|
100
96
|
if (normalizeOptions.hideFooter) {
|
|
101
97
|
var _gridClone$querySelec2;
|
|
102
|
-
(_gridClone$querySelec2 = gridClone.querySelector(`.${gridClasses.footerContainer}`)) == null
|
|
98
|
+
(_gridClone$querySelec2 = gridClone.querySelector(`.${gridClasses.footerContainer}`)) == null || _gridClone$querySelec2.remove();
|
|
103
99
|
gridFooterElementHeight = 0;
|
|
104
100
|
}
|
|
105
101
|
|
|
@@ -197,7 +193,14 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
197
193
|
previousColumnVisibility.current = gridColumnVisibilityModelSelector(apiRef);
|
|
198
194
|
if (props.pagination) {
|
|
199
195
|
const visibleRowCount = gridExpandedRowCountSelector(apiRef);
|
|
200
|
-
|
|
196
|
+
const paginationModel = {
|
|
197
|
+
page: 0,
|
|
198
|
+
pageSize: visibleRowCount
|
|
199
|
+
};
|
|
200
|
+
apiRef.current.updateControlState('pagination',
|
|
201
|
+
// Using signature `DataGridPro` to allow more than 100 rows in the print export
|
|
202
|
+
mergeStateWithPaginationModel(visibleRowCount, 'DataGridPro', paginationModel));
|
|
203
|
+
apiRef.current.forceUpdate();
|
|
201
204
|
}
|
|
202
205
|
await updateGridColumnsForPrint(options == null ? void 0 : options.fields, options == null ? void 0 : options.allColumns);
|
|
203
206
|
apiRef.current.unstable_disableVirtualization();
|
|
@@ -7,7 +7,13 @@ export const getColumnsToExport = ({
|
|
|
7
7
|
}) => {
|
|
8
8
|
const columns = gridColumnDefinitionsSelector(apiRef);
|
|
9
9
|
if (options.fields) {
|
|
10
|
-
return options.fields.
|
|
10
|
+
return options.fields.reduce((currentColumns, field) => {
|
|
11
|
+
const column = columns.find(col => col.field === field);
|
|
12
|
+
if (column) {
|
|
13
|
+
currentColumns.push(column);
|
|
14
|
+
}
|
|
15
|
+
return currentColumns;
|
|
16
|
+
}, []);
|
|
11
17
|
}
|
|
12
18
|
const validColumns = options.allColumns ? columns : gridVisibleColumnDefinitionsSelector(apiRef);
|
|
13
19
|
return validColumns.filter(column => !column.disableExport);
|
|
@@ -21,7 +21,7 @@ export declare const mergeStateWithFilterModel: (filterModel: GridFilterModel, d
|
|
|
21
21
|
* @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
22
22
|
* @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.
|
|
23
23
|
*/
|
|
24
|
-
export declare const buildAggregatedFilterItemsApplier: (getRowId: GridRowIdGetter | undefined, filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity
|
|
24
|
+
export declare const buildAggregatedFilterItemsApplier: (getRowId: GridRowIdGetter | undefined, filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity>, disableEval: boolean) => GridFilterItemApplierNotAggregated | null;
|
|
25
25
|
/**
|
|
26
26
|
* Generates a method to easily check if a row is matching the current quick filter.
|
|
27
27
|
* @param {GridRowIdGetter | undefined} getRowId The getter for row's id.
|
|
@@ -30,7 +30,7 @@ export declare const buildAggregatedFilterItemsApplier: (getRowId: GridRowIdGett
|
|
|
30
30
|
* @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.
|
|
31
31
|
*/
|
|
32
32
|
export declare const buildAggregatedQuickFilterApplier: (getRowId: GridRowIdGetter | undefined, filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity>) => GridFilterItemApplierNotAggregated | null;
|
|
33
|
-
export declare const buildAggregatedFilterApplier: (getRowId: GridRowIdGetter | undefined, filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity
|
|
33
|
+
export declare const buildAggregatedFilterApplier: (getRowId: GridRowIdGetter | undefined, filterModel: GridFilterModel, apiRef: React.MutableRefObject<GridApiCommunity>, disableEval: boolean) => GridAggregatedFilterItemApplier;
|
|
34
34
|
type FilterCache = {
|
|
35
35
|
cleanedFilterItems?: GridFilterItem[];
|
|
36
36
|
};
|
|
@@ -4,6 +4,13 @@ import { GLOBAL_API_REF, isInternalFilter } from '../../../colDef/utils';
|
|
|
4
4
|
import { getDefaultGridFilterModel } from './gridFilterState';
|
|
5
5
|
import { buildWarning } from '../../../utils/warning';
|
|
6
6
|
import { gridColumnFieldsSelector, gridColumnLookupSelector, gridVisibleColumnFieldsSelector } from '../columns';
|
|
7
|
+
let hasEval;
|
|
8
|
+
try {
|
|
9
|
+
// eslint-disable-next-line no-eval
|
|
10
|
+
hasEval = eval('true');
|
|
11
|
+
} catch (_) {
|
|
12
|
+
hasEval = false;
|
|
13
|
+
}
|
|
7
14
|
/**
|
|
8
15
|
* Adds default values to the optional fields of a filter items.
|
|
9
16
|
* @param {GridFilterItem} item The raw filter item.
|
|
@@ -127,7 +134,7 @@ let filterItemsApplierId = 1;
|
|
|
127
134
|
* @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
|
|
128
135
|
* @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.
|
|
129
136
|
*/
|
|
130
|
-
export const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef) => {
|
|
137
|
+
export const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disableEval) => {
|
|
131
138
|
const {
|
|
132
139
|
items
|
|
133
140
|
} = filterModel;
|
|
@@ -135,22 +142,19 @@ export const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef)
|
|
|
135
142
|
if (appliers.length === 0) {
|
|
136
143
|
return null;
|
|
137
144
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
//
|
|
152
|
-
// return resultPerItemId;
|
|
153
|
-
// };
|
|
145
|
+
if (!hasEval || disableEval) {
|
|
146
|
+
// This is the original logic, which is used if `eval()` is not supported (aka prevented by CSP).
|
|
147
|
+
return (row, shouldApplyFilter) => {
|
|
148
|
+
const resultPerItemId = {};
|
|
149
|
+
for (let i = 0; i < appliers.length; i += 1) {
|
|
150
|
+
const applier = appliers[i];
|
|
151
|
+
if (!shouldApplyFilter || shouldApplyFilter(applier.item.field)) {
|
|
152
|
+
resultPerItemId[applier.item.id] = applier.v7 ? applier.fn(row) : applier.fn(getRowId ? getRowId(row) : row.id);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return resultPerItemId;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
154
158
|
|
|
155
159
|
// We generate a new function with `eval()` to avoid expensive patterns for JS engines
|
|
156
160
|
// such as a dynamic object assignment, e.g. `{ [dynamicKey]: value }`.
|
|
@@ -260,8 +264,8 @@ export const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef)
|
|
|
260
264
|
return result;
|
|
261
265
|
};
|
|
262
266
|
};
|
|
263
|
-
export const buildAggregatedFilterApplier = (getRowId, filterModel, apiRef) => {
|
|
264
|
-
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(getRowId, filterModel, apiRef);
|
|
267
|
+
export const buildAggregatedFilterApplier = (getRowId, filterModel, apiRef, disableEval) => {
|
|
268
|
+
const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(getRowId, filterModel, apiRef, disableEval);
|
|
265
269
|
const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(getRowId, filterModel, apiRef);
|
|
266
270
|
return function isRowMatchingFilters(row, shouldApplyFilter, result) {
|
|
267
271
|
var _isRowMatchingFilterI, _isRowMatchingQuickFi;
|
|
@@ -8,4 +8,4 @@ export declare const filterStateInitializer: GridStateInitializer<Pick<DataGridP
|
|
|
8
8
|
* @requires useGridParamsApi (method)
|
|
9
9
|
* @requires useGridRows (event)
|
|
10
10
|
*/
|
|
11
|
-
export declare const useGridFilter: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, 'rows' | 'initialState' | 'filterModel' | 'getRowId' | 'onFilterModelChange' | 'filterMode' | 'disableMultipleColumnsFiltering' | 'slots' | 'slotProps' | 'disableColumnFilter'>) => void;
|
|
11
|
+
export declare const useGridFilter: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, 'rows' | 'initialState' | 'filterModel' | 'getRowId' | 'onFilterModelChange' | 'filterMode' | 'disableMultipleColumnsFiltering' | 'slots' | 'slotProps' | 'disableColumnFilter' | 'disableEval'>) => void;
|
|
@@ -61,7 +61,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
61
61
|
const updateFilteredRows = React.useCallback(() => {
|
|
62
62
|
apiRef.current.setState(state => {
|
|
63
63
|
const filterModel = gridFilterModelSelector(state, apiRef.current.instanceId);
|
|
64
|
-
const isRowMatchingFilters = props.filterMode === 'client' ? buildAggregatedFilterApplier(props.getRowId, filterModel, apiRef) : null;
|
|
64
|
+
const isRowMatchingFilters = props.filterMode === 'client' ? buildAggregatedFilterApplier(props.getRowId, filterModel, apiRef, props.disableEval) : null;
|
|
65
65
|
const filteringResult = apiRef.current.applyStrategyProcessor('filtering', {
|
|
66
66
|
isRowMatchingFilters,
|
|
67
67
|
filterModel: filterModel != null ? filterModel : getDefaultGridFilterModel()
|
|
@@ -75,7 +75,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
77
|
apiRef.current.publishEvent('filteredRowsSet');
|
|
78
|
-
}, [apiRef, props.filterMode, props.getRowId]);
|
|
78
|
+
}, [apiRef, props.filterMode, props.getRowId, props.disableEval]);
|
|
79
79
|
const addColumnMenuItem = React.useCallback((columnMenuItems, colDef) => {
|
|
80
80
|
if (colDef == null || colDef.filterable === false || props.disableColumnFilter) {
|
|
81
81
|
return columnMenuItems;
|
|
@@ -2,7 +2,12 @@ import * as React from 'react';
|
|
|
2
2
|
import { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
4
|
import { GridStateInitializer } from '../../utils/useGridInitializeState';
|
|
5
|
+
import { GridPaginationState } from './gridPaginationInterfaces';
|
|
6
|
+
import { GridPaginationModel } from '../../../models/gridPaginationProps';
|
|
5
7
|
export declare const paginationStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'paginationModel' | 'rowCount' | 'initialState' | 'autoPageSize' | 'signature'>>;
|
|
8
|
+
export declare const mergeStateWithPaginationModel: (rowCount: number, signature: DataGridProcessedProps['signature'], paginationModelProp?: GridPaginationModel) => (paginationState: GridPaginationState) => {
|
|
9
|
+
paginationModel: GridPaginationModel;
|
|
10
|
+
};
|
|
6
11
|
/**
|
|
7
12
|
* @requires useGridFilter (state)
|
|
8
13
|
* @requires useGridDimensions (event) - can be after
|
|
@@ -17,7 +17,7 @@ export const paginationStateInitializer = (state, props) => {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
|
-
const mergeStateWithPaginationModel = (rowCount, signature, paginationModelProp) => paginationState => {
|
|
20
|
+
export const mergeStateWithPaginationModel = (rowCount, signature, paginationModelProp) => paginationState => {
|
|
21
21
|
var _paginationModelProp$;
|
|
22
22
|
let paginationModel = paginationState.paginationModel;
|
|
23
23
|
const pageSize = (_paginationModelProp$ = paginationModelProp == null ? void 0 : paginationModelProp.pageSize) != null ? _paginationModelProp$ : paginationModel.pageSize;
|
|
@@ -266,7 +266,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
266
266
|
const preventSelectionOnShift = React.useCallback((params, event) => {
|
|
267
267
|
if (canHaveMultipleSelection && event.shiftKey) {
|
|
268
268
|
var _window$getSelection;
|
|
269
|
-
(_window$getSelection = window.getSelection()) == null
|
|
269
|
+
(_window$getSelection = window.getSelection()) == null || _window$getSelection.removeAllRanges();
|
|
270
270
|
}
|
|
271
271
|
}, [canHaveMultipleSelection]);
|
|
272
272
|
const handleRowSelectionCheckboxChange = React.useCallback((params, event) => {
|
|
@@ -52,6 +52,16 @@ export const useGridRows = (apiRef, props) => {
|
|
|
52
52
|
}
|
|
53
53
|
return null;
|
|
54
54
|
}, [apiRef]);
|
|
55
|
+
const getRowIdProp = props.getRowId;
|
|
56
|
+
const getRowId = React.useCallback(row => {
|
|
57
|
+
if (GRID_ID_AUTOGENERATED in row) {
|
|
58
|
+
return row[GRID_ID_AUTOGENERATED];
|
|
59
|
+
}
|
|
60
|
+
if (getRowIdProp) {
|
|
61
|
+
return getRowIdProp(row);
|
|
62
|
+
}
|
|
63
|
+
return row.id;
|
|
64
|
+
}, [getRowIdProp]);
|
|
55
65
|
const lookup = React.useMemo(() => currentPage.rows.reduce((acc, {
|
|
56
66
|
id
|
|
57
67
|
}, index) => {
|
|
@@ -297,6 +307,7 @@ export const useGridRows = (apiRef, props) => {
|
|
|
297
307
|
}, [apiRef, props.signature, props.getRowId]);
|
|
298
308
|
const rowApi = {
|
|
299
309
|
getRow,
|
|
310
|
+
getRowId,
|
|
300
311
|
getRowModels,
|
|
301
312
|
getRowsCount,
|
|
302
313
|
getAllRowIds,
|
|
@@ -145,10 +145,10 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
145
145
|
}
|
|
146
146
|
return acc + maximumBaseSize + otherSizes;
|
|
147
147
|
}, 0);
|
|
148
|
-
pinnedRows == null || (_pinnedRows$top = pinnedRows.top) == null
|
|
148
|
+
pinnedRows == null || (_pinnedRows$top = pinnedRows.top) == null || _pinnedRows$top.forEach(row => {
|
|
149
149
|
calculateRowProcessedSizes(row);
|
|
150
150
|
});
|
|
151
|
-
pinnedRows == null || (_pinnedRows$bottom = pinnedRows.bottom) == null
|
|
151
|
+
pinnedRows == null || (_pinnedRows$bottom = pinnedRows.bottom) == null || _pinnedRows$bottom.forEach(row => {
|
|
152
152
|
calculateRowProcessedSizes(row);
|
|
153
153
|
});
|
|
154
154
|
apiRef.current.setState(state => {
|
|
@@ -30,7 +30,7 @@ export function createUseGridApiEventHandler(registryContainer) {
|
|
|
30
30
|
const enhancedHandler = (params, event, details) => {
|
|
31
31
|
if (!event.defaultMuiPrevented) {
|
|
32
32
|
var _handlerRef$current;
|
|
33
|
-
(_handlerRef$current = handlerRef.current) == null
|
|
33
|
+
(_handlerRef$current = handlerRef.current) == null || _handlerRef$current.call(handlerRef, params, event, details);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
subscription.current = apiRef.current.subscribeEvent(eventName, enhancedHandler, options);
|
|
@@ -42,7 +42,7 @@ export function createUseGridApiEventHandler(registryContainer) {
|
|
|
42
42
|
// The callback below will be called once this reference stops being retained
|
|
43
43
|
() => {
|
|
44
44
|
var _subscription$current;
|
|
45
|
-
(_subscription$current = subscription.current) == null
|
|
45
|
+
(_subscription$current = subscription.current) == null || _subscription$current.call(subscription);
|
|
46
46
|
subscription.current = null;
|
|
47
47
|
cleanupTokenRef.current = null;
|
|
48
48
|
}, cleanupTokenRef.current);
|
|
@@ -59,7 +59,7 @@ export function createUseGridApiEventHandler(registryContainer) {
|
|
|
59
59
|
const enhancedHandler = (params, event, details) => {
|
|
60
60
|
if (!event.defaultMuiPrevented) {
|
|
61
61
|
var _handlerRef$current2;
|
|
62
|
-
(_handlerRef$current2 = handlerRef.current) == null
|
|
62
|
+
(_handlerRef$current2 = handlerRef.current) == null || _handlerRef$current2.call(handlerRef, params, event, details);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
subscription.current = apiRef.current.subscribeEvent(eventName, enhancedHandler, options);
|
|
@@ -72,7 +72,7 @@ export function createUseGridApiEventHandler(registryContainer) {
|
|
|
72
72
|
}
|
|
73
73
|
return () => {
|
|
74
74
|
var _subscription$current2;
|
|
75
|
-
(_subscription$current2 = subscription.current) == null
|
|
75
|
+
(_subscription$current2 = subscription.current) == null || _subscription$current2.call(subscription);
|
|
76
76
|
subscription.current = null;
|
|
77
77
|
};
|
|
78
78
|
}, [apiRef, eventName, options]);
|
|
@@ -86,7 +86,7 @@ const registryContainer = {
|
|
|
86
86
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
87
87
|
export const unstable_resetCleanupTracking = () => {
|
|
88
88
|
var _registryContainer$re;
|
|
89
|
-
(_registryContainer$re = registryContainer.registry) == null
|
|
89
|
+
(_registryContainer$re = registryContainer.registry) == null || _registryContainer$re.reset();
|
|
90
90
|
registryContainer.registry = null;
|
|
91
91
|
};
|
|
92
92
|
export const useGridApiEventHandler = createUseGridApiEventHandler(registryContainer);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useLazyRef } from './useLazyRef';
|
|
2
|
+
import { useOnMount } from './useOnMount';
|
|
3
|
+
class Timeout {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.currentId = 0;
|
|
6
|
+
this.clear = () => {
|
|
7
|
+
if (this.currentId !== 0) {
|
|
8
|
+
clearTimeout(this.currentId);
|
|
9
|
+
this.currentId = 0;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
this.disposeEffect = () => {
|
|
13
|
+
return this.clear;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
static create() {
|
|
17
|
+
return new Timeout();
|
|
18
|
+
}
|
|
19
|
+
start(delay, fn) {
|
|
20
|
+
this.clear();
|
|
21
|
+
this.currentId = setTimeout(fn, delay);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function useTimeout() {
|
|
25
|
+
const timeout = useLazyRef(Timeout.create).current;
|
|
26
|
+
useOnMount(timeout.disposeEffect);
|
|
27
|
+
return timeout;
|
|
28
|
+
}
|
package/index.js
CHANGED
package/joy/joySlots.js
CHANGED
|
@@ -231,10 +231,10 @@ const Select = /*#__PURE__*/React.forwardRef((_ref6, ref) => {
|
|
|
231
231
|
listboxOpen: open,
|
|
232
232
|
onListboxOpenChange: isOpen => {
|
|
233
233
|
if (isOpen) {
|
|
234
|
-
onOpen == null
|
|
234
|
+
onOpen == null || onOpen({});
|
|
235
235
|
} else {
|
|
236
236
|
var _MenuProps$onClose;
|
|
237
|
-
MenuProps == null || (_MenuProps$onClose = MenuProps.onClose) == null
|
|
237
|
+
MenuProps == null || (_MenuProps$onClose = MenuProps.onClose) == null || _MenuProps$onClose.call(MenuProps, {}, undefined);
|
|
238
238
|
}
|
|
239
239
|
},
|
|
240
240
|
size: convertSize(size),
|
|
@@ -5,7 +5,7 @@ import { chainPropTypes } from '@mui/utils';
|
|
|
5
5
|
import { GridBody, GridFooterPlaceholder, GridHeader, GridRoot } from '../components';
|
|
6
6
|
import { GridContextProvider } from '../context/GridContextProvider';
|
|
7
7
|
import { useDataGridComponent } from './useDataGridComponent';
|
|
8
|
-
import { useDataGridProps } from './useDataGridProps';
|
|
8
|
+
import { useDataGridProps, DATA_GRID_PROPS_DEFAULT_VALUES } from './useDataGridProps';
|
|
9
9
|
import { DataGridVirtualScroller } from '../components/DataGridVirtualScroller';
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -28,6 +28,18 @@ var DataGridRaw = /*#__PURE__*/React.forwardRef(function DataGrid(inProps, ref)
|
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
export var DataGrid = /*#__PURE__*/React.memo(DataGridRaw);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Remove at v7
|
|
34
|
+
* @deprecated
|
|
35
|
+
*/
|
|
36
|
+
export var SUBMIT_FILTER_STROKE_TIME = DATA_GRID_PROPS_DEFAULT_VALUES.filterDebounceMs;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Remove at v7
|
|
40
|
+
* @deprecated
|
|
41
|
+
*/
|
|
42
|
+
export var SUBMIT_FILTER_DATE_STROKE_TIME = DATA_GRID_PROPS_DEFAULT_VALUES.filterDebounceMs;
|
|
31
43
|
DataGridRaw.propTypes = {
|
|
32
44
|
// ----------------------------- Warning --------------------------------
|
|
33
45
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
@@ -143,6 +155,12 @@ DataGridRaw.propTypes = {
|
|
|
143
155
|
* @default false
|
|
144
156
|
*/
|
|
145
157
|
disableDensitySelector: PropTypes.bool,
|
|
158
|
+
/**
|
|
159
|
+
* If `true`, `eval()` is not used for performance optimization.
|
|
160
|
+
* @default false
|
|
161
|
+
* @ignore - do not document
|
|
162
|
+
*/
|
|
163
|
+
disableEval: PropTypes.bool,
|
|
146
164
|
/**
|
|
147
165
|
* If `true`, the selection on click on a row or cell is disabled.
|
|
148
166
|
* @default false
|
|
@@ -167,6 +185,11 @@ DataGridRaw.propTypes = {
|
|
|
167
185
|
columnGrouping: PropTypes.bool,
|
|
168
186
|
warnIfFocusStateIsNotSynced: PropTypes.bool
|
|
169
187
|
}),
|
|
188
|
+
/**
|
|
189
|
+
* The milliseconds delay to wait after a keystroke before triggering filtering.
|
|
190
|
+
* @default 150
|
|
191
|
+
*/
|
|
192
|
+
filterDebounceMs: PropTypes.number,
|
|
170
193
|
/**
|
|
171
194
|
* Filtering can be processed on the server or client-side.
|
|
172
195
|
* Set it to 'server' if you would like to handle filtering on the server-side.
|
|
@@ -38,6 +38,7 @@ export var DATA_GRID_PROPS_DEFAULT_VALUES = {
|
|
|
38
38
|
disableColumnMenu: false,
|
|
39
39
|
disableColumnSelector: false,
|
|
40
40
|
disableDensitySelector: false,
|
|
41
|
+
disableEval: false,
|
|
41
42
|
disableMultipleColumnsFiltering: false,
|
|
42
43
|
disableMultipleRowSelection: false,
|
|
43
44
|
disableMultipleColumnsSorting: false,
|
|
@@ -45,6 +46,7 @@ export var DATA_GRID_PROPS_DEFAULT_VALUES = {
|
|
|
45
46
|
disableVirtualization: false,
|
|
46
47
|
editMode: GridEditModes.Cell,
|
|
47
48
|
filterMode: 'client',
|
|
49
|
+
filterDebounceMs: 150,
|
|
48
50
|
columnHeaderHeight: 56,
|
|
49
51
|
hideFooter: false,
|
|
50
52
|
hideFooterPagination: false,
|
|
@@ -68,7 +68,7 @@ function GridActionsCell(props) {
|
|
|
68
68
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
69
69
|
index = _ref2[0],
|
|
70
70
|
ref = _ref2[1];
|
|
71
|
-
ref == null
|
|
71
|
+
ref == null || ref.stop({}, function () {
|
|
72
72
|
delete touchRippleRefs.current[index];
|
|
73
73
|
});
|
|
74
74
|
});
|
|
@@ -59,7 +59,7 @@ function GridEditSingleSelectCell(props) {
|
|
|
59
59
|
useEnhancedEffect(function () {
|
|
60
60
|
if (hasFocus) {
|
|
61
61
|
var _inputRef$current;
|
|
62
|
-
(_inputRef$current = inputRef.current) == null
|
|
62
|
+
(_inputRef$current = inputRef.current) == null || _inputRef$current.focus();
|
|
63
63
|
}
|
|
64
64
|
}, [hasFocus]);
|
|
65
65
|
if (!isSingleSelectColDef(colDef)) {
|