@mui/x-data-grid 7.0.0 → 7.1.1
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 +246 -4
- package/DataGrid/DataGrid.js +5 -0
- package/DataGrid/useDataGridProps.js +1 -0
- package/README.md +1 -1
- package/components/cell/GridCell.js +0 -1
- package/components/columnHeaders/GridColumnHeaderItem.js +3 -1
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +3 -1
- package/components/toolbar/GridToolbarQuickFilter.js +17 -2
- package/components/virtualization/GridMainContainer.js +8 -1
- package/components/virtualization/GridTopContainer.js +1 -0
- package/hooks/features/dimensions/useGridDimensions.d.ts +1 -1
- package/hooks/features/dimensions/useGridDimensions.js +3 -2
- package/hooks/features/editing/useGridRowEditing.js +13 -4
- package/hooks/features/headerFiltering/useGridHeaderFiltering.d.ts +2 -2
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +4 -7
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +2 -2
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -3
- package/hooks/features/virtualization/useGridVirtualScroller.js +17 -6
- package/index.js +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/utils/propValidation.d.ts +1 -0
- package/internals/utils/propValidation.js +9 -4
- package/locales/esES.js +3 -4
- package/locales/faIR.js +3 -4
- package/locales/ptBR.js +3 -4
- package/models/gridExport.d.ts +2 -2
- package/models/gridFilterModel.d.ts +3 -3
- package/models/params/gridCellParams.d.ts +0 -22
- package/models/props/DataGridProps.d.ts +24 -0
- package/modern/DataGrid/DataGrid.js +5 -0
- package/modern/DataGrid/useDataGridProps.js +1 -0
- package/modern/components/cell/GridCell.js +0 -1
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +3 -1
- package/modern/components/columnHeaders/GridGenericColumnHeaderItem.js +3 -1
- package/modern/components/toolbar/GridToolbarQuickFilter.js +17 -2
- package/modern/components/virtualization/GridMainContainer.js +8 -1
- package/modern/components/virtualization/GridTopContainer.js +1 -0
- package/modern/hooks/features/dimensions/useGridDimensions.js +3 -2
- package/modern/hooks/features/editing/useGridRowEditing.js +13 -4
- package/modern/hooks/features/headerFiltering/useGridHeaderFiltering.js +4 -7
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -3
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +17 -6
- package/modern/index.js +1 -1
- package/modern/internals/utils/propValidation.js +9 -4
- package/modern/locales/esES.js +3 -4
- package/modern/locales/faIR.js +3 -4
- package/modern/locales/ptBR.js +3 -4
- package/modern/utils/throttle.js +19 -0
- package/node/DataGrid/DataGrid.js +5 -0
- package/node/DataGrid/useDataGridProps.js +1 -0
- package/node/components/cell/GridCell.js +0 -1
- package/node/components/columnHeaders/GridColumnHeaderItem.js +3 -1
- package/node/components/columnHeaders/GridGenericColumnHeaderItem.js +3 -1
- package/node/components/toolbar/GridToolbarQuickFilter.js +17 -2
- package/node/components/virtualization/GridMainContainer.js +8 -1
- package/node/components/virtualization/GridTopContainer.js +1 -0
- package/node/hooks/features/dimensions/useGridDimensions.js +2 -1
- package/node/hooks/features/editing/useGridRowEditing.js +13 -4
- package/node/hooks/features/headerFiltering/useGridHeaderFiltering.js +4 -7
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -3
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +17 -6
- package/node/index.js +1 -1
- package/node/internals/utils/propValidation.js +12 -6
- package/node/locales/esES.js +3 -4
- package/node/locales/faIR.js +3 -4
- package/node/locales/ptBR.js +3 -4
- package/node/utils/throttle.js +25 -0
- package/package.json +2 -2
- package/utils/throttle.d.ts +4 -0
- package/utils/throttle.js +19 -0
|
@@ -38,9 +38,9 @@ const EMPTY_SCROLL_POSITION = {
|
|
|
38
38
|
left: 0
|
|
39
39
|
};
|
|
40
40
|
export const EMPTY_DETAIL_PANELS = Object.freeze(new Map());
|
|
41
|
-
const createScrollCache = (rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) => ({
|
|
41
|
+
const createScrollCache = (mode, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) => ({
|
|
42
42
|
direction: ScrollDirection.NONE,
|
|
43
|
-
buffer: bufferForDirection(ScrollDirection.NONE, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer)
|
|
43
|
+
buffer: bufferForDirection(mode, ScrollDirection.NONE, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer)
|
|
44
44
|
});
|
|
45
45
|
const isJSDOM = typeof window !== 'undefined' ? /jsdom/.test(window.navigator.userAgent) : false;
|
|
46
46
|
export const useGridVirtualScroller = () => {
|
|
@@ -92,7 +92,7 @@ export const useGridVirtualScroller = () => {
|
|
|
92
92
|
const renderContext = useGridSelector(apiRef, gridRenderContextSelector);
|
|
93
93
|
const scrollTimeout = useTimeout();
|
|
94
94
|
const frozenContext = React.useRef(undefined);
|
|
95
|
-
const scrollCache = useLazyRef(() => createScrollCache(rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6)).current;
|
|
95
|
+
const scrollCache = useLazyRef(() => createScrollCache(theme.direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6)).current;
|
|
96
96
|
const focusedCell = {
|
|
97
97
|
rowIndex: React.useMemo(() => cellFocus ? currentPage.rows.findIndex(row => row.id === cellFocus.id) : -1, [cellFocus, currentPage.rows]),
|
|
98
98
|
columnIndex: React.useMemo(() => cellFocus ? visibleColumns.findIndex(column => column.field === cellFocus.field) : -1, [cellFocus, visibleColumns])
|
|
@@ -157,7 +157,7 @@ export const useGridVirtualScroller = () => {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
scrollCache.direction = direction;
|
|
160
|
-
scrollCache.buffer = bufferForDirection(direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6);
|
|
160
|
+
scrollCache.buffer = bufferForDirection(theme.direction, direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6);
|
|
161
161
|
const inputs = inputsSelector(apiRef, rootProps, enabled, enabledForColumns);
|
|
162
162
|
const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
|
|
163
163
|
|
|
@@ -638,7 +638,7 @@ export function areRenderContextsEqual(context1, context2) {
|
|
|
638
638
|
export function computeOffsetLeft(columnPositions, renderContext, direction, pinnedLeftLength) {
|
|
639
639
|
const factor = direction === 'ltr' ? 1 : -1;
|
|
640
640
|
const left = factor * (columnPositions[renderContext.firstColumnIndex] ?? 0) - (columnPositions[pinnedLeftLength] ?? 0);
|
|
641
|
-
return left;
|
|
641
|
+
return Math.abs(left);
|
|
642
642
|
}
|
|
643
643
|
function directionForDelta(dx, dy) {
|
|
644
644
|
if (dx === 0 && dy === 0) {
|
|
@@ -660,7 +660,18 @@ function directionForDelta(dx, dy) {
|
|
|
660
660
|
}
|
|
661
661
|
/* eslint-enable */
|
|
662
662
|
}
|
|
663
|
-
function bufferForDirection(direction, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) {
|
|
663
|
+
function bufferForDirection(mode, direction, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) {
|
|
664
|
+
if (mode === 'rtl') {
|
|
665
|
+
switch (direction) {
|
|
666
|
+
case ScrollDirection.LEFT:
|
|
667
|
+
direction = ScrollDirection.RIGHT;
|
|
668
|
+
break;
|
|
669
|
+
case ScrollDirection.RIGHT:
|
|
670
|
+
direction = ScrollDirection.LEFT;
|
|
671
|
+
break;
|
|
672
|
+
default:
|
|
673
|
+
}
|
|
674
|
+
}
|
|
664
675
|
switch (direction) {
|
|
665
676
|
case ScrollDirection.NONE:
|
|
666
677
|
return {
|
package/index.js
CHANGED
package/internals/index.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export { useTimeout } from '../hooks/utils/useTimeout';
|
|
|
65
65
|
export { useGridVisibleRows, getVisibleRows } from '../hooks/utils/useGridVisibleRows';
|
|
66
66
|
export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
|
|
67
67
|
export type { GridStateInitializer } from '../hooks/utils/useGridInitializeState';
|
|
68
|
-
export type { GridExperimentalFeatures, DataGridPropsWithoutDefaultValue, DataGridPropsWithDefaultValues, DataGridPropsWithComplexDefaultValueAfterProcessing, DataGridPropsWithComplexDefaultValueBeforeProcessing, } from '../models/props/DataGridProps';
|
|
68
|
+
export type { DataGridProSharedPropsWithDefaultValue, DataGridPremiumSharedPropsWithDefaultValue, GridExperimentalFeatures, DataGridPropsWithoutDefaultValue, DataGridPropsWithDefaultValues, DataGridPropsWithComplexDefaultValueAfterProcessing, DataGridPropsWithComplexDefaultValueBeforeProcessing, } from '../models/props/DataGridProps';
|
|
69
69
|
export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
|
|
70
70
|
export * from '../utils/createControllablePromise';
|
|
71
71
|
export { createSelector, createSelectorMemoized } from '../utils/createSelector';
|
|
@@ -2,3 +2,4 @@ import { DataGridProcessedProps } from '../../models/props/DataGridProps';
|
|
|
2
2
|
export type PropValidator<TProps> = (props: TProps) => string | undefined;
|
|
3
3
|
export declare const propValidatorsDataGrid: PropValidator<DataGridProcessedProps>[];
|
|
4
4
|
export declare const validateProps: <TProps>(props: TProps, validators: PropValidator<TProps>[]) => void;
|
|
5
|
+
export declare const clearWarningsCache: () => void;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { isNumber } from '../../utils/utils';
|
|
2
|
+
import { GridSignature } from '../../hooks/utils/useGridApiEventHandler';
|
|
3
|
+
export const propValidatorsDataGrid = [props => props.autoPageSize && props.autoHeight && ['MUI X: `<DataGrid autoPageSize={true} autoHeight={true} />` are not valid props.', 'You cannot use both the `autoPageSize` and `autoHeight` props at the same time because `autoHeight` scales the height of the Data Grid according to the `pageSize`.', '', 'Please remove one of these two props.'].join('\n') || undefined, props => props.signature === GridSignature.DataGrid && props.paginationMode === 'client' && isNumber(props.rowCount) && 'MUI X: Usage of the `rowCount` prop with client side pagination (`paginationMode="client"`) has no effect. `rowCount` is only meant to be used with `paginationMode="server"`.' || undefined];
|
|
4
|
+
const warnedOnceCache = new Set();
|
|
3
5
|
const warnOnce = message => {
|
|
4
|
-
if (!
|
|
6
|
+
if (!warnedOnceCache.has(message)) {
|
|
5
7
|
console.error(message);
|
|
6
|
-
|
|
8
|
+
warnedOnceCache.add(message);
|
|
7
9
|
}
|
|
8
10
|
};
|
|
9
11
|
export const validateProps = (props, validators) => {
|
|
@@ -16,4 +18,7 @@ export const validateProps = (props, validators) => {
|
|
|
16
18
|
warnOnce(warning);
|
|
17
19
|
}
|
|
18
20
|
});
|
|
21
|
+
};
|
|
22
|
+
export const clearWarningsCache = () => {
|
|
23
|
+
warnedOnceCache.clear();
|
|
19
24
|
};
|
package/locales/esES.js
CHANGED
|
@@ -30,10 +30,9 @@ const esESGrid = {
|
|
|
30
30
|
toolbarExportPrint: 'Imprimir',
|
|
31
31
|
toolbarExportExcel: 'Descargar como Excel',
|
|
32
32
|
// Columns management text
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
columnsManagementSearchTitle: 'Buscar',
|
|
34
|
+
columnsManagementNoColumns: 'Sin columnas',
|
|
35
|
+
columnsManagementShowHideAllText: 'Mostrar/Ocultar todas',
|
|
37
36
|
// Filter panel text
|
|
38
37
|
filterPanelAddFilter: 'Agregar filtro',
|
|
39
38
|
filterPanelRemoveAll: 'Remover todos',
|
package/locales/faIR.js
CHANGED
|
@@ -30,10 +30,9 @@ const faIRGrid = {
|
|
|
30
30
|
toolbarExportPrint: 'چاپ',
|
|
31
31
|
toolbarExportExcel: 'دانلود به صورت اکسل',
|
|
32
32
|
// Columns management text
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
columnsManagementSearchTitle: 'جستجو',
|
|
34
|
+
columnsManagementNoColumns: 'بدون سطر',
|
|
35
|
+
columnsManagementShowHideAllText: 'نمایش/مخفی کردن همه',
|
|
37
36
|
// Filter panel text
|
|
38
37
|
filterPanelAddFilter: 'افزودن فیلتر',
|
|
39
38
|
filterPanelRemoveAll: 'حذف همه',
|
package/locales/ptBR.js
CHANGED
|
@@ -30,10 +30,9 @@ const ptBRGrid = {
|
|
|
30
30
|
toolbarExportPrint: 'Imprimir',
|
|
31
31
|
toolbarExportExcel: 'Baixar como Excel',
|
|
32
32
|
// Columns management text
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
columnsManagementSearchTitle: 'Buscar',
|
|
34
|
+
columnsManagementNoColumns: 'Nenhuma coluna',
|
|
35
|
+
columnsManagementShowHideAllText: 'Mostrar/Ocultar Todas',
|
|
37
36
|
// Filter panel text
|
|
38
37
|
filterPanelAddFilter: 'Adicionar filtro',
|
|
39
38
|
filterPanelRemoveAll: 'Remover todos',
|
package/models/gridExport.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface GridExportOptions {
|
|
|
23
23
|
export interface GridFileExportOptions<Api extends GridApiCommon = GridApiCommunity> extends GridExportOptions {
|
|
24
24
|
/**
|
|
25
25
|
* The string used as the file name.
|
|
26
|
-
* @default
|
|
26
|
+
* @default document.title
|
|
27
27
|
*/
|
|
28
28
|
fileName?: string;
|
|
29
29
|
/**
|
|
@@ -61,7 +61,7 @@ export interface GridCsvExportOptions extends GridFileExportOptions {
|
|
|
61
61
|
delimiter?: string;
|
|
62
62
|
/**
|
|
63
63
|
* The string used as the file name.
|
|
64
|
-
* @default
|
|
64
|
+
* @default document.title
|
|
65
65
|
*/
|
|
66
66
|
fileName?: string;
|
|
67
67
|
/**
|
|
@@ -12,18 +12,18 @@ export interface GridFilterModel {
|
|
|
12
12
|
/**
|
|
13
13
|
* - `GridLogicOperator.And`: the row must pass all the filter items.
|
|
14
14
|
* - `GridLogicOperator.Or`: the row must pass at least on filter item.
|
|
15
|
-
* @default
|
|
15
|
+
* @default GridLogicOperator.And
|
|
16
16
|
*/
|
|
17
17
|
logicOperator?: GridLogicOperator;
|
|
18
18
|
/**
|
|
19
19
|
* values used to quick filter rows
|
|
20
|
-
* @default
|
|
20
|
+
* @default []
|
|
21
21
|
*/
|
|
22
22
|
quickFilterValues?: any[];
|
|
23
23
|
/**
|
|
24
24
|
* - `GridLogicOperator.And`: the row must pass all the values.
|
|
25
25
|
* - `GridLogicOperator.Or`: the row must pass at least one value.
|
|
26
|
-
* @default
|
|
26
|
+
* @default GridLogicOperator.And
|
|
27
27
|
*/
|
|
28
28
|
quickFilterLogicOperator?: GridLogicOperator;
|
|
29
29
|
/**
|
|
@@ -81,28 +81,6 @@ export interface GridRenderEditCellParams<R extends GridValidRowModel = any, V =
|
|
|
81
81
|
*/
|
|
82
82
|
api: GridApiCommunity;
|
|
83
83
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Object passed as parameter in the column [[GridColDef]] value formatter callback.
|
|
86
|
-
*/
|
|
87
|
-
export interface GridValueFormatterParams<V = any> {
|
|
88
|
-
/**
|
|
89
|
-
* The grid row id.
|
|
90
|
-
* It is not available when the value formatter is called by the filter panel.
|
|
91
|
-
*/
|
|
92
|
-
id?: GridRowId;
|
|
93
|
-
/**
|
|
94
|
-
* The column field of the cell that triggered the event.
|
|
95
|
-
*/
|
|
96
|
-
field: string;
|
|
97
|
-
/**
|
|
98
|
-
* The cell value, if the column has valueGetter it is the value returned by it.
|
|
99
|
-
*/
|
|
100
|
-
value: V;
|
|
101
|
-
/**
|
|
102
|
-
* GridApi that let you manipulate the grid.
|
|
103
|
-
*/
|
|
104
|
-
api: GridApiCommunity;
|
|
105
|
-
}
|
|
106
84
|
/**
|
|
107
85
|
* Object passed as parameter in the column [[GridColDef]] edit cell props change callback.
|
|
108
86
|
*/
|
|
@@ -112,6 +112,11 @@ export interface DataGridPropsWithDefaultValues<R extends GridValidRowModel = an
|
|
|
112
112
|
* @default true
|
|
113
113
|
*/
|
|
114
114
|
rowSelection: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* The milliseconds throttle delay for resizing the grid.
|
|
117
|
+
* @default 60
|
|
118
|
+
*/
|
|
119
|
+
resizeThrottleMs: number;
|
|
115
120
|
/**
|
|
116
121
|
* If `true`, column filters are disabled.
|
|
117
122
|
* @default false
|
|
@@ -745,3 +750,22 @@ export interface DataGridPropsWithoutDefaultValue<R extends GridValidRowModel =
|
|
|
745
750
|
*/
|
|
746
751
|
onColumnWidthChange?: GridEventListener<'columnWidthChange'>;
|
|
747
752
|
}
|
|
753
|
+
export interface DataGridProSharedPropsWithDefaultValue {
|
|
754
|
+
/**
|
|
755
|
+
* If `true`, enables the data grid filtering on header feature.
|
|
756
|
+
* @default false
|
|
757
|
+
*/
|
|
758
|
+
headerFilters: boolean;
|
|
759
|
+
}
|
|
760
|
+
export interface DataGridPremiumSharedPropsWithDefaultValue {
|
|
761
|
+
/**
|
|
762
|
+
* If `true`, the cell selection mode is enabled.
|
|
763
|
+
* @default false
|
|
764
|
+
*/
|
|
765
|
+
cellSelection: boolean;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Contains the commercial packages' props shared in the MIT version.
|
|
769
|
+
*/
|
|
770
|
+
export interface DataGridProcessedPropsWithShared extends DataGridProcessedProps, Partial<DataGridProSharedPropsWithDefaultValue>, Partial<DataGridPremiumSharedPropsWithDefaultValue> {
|
|
771
|
+
}
|
|
@@ -608,6 +608,11 @@ DataGridRaw.propTypes = {
|
|
|
608
608
|
* @returns {Promise<R> | R} The final values to update the row.
|
|
609
609
|
*/
|
|
610
610
|
processRowUpdate: PropTypes.func,
|
|
611
|
+
/**
|
|
612
|
+
* The milliseconds throttle delay for resizing the grid.
|
|
613
|
+
* @default 60
|
|
614
|
+
*/
|
|
615
|
+
resizeThrottleMs: PropTypes.number,
|
|
611
616
|
/**
|
|
612
617
|
* Row region in pixels to render before/after the viewport
|
|
613
618
|
* @default 150
|
|
@@ -159,7 +159,6 @@ const GridCell = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
159
159
|
const cellRef = React.useRef(null);
|
|
160
160
|
const handleRef = useForkRef(ref, cellRef);
|
|
161
161
|
const focusElementRef = React.useRef(null);
|
|
162
|
-
// @ts-expect-error To access `cellSelection` flag as it's a `premium` feature
|
|
163
162
|
const isSelectionMode = rootProps.cellSelection ?? false;
|
|
164
163
|
const position = gridPinnedColumnPositionLookup[pinnedPosition];
|
|
165
164
|
const showLeftBorder = shouldCellShowLeftBorder(position, sectionIndex);
|
|
@@ -153,7 +153,9 @@ function GridColumnHeaderItem(props) {
|
|
|
153
153
|
const focusableElement = headerCellRef.current.querySelector('[tabindex="0"]');
|
|
154
154
|
const elementToFocus = focusableElement || headerCellRef.current;
|
|
155
155
|
elementToFocus?.focus();
|
|
156
|
-
apiRef.current.columnHeadersContainerRef
|
|
156
|
+
if (apiRef.current.columnHeadersContainerRef?.current) {
|
|
157
|
+
apiRef.current.columnHeadersContainerRef.current.scrollLeft = 0;
|
|
158
|
+
}
|
|
157
159
|
}
|
|
158
160
|
}, [apiRef, hasFocus]);
|
|
159
161
|
const headerClassName = typeof colDef.headerClassName === 'function' ? colDef.headerClassName({
|
|
@@ -56,7 +56,9 @@ const GridGenericColumnHeaderItem = /*#__PURE__*/React.forwardRef(function GridG
|
|
|
56
56
|
const focusableElement = headerCellRef.current.querySelector('[tabindex="0"]');
|
|
57
57
|
const elementToFocus = focusableElement || headerCellRef.current;
|
|
58
58
|
elementToFocus?.focus();
|
|
59
|
-
apiRef.current.columnHeadersContainerRef
|
|
59
|
+
if (apiRef.current.columnHeadersContainerRef?.current) {
|
|
60
|
+
apiRef.current.columnHeadersContainerRef.current.scrollLeft = 0;
|
|
61
|
+
}
|
|
60
62
|
}
|
|
61
63
|
}, [apiRef, hasFocus]);
|
|
62
64
|
return /*#__PURE__*/_jsxs("div", _extends({
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["quickFilterParser", "quickFilterFormatter", "debounceMs"];
|
|
3
|
+
const _excluded = ["quickFilterParser", "quickFilterFormatter", "debounceMs", "className"];
|
|
4
4
|
import * as React from 'react';
|
|
5
|
+
import clsx from 'clsx';
|
|
5
6
|
import PropTypes from 'prop-types';
|
|
6
7
|
import TextField from '@mui/material/TextField';
|
|
7
8
|
import { styled } from '@mui/material/styles';
|
|
8
9
|
import { unstable_debounce as debounce } from '@mui/utils';
|
|
10
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
11
|
+
import { getDataGridUtilityClass } from '../../constants';
|
|
9
12
|
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
|
|
10
13
|
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
|
|
11
14
|
import { useGridSelector } from '../../hooks/utils/useGridSelector';
|
|
12
15
|
import { gridQuickFilterValuesSelector } from '../../hooks/features/filter';
|
|
13
16
|
import { isDeepEqual } from '../../utils/utils';
|
|
14
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
const useUtilityClasses = ownerState => {
|
|
19
|
+
const {
|
|
20
|
+
classes
|
|
21
|
+
} = ownerState;
|
|
22
|
+
const slots = {
|
|
23
|
+
root: ['toolbarQuickFilter']
|
|
24
|
+
};
|
|
25
|
+
return composeClasses(slots, getDataGridUtilityClass, classes);
|
|
26
|
+
};
|
|
15
27
|
const GridToolbarQuickFilterRoot = styled(TextField, {
|
|
16
28
|
name: 'MuiDataGrid',
|
|
17
29
|
slot: 'ToolbarQuickFilter',
|
|
@@ -47,11 +59,13 @@ const defaultSearchValueFormatter = values => values.join(' ');
|
|
|
47
59
|
function GridToolbarQuickFilter(props) {
|
|
48
60
|
const apiRef = useGridApiContext();
|
|
49
61
|
const rootProps = useGridRootProps();
|
|
62
|
+
const classes = useUtilityClasses(rootProps);
|
|
50
63
|
const quickFilterValues = useGridSelector(apiRef, gridQuickFilterValuesSelector);
|
|
51
64
|
const {
|
|
52
65
|
quickFilterParser = defaultSearchValueParser,
|
|
53
66
|
quickFilterFormatter = defaultSearchValueFormatter,
|
|
54
|
-
debounceMs = rootProps.filterDebounceMs
|
|
67
|
+
debounceMs = rootProps.filterDebounceMs,
|
|
68
|
+
className
|
|
55
69
|
} = props,
|
|
56
70
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
57
71
|
const [searchValue, setSearchValue] = React.useState(() => quickFilterFormatter(quickFilterValues ?? []));
|
|
@@ -86,6 +100,7 @@ function GridToolbarQuickFilter(props) {
|
|
|
86
100
|
variant: "standard",
|
|
87
101
|
value: searchValue,
|
|
88
102
|
onChange: handleSearchValueChange,
|
|
103
|
+
className: clsx(className, classes.root),
|
|
89
104
|
placeholder: apiRef.current.getLocaleText('toolbarQuickFilterPlaceholder'),
|
|
90
105
|
"aria-label": apiRef.current.getLocaleText('toolbarQuickFilterLabel'),
|
|
91
106
|
type: "search"
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { styled } from '@mui/system';
|
|
4
|
+
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
|
|
4
5
|
import { useGridAriaAttributes } from '../../hooks/utils/useGridAriaAttributes';
|
|
5
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
const Element = styled('div'
|
|
7
|
+
const Element = styled('div', {
|
|
8
|
+
name: 'MuiDataGrid',
|
|
9
|
+
slot: 'Main',
|
|
10
|
+
overridesResolver: (props, styles) => styles.main
|
|
11
|
+
})({
|
|
7
12
|
flexGrow: 1,
|
|
8
13
|
position: 'relative',
|
|
9
14
|
overflow: 'hidden'
|
|
10
15
|
});
|
|
11
16
|
export const GridMainContainer = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
12
17
|
const ariaAttributes = useGridAriaAttributes();
|
|
18
|
+
const rootProps = useGridRootProps();
|
|
13
19
|
return /*#__PURE__*/_jsx(Element, _extends({
|
|
14
20
|
ref: ref,
|
|
21
|
+
ownerState: rootProps,
|
|
15
22
|
className: props.className,
|
|
16
23
|
tabIndex: -1
|
|
17
24
|
}, ariaAttributes, {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { unstable_ownerDocument as ownerDocument, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback, unstable_ownerWindow as ownerWindow } from '@mui/utils';
|
|
4
4
|
import { useGridApiEventHandler, useGridApiOptionHandler } from '../../utils/useGridApiEventHandler';
|
|
5
5
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
6
|
+
import { throttle } from '../../../utils/throttle';
|
|
6
7
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
7
8
|
import { gridColumnsTotalWidthSelector, gridVisiblePinnedColumnDefinitionsSelector } from '../columns';
|
|
8
9
|
import { gridDimensionsSelector } from './gridDimensionsSelectors';
|
|
@@ -57,7 +58,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
57
58
|
const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
|
|
58
59
|
const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
|
|
59
60
|
const [savedSize, setSavedSize] = React.useState();
|
|
60
|
-
const debouncedSetSavedSize = React.useMemo(() =>
|
|
61
|
+
const debouncedSetSavedSize = React.useMemo(() => throttle(setSavedSize, props.resizeThrottleMs), [props.resizeThrottleMs]);
|
|
61
62
|
const previousSize = React.useRef();
|
|
62
63
|
const getRootDimensions = () => apiRef.current.state.dimensions;
|
|
63
64
|
const setDimensions = useEventCallback(dimensions => {
|
|
@@ -45,6 +45,10 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
45
45
|
throw new Error(`MUI X: The row with id=${id} is not in ${mode} mode.`);
|
|
46
46
|
}
|
|
47
47
|
}, [apiRef]);
|
|
48
|
+
const hasFieldsWithErrors = React.useCallback(rowId => {
|
|
49
|
+
const editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
50
|
+
return Object.values(editingState[rowId]).some(fieldProps => fieldProps.error);
|
|
51
|
+
}, [apiRef]);
|
|
48
52
|
const handleCellDoubleClick = React.useCallback((params, event) => {
|
|
49
53
|
if (!params.isEditable) {
|
|
50
54
|
return;
|
|
@@ -86,6 +90,9 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
86
90
|
if (apiRef.current.getRowMode(params.id) === GridRowModes.View) {
|
|
87
91
|
return;
|
|
88
92
|
}
|
|
93
|
+
if (hasFieldsWithErrors(params.id)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
89
96
|
const rowParams = apiRef.current.getRowParams(params.id);
|
|
90
97
|
const newParams = _extends({}, rowParams, {
|
|
91
98
|
field: params.field,
|
|
@@ -94,7 +101,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
94
101
|
apiRef.current.publishEvent('rowEditStop', newParams, event);
|
|
95
102
|
}
|
|
96
103
|
});
|
|
97
|
-
}, [apiRef]);
|
|
104
|
+
}, [apiRef, hasFieldsWithErrors]);
|
|
98
105
|
React.useEffect(() => {
|
|
99
106
|
return () => {
|
|
100
107
|
clearTimeout(focusTimeout.current);
|
|
@@ -140,6 +147,9 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
149
|
if (reason) {
|
|
150
|
+
if (reason !== GridRowEditStopReasons.escapeKeyDown && hasFieldsWithErrors(params.id)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
143
153
|
const newParams = _extends({}, apiRef.current.getRowParams(params.id), {
|
|
144
154
|
reason,
|
|
145
155
|
field: params.field
|
|
@@ -174,7 +184,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
174
184
|
apiRef.current.publishEvent('rowEditStart', newParams, event);
|
|
175
185
|
}
|
|
176
186
|
}
|
|
177
|
-
}, [apiRef]);
|
|
187
|
+
}, [apiRef, hasFieldsWithErrors]);
|
|
178
188
|
const handleRowEditStart = React.useCallback(params => {
|
|
179
189
|
const {
|
|
180
190
|
id,
|
|
@@ -358,8 +368,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
358
368
|
prevRowModesModel.current[id].mode = GridRowModes.Edit;
|
|
359
369
|
return;
|
|
360
370
|
}
|
|
361
|
-
|
|
362
|
-
if (hasSomeFieldWithError) {
|
|
371
|
+
if (hasFieldsWithErrors(id)) {
|
|
363
372
|
prevRowModesModel.current[id].mode = GridRowModes.Edit;
|
|
364
373
|
// Revert the mode in the rowModesModel prop back to "edit"
|
|
365
374
|
updateRowInRowModesModel(id, {
|
|
@@ -4,7 +4,6 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
4
4
|
import { useGridLogger } from '../../utils';
|
|
5
5
|
import { gridColumnLookupSelector, gridColumnVisibilityModelSelector, gridColumnFieldsSelector } from '../columns/gridColumnsSelector';
|
|
6
6
|
export const headerFilteringStateInitializer = (state, props) => _extends({}, state, {
|
|
7
|
-
// @ts-expect-error Access `Pro` prop in MIT
|
|
8
7
|
headerFiltering: {
|
|
9
8
|
enabled: props.headerFilters ?? false,
|
|
10
9
|
editing: null,
|
|
@@ -13,8 +12,6 @@ export const headerFilteringStateInitializer = (state, props) => _extends({}, st
|
|
|
13
12
|
});
|
|
14
13
|
export const useGridHeaderFiltering = (apiRef, props) => {
|
|
15
14
|
const logger = useGridLogger(apiRef, 'useGridHeaderFiltering');
|
|
16
|
-
// @ts-expect-error Access `Pro` prop in MIT
|
|
17
|
-
const isHeaderFilteringEnabled = props.headerFilters ?? false;
|
|
18
15
|
const setHeaderFilterState = React.useCallback(headerFilterState => {
|
|
19
16
|
apiRef.current.setState(state => {
|
|
20
17
|
// Safety check to avoid MIT users from using it
|
|
@@ -24,14 +21,14 @@ export const useGridHeaderFiltering = (apiRef, props) => {
|
|
|
24
21
|
}
|
|
25
22
|
return _extends({}, state, {
|
|
26
23
|
headerFiltering: {
|
|
27
|
-
enabled:
|
|
24
|
+
enabled: props.headerFilters ?? false,
|
|
28
25
|
editing: headerFilterState.editing ?? null,
|
|
29
26
|
menuOpen: headerFilterState.menuOpen ?? null
|
|
30
27
|
}
|
|
31
28
|
});
|
|
32
29
|
});
|
|
33
30
|
apiRef.current.forceUpdate();
|
|
34
|
-
}, [apiRef, props.signature,
|
|
31
|
+
}, [apiRef, props.signature, props.headerFilters]);
|
|
35
32
|
const startHeaderFilterEditMode = React.useCallback(field => {
|
|
36
33
|
logger.debug(`Starting edit mode on header filter for field: ${field}`);
|
|
37
34
|
apiRef.current.setHeaderFilterState({
|
|
@@ -102,8 +99,8 @@ export const useGridHeaderFiltering = (apiRef, props) => {
|
|
|
102
99
|
isFirstRender.current = false;
|
|
103
100
|
} else {
|
|
104
101
|
apiRef.current.setHeaderFilterState({
|
|
105
|
-
enabled:
|
|
102
|
+
enabled: props.headerFilters ?? false
|
|
106
103
|
});
|
|
107
104
|
}
|
|
108
|
-
}, [apiRef,
|
|
105
|
+
}, [apiRef, props.headerFilters]);
|
|
109
106
|
};
|
|
@@ -69,9 +69,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
69
69
|
const initialCurrentPageRows = useGridVisibleRows(apiRef, props).rows;
|
|
70
70
|
const theme = useTheme();
|
|
71
71
|
const currentPageRows = React.useMemo(() => enrichPageRowsWithPinnedRows(apiRef, initialCurrentPageRows), [apiRef, initialCurrentPageRows]);
|
|
72
|
-
const headerFilteringEnabled =
|
|
73
|
-
// @ts-expect-error // TODO move relevant code to the `DataGridPro`
|
|
74
|
-
props.signature !== 'DataGrid' && props.headerFilters;
|
|
72
|
+
const headerFilteringEnabled = props.signature !== 'DataGrid' && props.headerFilters;
|
|
75
73
|
|
|
76
74
|
/**
|
|
77
75
|
* @param {number} colIndex Index of the column to focus
|
|
@@ -38,9 +38,9 @@ const EMPTY_SCROLL_POSITION = {
|
|
|
38
38
|
left: 0
|
|
39
39
|
};
|
|
40
40
|
export const EMPTY_DETAIL_PANELS = Object.freeze(new Map());
|
|
41
|
-
const createScrollCache = (rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) => ({
|
|
41
|
+
const createScrollCache = (mode, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) => ({
|
|
42
42
|
direction: ScrollDirection.NONE,
|
|
43
|
-
buffer: bufferForDirection(ScrollDirection.NONE, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer)
|
|
43
|
+
buffer: bufferForDirection(mode, ScrollDirection.NONE, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer)
|
|
44
44
|
});
|
|
45
45
|
const isJSDOM = typeof window !== 'undefined' ? /jsdom/.test(window.navigator.userAgent) : false;
|
|
46
46
|
export const useGridVirtualScroller = () => {
|
|
@@ -92,7 +92,7 @@ export const useGridVirtualScroller = () => {
|
|
|
92
92
|
const renderContext = useGridSelector(apiRef, gridRenderContextSelector);
|
|
93
93
|
const scrollTimeout = useTimeout();
|
|
94
94
|
const frozenContext = React.useRef(undefined);
|
|
95
|
-
const scrollCache = useLazyRef(() => createScrollCache(rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6)).current;
|
|
95
|
+
const scrollCache = useLazyRef(() => createScrollCache(theme.direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6)).current;
|
|
96
96
|
const focusedCell = {
|
|
97
97
|
rowIndex: React.useMemo(() => cellFocus ? currentPage.rows.findIndex(row => row.id === cellFocus.id) : -1, [cellFocus, currentPage.rows]),
|
|
98
98
|
columnIndex: React.useMemo(() => cellFocus ? visibleColumns.findIndex(column => column.field === cellFocus.field) : -1, [cellFocus, visibleColumns])
|
|
@@ -157,7 +157,7 @@ export const useGridVirtualScroller = () => {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
scrollCache.direction = direction;
|
|
160
|
-
scrollCache.buffer = bufferForDirection(direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6);
|
|
160
|
+
scrollCache.buffer = bufferForDirection(theme.direction, direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6);
|
|
161
161
|
const inputs = inputsSelector(apiRef, rootProps, enabled, enabledForColumns);
|
|
162
162
|
const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
|
|
163
163
|
|
|
@@ -638,7 +638,7 @@ export function areRenderContextsEqual(context1, context2) {
|
|
|
638
638
|
export function computeOffsetLeft(columnPositions, renderContext, direction, pinnedLeftLength) {
|
|
639
639
|
const factor = direction === 'ltr' ? 1 : -1;
|
|
640
640
|
const left = factor * (columnPositions[renderContext.firstColumnIndex] ?? 0) - (columnPositions[pinnedLeftLength] ?? 0);
|
|
641
|
-
return left;
|
|
641
|
+
return Math.abs(left);
|
|
642
642
|
}
|
|
643
643
|
function directionForDelta(dx, dy) {
|
|
644
644
|
if (dx === 0 && dy === 0) {
|
|
@@ -660,7 +660,18 @@ function directionForDelta(dx, dy) {
|
|
|
660
660
|
}
|
|
661
661
|
/* eslint-enable */
|
|
662
662
|
}
|
|
663
|
-
function bufferForDirection(direction, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) {
|
|
663
|
+
function bufferForDirection(mode, direction, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) {
|
|
664
|
+
if (mode === 'rtl') {
|
|
665
|
+
switch (direction) {
|
|
666
|
+
case ScrollDirection.LEFT:
|
|
667
|
+
direction = ScrollDirection.RIGHT;
|
|
668
|
+
break;
|
|
669
|
+
case ScrollDirection.RIGHT:
|
|
670
|
+
direction = ScrollDirection.LEFT;
|
|
671
|
+
break;
|
|
672
|
+
default:
|
|
673
|
+
}
|
|
674
|
+
}
|
|
664
675
|
switch (direction) {
|
|
665
676
|
case ScrollDirection.NONE:
|
|
666
677
|
return {
|
package/modern/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { isNumber } from '../../utils/utils';
|
|
2
|
+
import { GridSignature } from '../../hooks/utils/useGridApiEventHandler';
|
|
3
|
+
export const propValidatorsDataGrid = [props => props.autoPageSize && props.autoHeight && ['MUI X: `<DataGrid autoPageSize={true} autoHeight={true} />` are not valid props.', 'You cannot use both the `autoPageSize` and `autoHeight` props at the same time because `autoHeight` scales the height of the Data Grid according to the `pageSize`.', '', 'Please remove one of these two props.'].join('\n') || undefined, props => props.signature === GridSignature.DataGrid && props.paginationMode === 'client' && isNumber(props.rowCount) && 'MUI X: Usage of the `rowCount` prop with client side pagination (`paginationMode="client"`) has no effect. `rowCount` is only meant to be used with `paginationMode="server"`.' || undefined];
|
|
4
|
+
const warnedOnceCache = new Set();
|
|
3
5
|
const warnOnce = message => {
|
|
4
|
-
if (!
|
|
6
|
+
if (!warnedOnceCache.has(message)) {
|
|
5
7
|
console.error(message);
|
|
6
|
-
|
|
8
|
+
warnedOnceCache.add(message);
|
|
7
9
|
}
|
|
8
10
|
};
|
|
9
11
|
export const validateProps = (props, validators) => {
|
|
@@ -16,4 +18,7 @@ export const validateProps = (props, validators) => {
|
|
|
16
18
|
warnOnce(warning);
|
|
17
19
|
}
|
|
18
20
|
});
|
|
21
|
+
};
|
|
22
|
+
export const clearWarningsCache = () => {
|
|
23
|
+
warnedOnceCache.clear();
|
|
19
24
|
};
|