@mui/x-data-grid 7.0.0-beta.7 → 7.1.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 +266 -12
- package/DataGrid/DataGrid.js +18 -17
- package/DataGrid/useDataGridProps.js +4 -5
- package/README.md +1 -1
- package/components/GridFooter.js +2 -3
- package/components/GridHeader.js +1 -2
- package/components/GridPagination.d.ts +6 -5
- package/components/GridPagination.js +12 -4
- package/components/GridRow.js +13 -17
- package/components/base/GridFooterPlaceholder.js +1 -2
- package/components/base/GridOverlays.js +3 -6
- package/components/cell/GridActionsCell.js +4 -6
- package/components/cell/GridActionsCellItem.d.ts +8 -25
- package/components/cell/GridActionsCellItem.js +8 -5
- package/components/cell/GridBooleanCell.d.ts +1 -0
- package/components/cell/GridBooleanCell.js +3 -2
- package/components/cell/GridCell.js +7 -8
- package/components/cell/GridEditBooleanCell.js +1 -2
- package/components/cell/GridEditDateCell.js +2 -3
- package/components/cell/GridEditInputCell.js +2 -2
- package/components/cell/GridEditSingleSelectCell.js +5 -8
- package/components/columnHeaders/ColumnHeaderMenuIcon.js +2 -3
- package/components/columnHeaders/GridColumnGroupHeader.js +4 -5
- package/components/columnHeaders/GridColumnHeaderFilterIconButton.js +2 -3
- package/components/columnHeaders/GridColumnHeaderItem.js +8 -7
- package/components/columnHeaders/GridColumnHeaderSortIcon.js +1 -2
- package/components/columnHeaders/GridColumnHeaderTitle.js +2 -3
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +4 -2
- package/components/columnSelection/GridCellCheckboxRenderer.js +3 -5
- package/components/columnSelection/GridHeaderCheckbox.js +1 -2
- package/components/columnsManagement/GridColumnsManagement.js +17 -21
- package/components/containers/GridRoot.js +3 -3
- package/components/menu/GridMenu.js +4 -6
- package/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +2 -3
- package/components/panel/GridColumnsPanel.js +1 -2
- package/components/panel/GridPanel.d.ts +1 -10
- package/components/panel/GridPanel.js +1 -2
- package/components/panel/GridPreferencesPanel.js +2 -3
- package/components/panel/filterPanel/GridFilterForm.js +24 -27
- package/components/panel/filterPanel/GridFilterInputBoolean.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputBoolean.js +6 -7
- package/components/panel/filterPanel/GridFilterInputDate.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +3 -4
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +11 -15
- package/components/panel/filterPanel/GridFilterInputMultipleValue.js +10 -14
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +10 -11
- package/components/panel/filterPanel/GridFilterInputValue.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputValue.js +5 -7
- package/components/panel/filterPanel/GridFilterPanel.js +5 -9
- package/components/panel/filterPanel/filterPanelUtils.js +1 -1
- package/components/toolbar/GridToolbarColumnsButton.js +3 -5
- package/components/toolbar/GridToolbarDensitySelector.js +8 -10
- package/components/toolbar/GridToolbarExport.js +2 -2
- package/components/toolbar/GridToolbarExportContainer.js +3 -5
- package/components/toolbar/GridToolbarFilterButton.js +3 -5
- package/components/toolbar/GridToolbarQuickFilter.js +21 -7
- package/components/virtualization/GridVirtualScrollerContent.js +1 -2
- package/components/virtualization/GridVirtualScrollerRenderZone.js +1 -2
- package/hooks/core/strategyProcessing/useGridStrategyProcessing.js +1 -2
- package/hooks/core/useGridApiInitialization.js +4 -6
- package/hooks/features/clipboard/useGridClipboard.js +6 -5
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -16
- package/hooks/features/columnGrouping/gridColumnGroupsUtils.js +4 -8
- package/hooks/features/columnGrouping/useGridColumnGrouping.js +12 -23
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +6 -8
- package/hooks/features/columnMenu/useGridColumnMenuSlots.js +2 -2
- package/hooks/features/columnResize/useGridColumnResize.js +9 -19
- package/hooks/features/columns/gridColumnsSelector.js +1 -2
- package/hooks/features/columns/gridColumnsUtils.d.ts +0 -9
- package/hooks/features/columns/gridColumnsUtils.js +2 -22
- package/hooks/features/columns/useGridColumnSpanning.js +1 -2
- package/hooks/features/columns/useGridColumns.js +11 -19
- package/hooks/features/density/densitySelector.d.ts +4 -2
- package/hooks/features/density/densitySelector.js +8 -2
- package/hooks/features/density/densityState.d.ts +1 -4
- package/hooks/features/density/useGridDensity.d.ts +2 -4
- package/hooks/features/density/useGridDensity.js +21 -29
- package/hooks/features/dimensions/useGridDimensions.d.ts +1 -1
- package/hooks/features/dimensions/useGridDimensions.js +6 -7
- package/hooks/features/editing/useGridCellEditing.js +4 -6
- package/hooks/features/editing/useGridEditing.js +1 -2
- package/hooks/features/editing/useGridRowEditing.js +17 -10
- package/hooks/features/export/serializers/csvSerializer.d.ts +2 -0
- package/hooks/features/export/serializers/csvSerializer.js +25 -16
- package/hooks/features/export/useGridCsvExport.js +9 -10
- package/hooks/features/export/useGridPrintExport.js +9 -15
- package/hooks/features/export/utils.js +2 -3
- package/hooks/features/filter/gridFilterSelector.js +15 -22
- package/hooks/features/filter/gridFilterUtils.js +10 -16
- package/hooks/features/filter/useGridFilter.js +9 -15
- package/hooks/features/focus/useGridFocus.js +5 -6
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +1 -4
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +12 -17
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -2
- package/hooks/features/pagination/gridPaginationSelector.js +1 -2
- package/hooks/features/pagination/useGridPagination.js +2 -3
- package/hooks/features/pagination/useGridPaginationModel.js +6 -11
- package/hooks/features/pagination/useGridRowCount.js +3 -6
- package/hooks/features/preferencesPanel/useGridPreferencesPanel.js +7 -12
- package/hooks/features/rowSelection/useGridRowSelection.js +11 -16
- package/hooks/features/rows/gridRowsSelector.js +11 -19
- package/hooks/features/rows/gridRowsUtils.js +7 -9
- package/hooks/features/rows/useGridParamsApi.js +1 -1
- package/hooks/features/rows/useGridRows.js +4 -13
- package/hooks/features/rows/useGridRowsMeta.js +7 -13
- package/hooks/features/scroll/useGridScroll.js +2 -3
- package/hooks/features/sorting/gridSortingSelector.js +4 -7
- package/hooks/features/sorting/useGridSorting.js +8 -14
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +220 -71
- package/hooks/utils/useGridApiEventHandler.js +5 -10
- package/hooks/utils/useGridNativeEventListener.js +1 -2
- package/index.js +1 -1
- package/internals/index.d.ts +2 -0
- package/internals/index.js +1 -0
- package/internals/utils/useProps.js +1 -2
- package/joy/joySlots.js +7 -13
- package/models/api/gridRowsMetaApi.d.ts +1 -1
- package/models/api/index.d.ts +1 -1
- package/models/api/index.js +0 -1
- package/models/events/gridEventLookup.d.ts +7 -0
- package/models/gridExport.d.ts +6 -0
- package/models/gridStateCommunity.d.ts +1 -0
- package/models/props/DataGridProps.d.ts +26 -25
- package/modern/DataGrid/DataGrid.js +18 -17
- package/modern/DataGrid/useDataGridProps.js +4 -5
- package/modern/components/GridPagination.js +11 -2
- package/modern/components/cell/GridActionsCell.js +1 -1
- package/modern/components/cell/GridActionsCellItem.js +4 -0
- package/modern/components/cell/GridBooleanCell.js +3 -2
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +3 -1
- package/modern/components/columnHeaders/GridGenericColumnHeaderItem.js +3 -1
- package/modern/components/containers/GridRoot.js +3 -3
- package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputDate.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputValue.js +1 -1
- package/modern/components/toolbar/GridToolbarDensitySelector.js +5 -5
- package/modern/components/toolbar/GridToolbarQuickFilter.js +17 -2
- package/modern/hooks/features/clipboard/useGridClipboard.js +4 -2
- package/modern/hooks/features/columnResize/useGridColumnResize.js +1 -1
- package/modern/hooks/features/columns/gridColumnsUtils.js +0 -19
- package/modern/hooks/features/density/densitySelector.js +8 -2
- package/modern/hooks/features/density/useGridDensity.js +21 -29
- package/modern/hooks/features/dimensions/useGridDimensions.js +3 -2
- package/modern/hooks/features/editing/useGridCellEditing.js +1 -1
- package/modern/hooks/features/editing/useGridRowEditing.js +14 -5
- package/modern/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/modern/hooks/features/export/useGridCsvExport.js +2 -1
- package/modern/hooks/features/filter/gridFilterUtils.js +1 -1
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +3 -2
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -0
- package/modern/models/api/index.js +0 -1
- package/modern/utils/createSelector.js +1 -1
- package/modern/utils/domUtils.js +1 -1
- package/modern/utils/keyboardUtils.js +1 -1
- package/modern/utils/throttle.js +19 -0
- package/node/DataGrid/DataGrid.js +18 -17
- package/node/DataGrid/useDataGridProps.js +4 -5
- package/node/components/GridPagination.js +9 -1
- package/node/components/cell/GridActionsCell.js +1 -1
- package/node/components/cell/GridActionsCellItem.js +4 -0
- package/node/components/cell/GridBooleanCell.js +3 -2
- package/node/components/columnHeaders/GridColumnHeaderItem.js +3 -1
- package/node/components/columnHeaders/GridGenericColumnHeaderItem.js +3 -1
- package/node/components/containers/GridRoot.js +2 -2
- package/node/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputDate.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputValue.js +1 -1
- package/node/components/toolbar/GridToolbarDensitySelector.js +4 -4
- package/node/components/toolbar/GridToolbarQuickFilter.js +17 -2
- package/node/hooks/features/clipboard/useGridClipboard.js +4 -2
- package/node/hooks/features/columnResize/useGridColumnResize.js +1 -1
- package/node/hooks/features/columns/gridColumnsUtils.js +0 -20
- package/node/hooks/features/density/densitySelector.js +9 -3
- package/node/hooks/features/density/useGridDensity.js +22 -30
- package/node/hooks/features/dimensions/useGridDimensions.js +2 -1
- package/node/hooks/features/editing/useGridCellEditing.js +1 -1
- package/node/hooks/features/editing/useGridRowEditing.js +14 -5
- package/node/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/node/hooks/features/export/useGridCsvExport.js +2 -1
- package/node/hooks/features/filter/gridFilterUtils.js +1 -1
- package/node/hooks/features/rowSelection/useGridRowSelection.js +2 -1
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- package/node/index.js +1 -1
- package/node/internals/index.js +12 -0
- package/node/models/api/index.js +0 -11
- package/node/utils/createSelector.js +1 -1
- package/node/utils/domUtils.js +1 -1
- package/node/utils/keyboardUtils.js +1 -1
- package/node/utils/throttle.js +25 -0
- package/package.json +4 -4
- package/utils/createSelector.js +9 -9
- package/utils/domUtils.js +4 -7
- package/utils/getGridLocalization.js +9 -12
- package/utils/keyboardUtils.js +1 -1
- package/utils/throttle.d.ts +4 -0
- package/utils/throttle.js +19 -0
|
@@ -1,43 +1,35 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import useEventCallback from '@mui/utils/useEventCallback';
|
|
3
4
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
4
5
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
5
6
|
import { gridDensitySelector } from './densitySelector';
|
|
6
|
-
import { isDeepEqual } from '../../../utils/utils';
|
|
7
|
-
export const COMPACT_DENSITY_FACTOR = 0.7;
|
|
8
|
-
export const COMFORTABLE_DENSITY_FACTOR = 1.3;
|
|
9
|
-
const DENSITY_FACTORS = {
|
|
10
|
-
compact: COMPACT_DENSITY_FACTOR,
|
|
11
|
-
comfortable: COMFORTABLE_DENSITY_FACTOR,
|
|
12
|
-
standard: 1
|
|
13
|
-
};
|
|
14
7
|
export const densityStateInitializer = (state, props) => _extends({}, state, {
|
|
15
|
-
density:
|
|
16
|
-
value: props.density,
|
|
17
|
-
factor: DENSITY_FACTORS[props.density]
|
|
18
|
-
}
|
|
8
|
+
density: props.initialState?.density ?? props.density ?? 'standard'
|
|
19
9
|
});
|
|
20
10
|
export const useGridDensity = (apiRef, props) => {
|
|
21
11
|
const logger = useGridLogger(apiRef, 'useDensity');
|
|
22
|
-
|
|
12
|
+
apiRef.current.registerControlState({
|
|
13
|
+
stateId: 'density',
|
|
14
|
+
propModel: props.density,
|
|
15
|
+
propOnChange: props.onDensityChange,
|
|
16
|
+
stateSelector: gridDensitySelector,
|
|
17
|
+
changeEvent: 'densityChange'
|
|
18
|
+
});
|
|
19
|
+
const setDensity = useEventCallback(newDensity => {
|
|
20
|
+
const currentDensity = gridDensitySelector(apiRef.current.state);
|
|
21
|
+
if (currentDensity === newDensity) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
23
24
|
logger.debug(`Set grid density to ${newDensity}`);
|
|
24
|
-
apiRef.current.setState(state => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
factor: DENSITY_FACTORS[newDensity]
|
|
29
|
-
};
|
|
30
|
-
if (isDeepEqual(currentDensityState, newDensityState)) {
|
|
31
|
-
return state;
|
|
32
|
-
}
|
|
33
|
-
return _extends({}, state, {
|
|
34
|
-
density: newDensityState
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
apiRef.current.forceUpdate();
|
|
38
|
-
}, [logger, apiRef]);
|
|
25
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
26
|
+
density: newDensity
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
39
29
|
React.useEffect(() => {
|
|
40
|
-
|
|
30
|
+
if (props.density) {
|
|
31
|
+
apiRef.current.setDensity(props.density);
|
|
32
|
+
}
|
|
41
33
|
}, [apiRef, props.density]);
|
|
42
34
|
const densityApi = {
|
|
43
35
|
setDensity
|
|
@@ -3,7 +3,7 @@ import { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
4
|
import { GridDimensions } from './gridDimensionsApi';
|
|
5
5
|
import { GridStateInitializer } from '../../utils/useGridInitializeState';
|
|
6
|
-
type RootProps = Pick<DataGridProcessedProps, 'onResize' | 'scrollbarSize' | 'pagination' | 'paginationMode' | 'autoHeight' | 'getRowHeight' | 'rowHeight' | 'columnHeaderHeight'>;
|
|
6
|
+
type RootProps = Pick<DataGridProcessedProps, 'onResize' | 'scrollbarSize' | 'pagination' | 'paginationMode' | 'autoHeight' | 'getRowHeight' | 'rowHeight' | 'resizeThrottleMs' | 'columnHeaderHeight'>;
|
|
7
7
|
export type GridDimensionsState = GridDimensions;
|
|
8
8
|
export declare const dimensionsStateInitializer: GridStateInitializer<RootProps>;
|
|
9
9
|
export declare function useGridDimensions(apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: RootProps): void;
|
|
@@ -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 => {
|
|
@@ -66,7 +67,6 @@ export function useGridDimensions(apiRef, props) {
|
|
|
66
67
|
}));
|
|
67
68
|
});
|
|
68
69
|
const resize = React.useCallback(() => {
|
|
69
|
-
var _previousSize$current, _previousSize$current2;
|
|
70
70
|
const element = apiRef.current.mainElementRef.current;
|
|
71
71
|
if (!element) {
|
|
72
72
|
return;
|
|
@@ -74,8 +74,8 @@ export function useGridDimensions(apiRef, props) {
|
|
|
74
74
|
const computedStyle = ownerWindow(element).getComputedStyle(element);
|
|
75
75
|
const height = parseFloat(computedStyle.height) || 0;
|
|
76
76
|
const width = parseFloat(computedStyle.width) || 0;
|
|
77
|
-
const hasHeightChanged = height !==
|
|
78
|
-
const hasWidthChanged = width !==
|
|
77
|
+
const hasHeightChanged = height !== previousSize.current?.height;
|
|
78
|
+
const hasWidthChanged = width !== previousSize.current?.width;
|
|
79
79
|
if (!previousSize.current || hasHeightChanged || hasWidthChanged) {
|
|
80
80
|
const size = {
|
|
81
81
|
width,
|
|
@@ -106,7 +106,6 @@ export function useGridDimensions(apiRef, props) {
|
|
|
106
106
|
return Math.min(maximumPageSizeWithoutScrollBar, currentPage.rows.length);
|
|
107
107
|
}, [apiRef, props.pagination, props.paginationMode, props.getRowHeight, rowHeight]);
|
|
108
108
|
const updateDimensions = React.useCallback(() => {
|
|
109
|
-
var _apiRef$current$updat, _apiRef$current;
|
|
110
109
|
const rootElement = apiRef.current.rootElementRef.current;
|
|
111
110
|
const pinnedRowsHeight = calculatePinnedRowsHeight(apiRef);
|
|
112
111
|
const scrollbarSize = measureScrollbarSize(rootElement, columnsTotalWidth, props.scrollbarSize);
|
|
@@ -191,7 +190,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
191
190
|
if (newDimensions.viewportInnerSize.width !== prevDimensions.viewportInnerSize.width || newDimensions.viewportInnerSize.height !== prevDimensions.viewportInnerSize.height) {
|
|
192
191
|
apiRef.current.publishEvent('viewportInnerSizeChange', newDimensions.viewportInnerSize);
|
|
193
192
|
}
|
|
194
|
-
|
|
193
|
+
apiRef.current.updateRenderContext?.();
|
|
195
194
|
}, [apiRef, setDimensions, props.scrollbarSize, props.autoHeight, rowsMeta.currentPageTotalHeight, rowHeight, headerHeight, columnsTotalWidth, headersTotalHeight, leftPinnedWidth, rightPinnedWidth]);
|
|
196
195
|
const apiPublic = {
|
|
197
196
|
resize,
|
|
@@ -14,7 +14,7 @@ import { buildWarning } from '../../../utils/warning';
|
|
|
14
14
|
import { gridRowsDataRowIdToIdLookupSelector } from '../rows/gridRowsSelector';
|
|
15
15
|
import { deepClone } from '../../../utils/utils';
|
|
16
16
|
import { GridCellEditStartReasons, GridCellEditStopReasons } from '../../../models/params/gridEditCellParams';
|
|
17
|
-
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop,
|
|
17
|
+
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/#server-side-persistence.'], 'error');
|
|
18
18
|
export const useGridCellEditing = (apiRef, props) => {
|
|
19
19
|
const [cellModesModel, setCellModesModel] = React.useState({});
|
|
20
20
|
const cellModesModelRef = React.useRef(cellModesModel);
|
|
@@ -339,7 +339,6 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
339
339
|
}
|
|
340
340
|
});
|
|
341
341
|
const setCellEditingEditCellValue = React.useCallback(async params => {
|
|
342
|
-
var _editingState$id;
|
|
343
342
|
const {
|
|
344
343
|
id,
|
|
345
344
|
field,
|
|
@@ -389,7 +388,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
389
388
|
newProps.value = column.preProcessEditCellProps ? editingState[id][field].value : parsedValue;
|
|
390
389
|
updateOrDeleteFieldState(id, field, newProps);
|
|
391
390
|
editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
392
|
-
return !
|
|
391
|
+
return !editingState[id]?.[field]?.error;
|
|
393
392
|
}, [apiRef, throwIfNotEditable, throwIfNotInMode, updateOrDeleteFieldState]);
|
|
394
393
|
const getRowWithUpdatedValuesFromCellEditing = React.useCallback((id, field) => {
|
|
395
394
|
const column = apiRef.current.getColumn(field);
|
|
@@ -432,9 +431,8 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
432
431
|
|
|
433
432
|
Object.entries(cellModesModel).forEach(([id, fields]) => {
|
|
434
433
|
Object.entries(fields).forEach(([field, params]) => {
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
const originalId = (_idToIdLookup$id = idToIdLookup[id]) != null ? _idToIdLookup$id : id;
|
|
434
|
+
const prevMode = copyOfPrevCellModes[id]?.[field]?.mode || GridCellModes.View;
|
|
435
|
+
const originalId = idToIdLookup[id] ?? id;
|
|
438
436
|
if (params.mode === GridCellModes.Edit && prevMode === GridCellModes.View) {
|
|
439
437
|
updateStateToStartCellEditMode(_extends({
|
|
440
438
|
id: originalId,
|
|
@@ -106,9 +106,8 @@ export const useGridEditing = (apiRef, props) => {
|
|
|
106
106
|
return props.editMode === GridEditModes.Cell ? apiRef.current.getRowWithUpdatedValuesFromCellEditing(id, field) : apiRef.current.getRowWithUpdatedValuesFromRowEditing(id);
|
|
107
107
|
}, [apiRef, props.editMode]);
|
|
108
108
|
const getEditCellMeta = React.useCallback((id, field) => {
|
|
109
|
-
var _editingState$id$fiel, _editingState$id;
|
|
110
109
|
const editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
111
|
-
return
|
|
110
|
+
return editingState[id]?.[field] ?? null;
|
|
112
111
|
}, [apiRef]);
|
|
113
112
|
const editingSharedApi = {
|
|
114
113
|
isCellEditable,
|
|
@@ -16,7 +16,7 @@ import { gridRowsDataRowIdToIdLookupSelector } from '../rows/gridRowsSelector';
|
|
|
16
16
|
import { deepClone } from '../../../utils/utils';
|
|
17
17
|
import { GridRowEditStopReasons, GridRowEditStartReasons } from '../../../models/params/gridRowParams';
|
|
18
18
|
import { GRID_ACTIONS_COLUMN_TYPE } from '../../../colDef';
|
|
19
|
-
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop,
|
|
19
|
+
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/#server-side-persistence.'], 'error');
|
|
20
20
|
export const useGridRowEditing = (apiRef, props) => {
|
|
21
21
|
const [rowModesModel, setRowModesModel] = React.useState({});
|
|
22
22
|
const rowModesModelRef = React.useRef(rowModesModel);
|
|
@@ -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;
|
|
@@ -76,8 +80,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
76
80
|
// focus we check if the next cell that received focus is from a different row.
|
|
77
81
|
nextFocusedCell.current = null;
|
|
78
82
|
focusTimeout.current = setTimeout(() => {
|
|
79
|
-
|
|
80
|
-
if (((_nextFocusedCell$curr = nextFocusedCell.current) == null ? void 0 : _nextFocusedCell$curr.id) !== params.id) {
|
|
83
|
+
if (nextFocusedCell.current?.id !== params.id) {
|
|
81
84
|
// The row might have been deleted during the click
|
|
82
85
|
if (!apiRef.current.getRow(params.id)) {
|
|
83
86
|
return;
|
|
@@ -87,6 +90,9 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
87
90
|
if (apiRef.current.getRowMode(params.id) === GridRowModes.View) {
|
|
88
91
|
return;
|
|
89
92
|
}
|
|
93
|
+
if (hasFieldsWithErrors(params.id)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
90
96
|
const rowParams = apiRef.current.getRowParams(params.id);
|
|
91
97
|
const newParams = _extends({}, rowParams, {
|
|
92
98
|
field: params.field,
|
|
@@ -95,7 +101,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
95
101
|
apiRef.current.publishEvent('rowEditStop', newParams, event);
|
|
96
102
|
}
|
|
97
103
|
});
|
|
98
|
-
}, [apiRef]);
|
|
104
|
+
}, [apiRef, hasFieldsWithErrors]);
|
|
99
105
|
React.useEffect(() => {
|
|
100
106
|
return () => {
|
|
101
107
|
clearTimeout(focusTimeout.current);
|
|
@@ -141,6 +147,9 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
141
147
|
}
|
|
142
148
|
}
|
|
143
149
|
if (reason) {
|
|
150
|
+
if (reason !== GridRowEditStopReasons.escapeKeyDown && hasFieldsWithErrors(params.id)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
144
153
|
const newParams = _extends({}, apiRef.current.getRowParams(params.id), {
|
|
145
154
|
reason,
|
|
146
155
|
field: params.field
|
|
@@ -175,7 +184,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
175
184
|
apiRef.current.publishEvent('rowEditStart', newParams, event);
|
|
176
185
|
}
|
|
177
186
|
}
|
|
178
|
-
}, [apiRef]);
|
|
187
|
+
}, [apiRef, hasFieldsWithErrors]);
|
|
179
188
|
const handleRowEditStart = React.useCallback(params => {
|
|
180
189
|
const {
|
|
181
190
|
id,
|
|
@@ -359,8 +368,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
359
368
|
prevRowModesModel.current[id].mode = GridRowModes.Edit;
|
|
360
369
|
return;
|
|
361
370
|
}
|
|
362
|
-
|
|
363
|
-
if (hasSomeFieldWithError) {
|
|
371
|
+
if (hasFieldsWithErrors(id)) {
|
|
364
372
|
prevRowModesModel.current[id].mode = GridRowModes.Edit;
|
|
365
373
|
// Revert the mode in the rowModesModel prop back to "edit"
|
|
366
374
|
updateRowInRowModesModel(id, {
|
|
@@ -541,9 +549,8 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
541
549
|
prevRowModesModel.current = deepClone(rowModesModel); // Do a deep-clone because the attributes might be changed later
|
|
542
550
|
|
|
543
551
|
Object.entries(rowModesModel).forEach(([id, params]) => {
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
const originalId = (_idToIdLookup$id = idToIdLookup[id]) != null ? _idToIdLookup$id : id;
|
|
552
|
+
const prevMode = copyOfPrevRowModesModel[id]?.mode || GridRowModes.View;
|
|
553
|
+
const originalId = idToIdLookup[id] ?? id;
|
|
547
554
|
if (params.mode === GridRowModes.Edit && prevMode === GridRowModes.View) {
|
|
548
555
|
updateStateToStartRowEditMode(_extends({
|
|
549
556
|
id: originalId
|
|
@@ -6,6 +6,7 @@ import type { GridApiCommunity } from '../../../../models/api/gridApiCommunity';
|
|
|
6
6
|
export declare const serializeCellValue: (cellParams: GridCellParams, options: {
|
|
7
7
|
delimiterCharacter: string;
|
|
8
8
|
ignoreValueFormatter: boolean;
|
|
9
|
+
shouldAppendQuotes: boolean;
|
|
9
10
|
}) => any;
|
|
10
11
|
interface BuildCSVOptions {
|
|
11
12
|
columns: GridStateColDef[];
|
|
@@ -15,6 +16,7 @@ interface BuildCSVOptions {
|
|
|
15
16
|
includeColumnGroupsHeaders: NonNullable<GridCsvExportOptions['includeColumnGroupsHeaders']>;
|
|
16
17
|
ignoreValueFormatter: boolean;
|
|
17
18
|
apiRef: React.MutableRefObject<GridApiCommunity>;
|
|
19
|
+
shouldAppendQuotes: boolean;
|
|
18
20
|
}
|
|
19
21
|
export declare function buildCSV(options: BuildCSVOptions): string;
|
|
20
22
|
export {};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../../colDef';
|
|
2
2
|
import { buildWarning } from '../../../../utils/warning';
|
|
3
|
-
function sanitizeCellValue(value, delimiterCharacter) {
|
|
3
|
+
function sanitizeCellValue(value, delimiterCharacter, shouldAppendQuotes) {
|
|
4
4
|
if (typeof value === 'string') {
|
|
5
5
|
// Make sure value containing delimiter or line break won't be split into multiple rows
|
|
6
6
|
if ([delimiterCharacter, '\n', '\r', '"'].some(delimiter => value.includes(delimiter))) {
|
|
7
|
-
|
|
7
|
+
if (shouldAppendQuotes) {
|
|
8
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
9
|
+
}
|
|
10
|
+
return `${value.replace(/"/g, '""')}`;
|
|
8
11
|
}
|
|
9
12
|
return value;
|
|
10
13
|
}
|
|
@@ -13,18 +16,17 @@ function sanitizeCellValue(value, delimiterCharacter) {
|
|
|
13
16
|
export const serializeCellValue = (cellParams, options) => {
|
|
14
17
|
const {
|
|
15
18
|
delimiterCharacter,
|
|
16
|
-
ignoreValueFormatter
|
|
19
|
+
ignoreValueFormatter,
|
|
20
|
+
shouldAppendQuotes
|
|
17
21
|
} = options;
|
|
18
22
|
let value;
|
|
19
23
|
if (ignoreValueFormatter) {
|
|
20
|
-
var _cellParams$value2;
|
|
21
24
|
const columnType = cellParams.colDef.type;
|
|
22
25
|
if (columnType === 'number') {
|
|
23
26
|
value = String(cellParams.value);
|
|
24
27
|
} else if (columnType === 'date' || columnType === 'dateTime') {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} else if (typeof ((_cellParams$value2 = cellParams.value) == null ? void 0 : _cellParams$value2.toString) === 'function') {
|
|
28
|
+
value = cellParams.value?.toISOString();
|
|
29
|
+
} else if (typeof cellParams.value?.toString === 'function') {
|
|
28
30
|
value = cellParams.value.toString();
|
|
29
31
|
} else {
|
|
30
32
|
value = cellParams.value;
|
|
@@ -32,7 +34,7 @@ export const serializeCellValue = (cellParams, options) => {
|
|
|
32
34
|
} else {
|
|
33
35
|
value = cellParams.formattedValue;
|
|
34
36
|
}
|
|
35
|
-
return sanitizeCellValue(value, delimiterCharacter);
|
|
37
|
+
return sanitizeCellValue(value, delimiterCharacter, shouldAppendQuotes);
|
|
36
38
|
};
|
|
37
39
|
const objectFormattedValueWarning = buildWarning(['MUI X: When the value of a field is an object or a `renderCell` is provided, the CSV export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.']);
|
|
38
40
|
class CSVRow {
|
|
@@ -49,7 +51,7 @@ class CSVRow {
|
|
|
49
51
|
if (value === null || value === undefined) {
|
|
50
52
|
this.rowString += '';
|
|
51
53
|
} else if (typeof this.options.sanitizeCellValue === 'function') {
|
|
52
|
-
this.rowString += this.options.sanitizeCellValue(value, this.options.delimiterCharacter);
|
|
54
|
+
this.rowString += this.options.sanitizeCellValue(value, this.options.delimiterCharacter, this.options.shouldAppendQuotes);
|
|
53
55
|
} else {
|
|
54
56
|
this.rowString += value;
|
|
55
57
|
}
|
|
@@ -64,10 +66,12 @@ const serializeRow = ({
|
|
|
64
66
|
columns,
|
|
65
67
|
getCellParams,
|
|
66
68
|
delimiterCharacter,
|
|
67
|
-
ignoreValueFormatter
|
|
69
|
+
ignoreValueFormatter,
|
|
70
|
+
shouldAppendQuotes
|
|
68
71
|
}) => {
|
|
69
72
|
const row = new CSVRow({
|
|
70
|
-
delimiterCharacter
|
|
73
|
+
delimiterCharacter,
|
|
74
|
+
shouldAppendQuotes
|
|
71
75
|
});
|
|
72
76
|
columns.forEach(column => {
|
|
73
77
|
const cellParams = getCellParams(id, column.field);
|
|
@@ -78,7 +82,8 @@ const serializeRow = ({
|
|
|
78
82
|
}
|
|
79
83
|
row.addValue(serializeCellValue(cellParams, {
|
|
80
84
|
delimiterCharacter,
|
|
81
|
-
ignoreValueFormatter
|
|
85
|
+
ignoreValueFormatter,
|
|
86
|
+
shouldAppendQuotes
|
|
82
87
|
}));
|
|
83
88
|
});
|
|
84
89
|
return row.getRowString();
|
|
@@ -91,14 +96,16 @@ export function buildCSV(options) {
|
|
|
91
96
|
includeHeaders,
|
|
92
97
|
includeColumnGroupsHeaders,
|
|
93
98
|
ignoreValueFormatter,
|
|
94
|
-
apiRef
|
|
99
|
+
apiRef,
|
|
100
|
+
shouldAppendQuotes
|
|
95
101
|
} = options;
|
|
96
102
|
const CSVBody = rowIds.reduce((acc, id) => `${acc}${serializeRow({
|
|
97
103
|
id,
|
|
98
104
|
columns,
|
|
99
105
|
getCellParams: apiRef.current.getCellParams,
|
|
100
106
|
delimiterCharacter,
|
|
101
|
-
ignoreValueFormatter
|
|
107
|
+
ignoreValueFormatter,
|
|
108
|
+
shouldAppendQuotes
|
|
102
109
|
})}\r\n`, '').trim();
|
|
103
110
|
if (!includeHeaders) {
|
|
104
111
|
return CSVBody;
|
|
@@ -117,7 +124,8 @@ export function buildCSV(options) {
|
|
|
117
124
|
for (let i = 0; i < maxColumnGroupsDepth; i += 1) {
|
|
118
125
|
const headerGroupRow = new CSVRow({
|
|
119
126
|
delimiterCharacter,
|
|
120
|
-
sanitizeCellValue
|
|
127
|
+
sanitizeCellValue,
|
|
128
|
+
shouldAppendQuotes
|
|
121
129
|
});
|
|
122
130
|
headerRows.push(headerGroupRow);
|
|
123
131
|
filteredColumns.forEach(column => {
|
|
@@ -129,7 +137,8 @@ export function buildCSV(options) {
|
|
|
129
137
|
}
|
|
130
138
|
const mainHeaderRow = new CSVRow({
|
|
131
139
|
delimiterCharacter,
|
|
132
|
-
sanitizeCellValue
|
|
140
|
+
sanitizeCellValue,
|
|
141
|
+
shouldAppendQuotes
|
|
133
142
|
});
|
|
134
143
|
filteredColumns.forEach(column => {
|
|
135
144
|
mainHeaderRow.addValue(column.headerName || column.field);
|
|
@@ -17,15 +17,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
17
17
|
export const useGridCsvExport = (apiRef, props) => {
|
|
18
18
|
const logger = useGridLogger(apiRef, 'useGridCsvExport');
|
|
19
19
|
const ignoreValueFormatterProp = props.ignoreValueFormatterDuringExport;
|
|
20
|
-
const ignoreValueFormatter = (typeof ignoreValueFormatterProp === 'object' ? ignoreValueFormatterProp
|
|
20
|
+
const ignoreValueFormatter = (typeof ignoreValueFormatterProp === 'object' ? ignoreValueFormatterProp?.csvExport : ignoreValueFormatterProp) || false;
|
|
21
21
|
const getDataAsCsv = React.useCallback((options = {}) => {
|
|
22
|
-
var _options$getRowsToExp, _options$includeHeade, _options$includeColum;
|
|
23
22
|
logger.debug(`Get data as CSV`);
|
|
24
23
|
const exportedColumns = getColumnsToExport({
|
|
25
24
|
apiRef,
|
|
26
25
|
options
|
|
27
26
|
});
|
|
28
|
-
const getRowsToExport =
|
|
27
|
+
const getRowsToExport = options.getRowsToExport ?? defaultGetRowsToExport;
|
|
29
28
|
const exportedRowIds = getRowsToExport({
|
|
30
29
|
apiRef
|
|
31
30
|
});
|
|
@@ -33,19 +32,20 @@ export const useGridCsvExport = (apiRef, props) => {
|
|
|
33
32
|
columns: exportedColumns,
|
|
34
33
|
rowIds: exportedRowIds,
|
|
35
34
|
delimiterCharacter: options.delimiter || ',',
|
|
36
|
-
includeHeaders:
|
|
37
|
-
includeColumnGroupsHeaders:
|
|
35
|
+
includeHeaders: options.includeHeaders ?? true,
|
|
36
|
+
includeColumnGroupsHeaders: options.includeColumnGroupsHeaders ?? true,
|
|
38
37
|
ignoreValueFormatter,
|
|
39
|
-
apiRef
|
|
38
|
+
apiRef,
|
|
39
|
+
shouldAppendQuotes: options.shouldAppendQuotes ?? true
|
|
40
40
|
});
|
|
41
41
|
}, [logger, apiRef, ignoreValueFormatter]);
|
|
42
42
|
const exportDataAsCsv = React.useCallback(options => {
|
|
43
43
|
logger.debug(`Export data as CSV`);
|
|
44
44
|
const csv = getDataAsCsv(options);
|
|
45
|
-
const blob = new Blob([options
|
|
45
|
+
const blob = new Blob([options?.utf8WithBom ? new Uint8Array([0xef, 0xbb, 0xbf]) : '', csv], {
|
|
46
46
|
type: 'text/csv'
|
|
47
47
|
});
|
|
48
|
-
exportAs(blob, 'csv', options
|
|
48
|
+
exportAs(blob, 'csv', options?.fileName);
|
|
49
49
|
}, [logger, getDataAsCsv]);
|
|
50
50
|
const csvExportApi = {
|
|
51
51
|
getDataAsCsv,
|
|
@@ -57,8 +57,7 @@ export const useGridCsvExport = (apiRef, props) => {
|
|
|
57
57
|
* PRE-PROCESSING
|
|
58
58
|
*/
|
|
59
59
|
const addExportMenuButtons = React.useCallback((initialValue, options) => {
|
|
60
|
-
|
|
61
|
-
if ((_options$csvOptions = options.csvOptions) != null && _options$csvOptions.disableToolbarButton) {
|
|
60
|
+
if (options.csvOptions?.disableToolbarButton) {
|
|
62
61
|
return initialValue;
|
|
63
62
|
}
|
|
64
63
|
return [...initialValue, {
|
|
@@ -75,7 +75,6 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
75
75
|
apiRef.current.setRows(newRows);
|
|
76
76
|
}, [apiRef]);
|
|
77
77
|
const handlePrintWindowLoad = React.useCallback((printWindow, options) => {
|
|
78
|
-
var _querySelector, _querySelector2;
|
|
79
78
|
const normalizeOptions = _extends({
|
|
80
79
|
copyStyles: true,
|
|
81
80
|
hideToolbar: false,
|
|
@@ -96,16 +95,14 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
96
95
|
|
|
97
96
|
// See https://support.google.com/chrome/thread/191619088?hl=en&msgid=193009642
|
|
98
97
|
gridClone.style.contain = 'size';
|
|
99
|
-
let gridToolbarElementHeight =
|
|
100
|
-
let gridFooterElementHeight =
|
|
98
|
+
let gridToolbarElementHeight = gridRootElement.querySelector(`.${gridClasses.toolbarContainer}`)?.offsetHeight || 0;
|
|
99
|
+
let gridFooterElementHeight = gridRootElement.querySelector(`.${gridClasses.footerContainer}`)?.offsetHeight || 0;
|
|
101
100
|
if (normalizeOptions.hideToolbar) {
|
|
102
|
-
|
|
103
|
-
(_gridClone$querySelec = gridClone.querySelector(`.${gridClasses.toolbarContainer}`)) == null || _gridClone$querySelec.remove();
|
|
101
|
+
gridClone.querySelector(`.${gridClasses.toolbarContainer}`)?.remove();
|
|
104
102
|
gridToolbarElementHeight = 0;
|
|
105
103
|
}
|
|
106
104
|
if (normalizeOptions.hideFooter) {
|
|
107
|
-
|
|
108
|
-
(_gridClone$querySelec2 = gridClone.querySelector(`.${gridClasses.footerContainer}`)) == null || _gridClone$querySelec2.remove();
|
|
105
|
+
gridClone.querySelector(`.${gridClasses.footerContainer}`)?.remove();
|
|
109
106
|
gridFooterElementHeight = 0;
|
|
110
107
|
}
|
|
111
108
|
|
|
@@ -186,13 +183,12 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
186
183
|
}
|
|
187
184
|
}, [apiRef, doc, props.columnHeaderHeight]);
|
|
188
185
|
const handlePrintWindowAfterPrint = React.useCallback(printWindow => {
|
|
189
|
-
var _previousGridState$cu;
|
|
190
186
|
// Remove the print iframe
|
|
191
187
|
doc.current.body.removeChild(printWindow);
|
|
192
188
|
|
|
193
189
|
// Revert grid to previous state
|
|
194
190
|
apiRef.current.restoreState(previousGridState.current || {});
|
|
195
|
-
if (!
|
|
191
|
+
if (!previousGridState.current?.columns?.columnVisibilityModel) {
|
|
196
192
|
// if the apiRef.current.exportState(); did not exported the column visibility, we update it
|
|
197
193
|
apiRef.current.setColumnVisibilityModel(previousColumnVisibility.current);
|
|
198
194
|
}
|
|
@@ -205,7 +201,6 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
205
201
|
previousRows.current = [];
|
|
206
202
|
}, [apiRef]);
|
|
207
203
|
const exportDataAsPrint = React.useCallback(async options => {
|
|
208
|
-
var _options$getRowsToExp;
|
|
209
204
|
logger.debug(`Export data as Print`);
|
|
210
205
|
if (!apiRef.current.rootElementRef.current) {
|
|
211
206
|
throw new Error('MUI X: No grid root element available.');
|
|
@@ -229,11 +224,11 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
229
224
|
}));
|
|
230
225
|
apiRef.current.forceUpdate();
|
|
231
226
|
}
|
|
232
|
-
await updateGridColumnsForPrint(options
|
|
233
|
-
updateGridRowsForPrint(
|
|
227
|
+
await updateGridColumnsForPrint(options?.fields, options?.allColumns, options?.includeCheckboxes);
|
|
228
|
+
updateGridRowsForPrint(options?.getRowsToExport ?? defaultGetRowsToExport);
|
|
234
229
|
apiRef.current.unstable_setVirtualization(false);
|
|
235
230
|
await raf(); // wait for the state changes to take action
|
|
236
|
-
const printWindow = buildPrintWindow(options
|
|
231
|
+
const printWindow = buildPrintWindow(options?.fileName);
|
|
237
232
|
if (process.env.NODE_ENV === 'test') {
|
|
238
233
|
doc.current.body.appendChild(printWindow);
|
|
239
234
|
// In test env, run the all pipeline without waiting for loading
|
|
@@ -262,8 +257,7 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
262
257
|
* PRE-PROCESSING
|
|
263
258
|
*/
|
|
264
259
|
const addExportMenuButtons = React.useCallback((initialValue, options) => {
|
|
265
|
-
|
|
266
|
-
if ((_options$printOptions = options.printOptions) != null && _options$printOptions.disableToolbarButton) {
|
|
260
|
+
if (options.printOptions?.disableToolbarButton) {
|
|
267
261
|
return initialValue;
|
|
268
262
|
}
|
|
269
263
|
return [...initialValue, {
|
|
@@ -21,14 +21,13 @@ export const getColumnsToExport = ({
|
|
|
21
21
|
export const defaultGetRowsToExport = ({
|
|
22
22
|
apiRef
|
|
23
23
|
}) => {
|
|
24
|
-
var _pinnedRows$top, _pinnedRows$bottom;
|
|
25
24
|
const filteredSortedRowIds = gridFilteredSortedRowIdsSelector(apiRef);
|
|
26
25
|
const rowTree = gridRowTreeSelector(apiRef);
|
|
27
26
|
const selectedRows = apiRef.current.getSelectedRows();
|
|
28
27
|
const bodyRows = filteredSortedRowIds.filter(id => rowTree[id].type !== 'footer');
|
|
29
28
|
const pinnedRows = gridPinnedRowsSelector(apiRef);
|
|
30
|
-
const topPinnedRowsIds =
|
|
31
|
-
const bottomPinnedRowsIds =
|
|
29
|
+
const topPinnedRowsIds = pinnedRows?.top?.map(row => row.id) || [];
|
|
30
|
+
const bottomPinnedRowsIds = pinnedRows?.bottom?.map(row => row.id) || [];
|
|
32
31
|
bodyRows.unshift(...topPinnedRowsIds);
|
|
33
32
|
bodyRows.push(...bottomPinnedRowsIds);
|
|
34
33
|
if (selectedRows.size > 0) {
|
|
@@ -74,10 +74,7 @@ export const gridFilteredSortedTopLevelRowEntriesSelector = createSelectorMemoiz
|
|
|
74
74
|
if (rowTreeDepth < 2) {
|
|
75
75
|
return visibleSortedRows;
|
|
76
76
|
}
|
|
77
|
-
return visibleSortedRows.filter(row =>
|
|
78
|
-
var _rowTree$row$id;
|
|
79
|
-
return ((_rowTree$row$id = rowTree[row.id]) == null ? void 0 : _rowTree$row$id.depth) === 0;
|
|
80
|
-
});
|
|
77
|
+
return visibleSortedRows.filter(row => rowTree[row.id]?.depth === 0);
|
|
81
78
|
});
|
|
82
79
|
|
|
83
80
|
/**
|
|
@@ -96,24 +93,20 @@ export const gridFilteredTopLevelRowCountSelector = createSelector(gridFilteredS
|
|
|
96
93
|
* @category Filtering
|
|
97
94
|
* @ignore - do not document.
|
|
98
95
|
*/
|
|
99
|
-
export const gridFilterActiveItemsSelector = createSelectorMemoized(gridFilterModelSelector, gridColumnLookupSelector, (filterModel, columnLookup) => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
return !filterOperator.InputComponent || item.value != null && ((_item$value = item.value) == null ? void 0 : _item$value.toString()) !== '';
|
|
115
|
-
});
|
|
116
|
-
});
|
|
96
|
+
export const gridFilterActiveItemsSelector = createSelectorMemoized(gridFilterModelSelector, gridColumnLookupSelector, (filterModel, columnLookup) => filterModel.items?.filter(item => {
|
|
97
|
+
if (!item.field) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const column = columnLookup[item.field];
|
|
101
|
+
if (!column?.filterOperators || column?.filterOperators?.length === 0) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const filterOperator = column.filterOperators.find(operator => operator.value === item.operator);
|
|
105
|
+
if (!filterOperator) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return !filterOperator.InputComponent || item.value != null && item.value?.toString() !== '';
|
|
109
|
+
}));
|
|
117
110
|
/**
|
|
118
111
|
* @category Filtering
|
|
119
112
|
* @ignore - do not document.
|