@mui/x-data-grid 7.0.0-beta.6 → 7.0.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 +311 -12
- package/DataGrid/DataGrid.js +57 -17
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +6 -7
- package/README.md +1 -1
- package/components/GridColumnHeaders.d.ts +1 -2
- package/components/GridColumnHeaders.js +6 -17
- package/components/GridFooter.js +2 -3
- package/components/GridHeader.js +1 -2
- package/components/GridHeaders.js +1 -4
- package/components/GridPagination.d.ts +6 -5
- package/components/GridPagination.js +14 -11
- package/components/GridRow.d.ts +1 -1
- package/components/GridRow.js +17 -36
- package/components/GridScrollArea.d.ts +10 -0
- package/components/GridScrollArea.js +150 -0
- 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.d.ts +7 -0
- package/components/cell/GridCell.js +18 -11
- 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/GridBaseColumnHeaders.js +1 -0
- package/components/columnHeaders/GridColumnGroupHeader.d.ts +5 -0
- package/components/columnHeaders/GridColumnGroupHeader.js +22 -13
- package/components/columnHeaders/GridColumnHeaderFilterIconButton.js +2 -3
- package/components/columnHeaders/GridColumnHeaderItem.d.ts +5 -0
- package/components/columnHeaders/GridColumnHeaderItem.js +26 -12
- package/components/columnHeaders/GridColumnHeaderSortIcon.js +1 -2
- package/components/columnHeaders/GridColumnHeaderTitle.js +2 -3
- package/components/columnHeaders/GridGenericColumnHeaderItem.d.ts +1 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +7 -6
- 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/containers/GridRootStyles.js +12 -20
- 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 +4 -5
- package/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/components/virtualization/GridVirtualScroller.js +6 -1
- package/components/virtualization/GridVirtualScrollerContent.js +1 -2
- package/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/components/virtualization/GridVirtualScrollerRenderZone.js +1 -2
- package/constants/gridClasses.d.ts +6 -32
- package/constants/gridClasses.js +1 -1
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -1
- 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.d.ts +23 -7
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +186 -101
- package/hooks/features/columnMenu/useGridColumnMenuSlots.js +2 -2
- package/hooks/features/columnResize/columnResizeSelector.d.ts +3 -0
- package/hooks/features/columnResize/columnResizeSelector.js +3 -0
- package/hooks/features/columnResize/columnResizeState.d.ts +3 -0
- package/hooks/features/columnResize/columnResizeState.js +1 -0
- package/hooks/features/columnResize/gridColumnResizeApi.d.ts +44 -0
- package/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
- package/hooks/features/columnResize/index.d.ts +3 -0
- package/hooks/features/columnResize/index.js +3 -0
- package/hooks/features/columnResize/useGridColumnResize.d.ts +10 -0
- package/hooks/features/columnResize/useGridColumnResize.js +553 -0
- package/hooks/features/columns/gridColumnsSelector.js +1 -2
- package/hooks/features/columns/gridColumnsUtils.d.ts +0 -9
- package/hooks/features/columns/gridColumnsUtils.js +5 -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.js +7 -10
- package/hooks/features/editing/useGridCellEditing.js +25 -8
- package/hooks/features/editing/useGridEditing.js +1 -2
- package/hooks/features/editing/useGridRowEditing.js +4 -6
- 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 +17 -22
- 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.d.ts +1 -0
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +3 -0
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +23 -5
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -2
- package/hooks/features/pagination/gridPaginationInterfaces.d.ts +19 -2
- package/hooks/features/pagination/gridPaginationSelector.d.ts +5 -0
- package/hooks/features/pagination/gridPaginationSelector.js +9 -4
- package/hooks/features/pagination/useGridPagination.d.ts +1 -6
- package/hooks/features/pagination/useGridPagination.js +9 -158
- package/hooks/features/pagination/useGridPaginationModel.d.ts +11 -0
- package/hooks/features/pagination/useGridPaginationModel.js +165 -0
- package/hooks/features/pagination/useGridRowCount.d.ts +8 -0
- package/hooks/features/pagination/useGridRowCount.js +94 -0
- 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 +3 -4
- package/hooks/features/sorting/gridSortingSelector.js +4 -7
- package/hooks/features/sorting/useGridSorting.js +8 -14
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +4 -4
- package/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +3 -3
- package/hooks/features/virtualization/useGridVirtualScroller.js +220 -71
- package/hooks/utils/useGridApiEventHandler.js +5 -10
- package/hooks/utils/useGridNativeEventListener.js +1 -2
- package/hooks/utils/useLazyRef.d.ts +1 -2
- package/hooks/utils/useLazyRef.js +1 -11
- package/hooks/utils/useOnMount.d.ts +1 -2
- package/hooks/utils/useOnMount.js +1 -7
- package/hooks/utils/useTimeout.d.ts +1 -11
- package/hooks/utils/useTimeout.js +1 -36
- package/index.js +1 -1
- package/internals/index.d.ts +3 -1
- package/internals/index.js +2 -1
- package/internals/utils/getPinnedCellOffset.d.ts +3 -0
- package/internals/utils/getPinnedCellOffset.js +17 -0
- package/internals/utils/useProps.js +1 -2
- package/joy/joySlots.js +18 -63
- package/locales/jaJP.js +3 -4
- package/material/index.js +0 -2
- package/models/api/gridApiCommon.d.ts +3 -3
- package/models/api/gridCoreApi.d.ts +1 -5
- 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 +13 -0
- package/models/gridExport.d.ts +6 -0
- package/models/gridHeaderFilteringModel.d.ts +1 -0
- package/models/gridSlotsComponent.d.ts +0 -5
- package/models/gridStateCommunity.d.ts +3 -0
- package/models/params/gridScrollParams.d.ts +5 -3
- package/models/props/DataGridProps.d.ts +58 -28
- package/modern/DataGrid/DataGrid.js +57 -17
- package/modern/DataGrid/useDataGridComponent.js +3 -0
- package/modern/DataGrid/useDataGridProps.js +6 -7
- package/modern/components/GridColumnHeaders.js +6 -17
- package/modern/components/GridHeaders.js +1 -4
- package/modern/components/GridPagination.js +13 -6
- package/modern/components/GridRow.js +4 -19
- package/modern/components/GridScrollArea.js +150 -0
- 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/cell/GridCell.js +11 -3
- package/modern/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/modern/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/modern/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/modern/components/containers/GridRoot.js +3 -3
- package/modern/components/containers/GridRootStyles.js +12 -20
- 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/virtualization/GridVirtualScrollbar.js +4 -0
- package/modern/components/virtualization/GridVirtualScroller.js +6 -1
- package/modern/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/modern/constants/gridClasses.js +1 -1
- package/modern/hooks/features/clipboard/useGridClipboard.js +4 -2
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +184 -97
- package/modern/hooks/features/columnResize/columnResizeSelector.js +3 -0
- package/modern/hooks/features/columnResize/columnResizeState.js +1 -0
- package/modern/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
- package/modern/hooks/features/columnResize/index.js +3 -0
- package/modern/hooks/features/columnResize/useGridColumnResize.js +553 -0
- package/modern/hooks/features/columns/gridColumnsUtils.js +4 -20
- 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 +4 -5
- package/modern/hooks/features/editing/useGridCellEditing.js +22 -3
- package/modern/hooks/features/editing/useGridRowEditing.js +1 -1
- package/modern/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/modern/hooks/features/export/useGridCsvExport.js +2 -1
- package/modern/hooks/features/export/useGridPrintExport.js +8 -7
- package/modern/hooks/features/filter/gridFilterUtils.js +1 -1
- package/modern/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +3 -0
- package/modern/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
- package/modern/hooks/features/index.js +1 -0
- package/modern/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/modern/hooks/features/pagination/useGridPagination.js +8 -149
- package/modern/hooks/features/pagination/useGridPaginationModel.js +165 -0
- package/modern/hooks/features/pagination/useGridRowCount.js +94 -0
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +3 -2
- package/modern/hooks/features/scroll/useGridScroll.js +1 -1
- package/modern/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- package/modern/hooks/utils/useLazyRef.js +1 -11
- package/modern/hooks/utils/useOnMount.js +1 -7
- package/modern/hooks/utils/useTimeout.js +1 -36
- package/modern/index.js +1 -1
- package/modern/internals/index.js +2 -1
- package/modern/internals/utils/getPinnedCellOffset.js +17 -0
- package/modern/joy/joySlots.js +11 -50
- package/modern/locales/jaJP.js +3 -4
- package/modern/material/index.js +0 -2
- package/modern/models/api/index.js +0 -1
- package/modern/utils/cellBorderUtils.js +8 -0
- package/modern/utils/createSelector.js +1 -1
- package/modern/utils/domUtils.js +144 -0
- package/modern/utils/keyboardUtils.js +1 -1
- package/node/DataGrid/DataGrid.js +57 -17
- package/node/DataGrid/useDataGridComponent.js +3 -0
- package/node/DataGrid/useDataGridProps.js +6 -7
- package/node/components/GridColumnHeaders.js +6 -16
- package/node/components/GridHeaders.js +1 -4
- package/node/components/GridPagination.js +10 -4
- package/node/components/GridRow.js +3 -18
- package/node/components/GridScrollArea.js +158 -0
- 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/cell/GridCell.js +12 -4
- package/node/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/node/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/node/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/node/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/node/components/containers/GridRoot.js +2 -2
- package/node/components/containers/GridRootStyles.js +12 -20
- 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/virtualization/GridVirtualScrollbar.js +4 -0
- package/node/components/virtualization/GridVirtualScroller.js +6 -1
- package/node/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/node/constants/gridClasses.js +1 -1
- package/node/hooks/features/clipboard/useGridClipboard.js +4 -2
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +190 -103
- package/node/hooks/features/columnResize/columnResizeSelector.js +10 -0
- package/node/hooks/features/columnResize/columnResizeState.js +5 -0
- package/node/hooks/features/columnResize/gridColumnResizeApi.js +16 -0
- package/node/hooks/features/columnResize/index.js +38 -0
- package/node/hooks/features/columnResize/useGridColumnResize.js +564 -0
- package/node/hooks/features/columns/gridColumnsUtils.js +4 -21
- 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 +4 -5
- package/node/hooks/features/editing/useGridCellEditing.js +22 -3
- package/node/hooks/features/editing/useGridRowEditing.js +1 -1
- package/node/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/node/hooks/features/export/useGridCsvExport.js +2 -1
- package/node/hooks/features/export/useGridPrintExport.js +8 -7
- package/node/hooks/features/filter/gridFilterUtils.js +1 -1
- package/node/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +4 -1
- package/node/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
- package/node/hooks/features/index.js +11 -0
- package/node/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/node/hooks/features/pagination/useGridPagination.js +9 -153
- package/node/hooks/features/pagination/useGridPaginationModel.js +176 -0
- package/node/hooks/features/pagination/useGridRowCount.js +103 -0
- package/node/hooks/features/rowSelection/useGridRowSelection.js +2 -1
- package/node/hooks/features/scroll/useGridScroll.js +1 -1
- package/node/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- package/node/hooks/utils/useLazyRef.js +7 -13
- package/node/hooks/utils/useOnMount.js +8 -10
- package/node/hooks/utils/useTimeout.js +7 -37
- package/node/index.js +1 -1
- package/node/internals/index.js +27 -8
- package/node/internals/utils/getPinnedCellOffset.js +24 -0
- package/node/joy/joySlots.js +11 -50
- package/node/locales/jaJP.js +3 -4
- package/node/material/index.js +0 -2
- package/node/models/api/index.js +0 -11
- package/node/utils/cellBorderUtils.js +16 -0
- package/node/utils/createSelector.js +1 -1
- package/node/utils/domUtils.js +155 -0
- package/node/utils/keyboardUtils.js +1 -1
- package/package.json +4 -4
- package/utils/cellBorderUtils.d.ts +3 -0
- package/utils/cellBorderUtils.js +8 -0
- package/utils/createSelector.js +9 -9
- package/utils/domUtils.d.ts +14 -1
- package/utils/domUtils.js +144 -0
- package/utils/getGridLocalization.js +9 -12
- package/utils/keyboardUtils.js +1 -1
- package/components/columnHeaders/GridColumnHeadersInner.d.ts +0 -8
- package/components/columnHeaders/GridColumnHeadersInner.js +0 -58
- package/modern/components/columnHeaders/GridColumnHeadersInner.js +0 -58
- package/node/components/columnHeaders/GridColumnHeadersInner.js +0 -67
|
@@ -10,19 +10,18 @@ import { hydrateColumnsWidth, createColumnsState, COLUMNS_DIMENSION_PROPERTIES }
|
|
|
10
10
|
import { GridPreferencePanelsValue } from '../preferencesPanel';
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
12
|
export const columnsStateInitializer = (state, props, apiRef) => {
|
|
13
|
-
var _props$initialState, _ref, _props$columnVisibili, _props$initialState2, _state$pinnedColumns;
|
|
14
13
|
const columnsState = createColumnsState({
|
|
15
14
|
apiRef,
|
|
16
15
|
columnsToUpsert: props.columns,
|
|
17
|
-
initialState:
|
|
18
|
-
columnVisibilityModel:
|
|
16
|
+
initialState: props.initialState?.columns,
|
|
17
|
+
columnVisibilityModel: props.columnVisibilityModel ?? props.initialState?.columns?.columnVisibilityModel ?? {},
|
|
19
18
|
keepOnlyColumnsToUpsert: true
|
|
20
19
|
});
|
|
21
20
|
return _extends({}, state, {
|
|
22
21
|
columns: columnsState,
|
|
23
22
|
// In pro/premium, this part of the state is defined. We give it an empty but defined value
|
|
24
23
|
// for the community version.
|
|
25
|
-
pinnedColumns:
|
|
24
|
+
pinnedColumns: state.pinnedColumns ?? EMPTY_PINNED_COLUMN_FIELDS
|
|
26
25
|
});
|
|
27
26
|
};
|
|
28
27
|
|
|
@@ -32,7 +31,6 @@ export const columnsStateInitializer = (state, props, apiRef) => {
|
|
|
32
31
|
* TODO: Impossible priority - useGridParamsApi also needs to be after useGridColumns
|
|
33
32
|
*/
|
|
34
33
|
export function useGridColumns(apiRef, props) {
|
|
35
|
-
var _props$initialState4, _props$slotProps2;
|
|
36
34
|
const logger = useGridLogger(apiRef, 'useGridColumns');
|
|
37
35
|
const previousColumnsProp = React.useRef(props.columns);
|
|
38
36
|
apiRef.current.registerControlState({
|
|
@@ -43,11 +41,10 @@ export function useGridColumns(apiRef, props) {
|
|
|
43
41
|
changeEvent: 'columnVisibilityModelChange'
|
|
44
42
|
});
|
|
45
43
|
const setGridColumnsState = React.useCallback(columnsState => {
|
|
46
|
-
var _apiRef$current$updat, _apiRef$current;
|
|
47
44
|
logger.debug('Updating columns state.');
|
|
48
45
|
apiRef.current.setState(mergeColumnsState(columnsState));
|
|
49
46
|
apiRef.current.publishEvent('columnsChange', columnsState.orderedFields);
|
|
50
|
-
|
|
47
|
+
apiRef.current.updateRenderContext?.();
|
|
51
48
|
apiRef.current.forceUpdate();
|
|
52
49
|
}, [logger, apiRef]);
|
|
53
50
|
|
|
@@ -68,7 +65,6 @@ export function useGridColumns(apiRef, props) {
|
|
|
68
65
|
const setColumnVisibilityModel = React.useCallback(model => {
|
|
69
66
|
const currentModel = gridColumnVisibilityModelSelector(apiRef);
|
|
70
67
|
if (currentModel !== model) {
|
|
71
|
-
var _apiRef$current$updat2, _apiRef$current2;
|
|
72
68
|
apiRef.current.setState(state => _extends({}, state, {
|
|
73
69
|
columns: createColumnsState({
|
|
74
70
|
apiRef,
|
|
@@ -78,7 +74,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
78
74
|
keepOnlyColumnsToUpsert: false
|
|
79
75
|
})
|
|
80
76
|
}));
|
|
81
|
-
|
|
77
|
+
apiRef.current.updateRenderContext?.();
|
|
82
78
|
apiRef.current.forceUpdate();
|
|
83
79
|
}
|
|
84
80
|
}, [apiRef]);
|
|
@@ -92,9 +88,8 @@ export function useGridColumns(apiRef, props) {
|
|
|
92
88
|
setGridColumnsState(columnsState);
|
|
93
89
|
}, [apiRef, setGridColumnsState]);
|
|
94
90
|
const setColumnVisibility = React.useCallback((field, isVisible) => {
|
|
95
|
-
var _columnVisibilityMode;
|
|
96
91
|
const columnVisibilityModel = gridColumnVisibilityModelSelector(apiRef);
|
|
97
|
-
const isCurrentlyVisible =
|
|
92
|
+
const isCurrentlyVisible = columnVisibilityModel[field] ?? true;
|
|
98
93
|
if (isVisible !== isCurrentlyVisible) {
|
|
99
94
|
const newModel = _extends({}, columnVisibilityModel, {
|
|
100
95
|
[field]: isVisible
|
|
@@ -167,7 +162,6 @@ export function useGridColumns(apiRef, props) {
|
|
|
167
162
|
* PRE-PROCESSING
|
|
168
163
|
*/
|
|
169
164
|
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
170
|
-
var _props$initialState$c, _props$initialState3;
|
|
171
165
|
const columnsStateToExport = {};
|
|
172
166
|
const columnVisibilityModelToExport = gridColumnVisibilityModelSelector(apiRef);
|
|
173
167
|
const shouldExportColumnVisibilityModel =
|
|
@@ -177,7 +171,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
177
171
|
props.columnVisibilityModel != null ||
|
|
178
172
|
// Always export if the model has been initialized
|
|
179
173
|
// TODO v6 Do a nullish check instead to export even if the initial model equals "{}"
|
|
180
|
-
Object.keys(
|
|
174
|
+
Object.keys(props.initialState?.columns?.columnVisibilityModel ?? {}).length > 0 ||
|
|
181
175
|
// Always export if the model is not empty
|
|
182
176
|
Object.keys(columnVisibilityModelToExport).length > 0;
|
|
183
177
|
if (shouldExportColumnVisibilityModel) {
|
|
@@ -205,10 +199,9 @@ export function useGridColumns(apiRef, props) {
|
|
|
205
199
|
return _extends({}, prevState, {
|
|
206
200
|
columns: columnsStateToExport
|
|
207
201
|
});
|
|
208
|
-
}, [apiRef, props.columnVisibilityModel,
|
|
202
|
+
}, [apiRef, props.columnVisibilityModel, props.initialState?.columns]);
|
|
209
203
|
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
210
|
-
|
|
211
|
-
const columnVisibilityModelToImport = (_context$stateToResto = context.stateToRestore.columns) == null ? void 0 : _context$stateToResto.columnVisibilityModel;
|
|
204
|
+
const columnVisibilityModelToImport = context.stateToRestore.columns?.columnVisibilityModel;
|
|
212
205
|
const initialState = context.stateToRestore.columns;
|
|
213
206
|
if (columnVisibilityModelToImport == null && initialState == null) {
|
|
214
207
|
return params;
|
|
@@ -228,12 +221,11 @@ export function useGridColumns(apiRef, props) {
|
|
|
228
221
|
}, [apiRef]);
|
|
229
222
|
const preferencePanelPreProcessing = React.useCallback((initialValue, value) => {
|
|
230
223
|
if (value === GridPreferencePanelsValue.columns) {
|
|
231
|
-
var _props$slotProps;
|
|
232
224
|
const ColumnsPanel = props.slots.columnsPanel;
|
|
233
|
-
return /*#__PURE__*/_jsx(ColumnsPanel, _extends({},
|
|
225
|
+
return /*#__PURE__*/_jsx(ColumnsPanel, _extends({}, props.slotProps?.columnsPanel));
|
|
234
226
|
}
|
|
235
227
|
return initialValue;
|
|
236
|
-
}, [props.slots.columnsPanel,
|
|
228
|
+
}, [props.slots.columnsPanel, props.slotProps?.columnsPanel]);
|
|
237
229
|
const addColumnMenuItems = React.useCallback(columnMenuItems => {
|
|
238
230
|
if (props.disableColumnSelector) {
|
|
239
231
|
return columnMenuItems;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { GridStateCommunity } from '../../../models/gridStateCommunity';
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
2
|
+
import { GridDensity } from '../../../models/gridDensity';
|
|
3
|
+
export declare const COMPACT_DENSITY_FACTOR = 0.7;
|
|
4
|
+
export declare const COMFORTABLE_DENSITY_FACTOR = 1.3;
|
|
5
|
+
export declare const gridDensitySelector: (state: GridStateCommunity) => GridDensity;
|
|
4
6
|
export declare const gridDensityFactorSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, number>;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { createSelector } from '../../../utils/createSelector';
|
|
2
|
+
export const COMPACT_DENSITY_FACTOR = 0.7;
|
|
3
|
+
export const COMFORTABLE_DENSITY_FACTOR = 1.3;
|
|
4
|
+
const DENSITY_FACTORS = {
|
|
5
|
+
compact: COMPACT_DENSITY_FACTOR,
|
|
6
|
+
comfortable: COMFORTABLE_DENSITY_FACTOR,
|
|
7
|
+
standard: 1
|
|
8
|
+
};
|
|
2
9
|
export const gridDensitySelector = state => state.density;
|
|
3
|
-
export const
|
|
4
|
-
export const gridDensityFactorSelector = createSelector(gridDensitySelector, density => density.factor);
|
|
10
|
+
export const gridDensityFactorSelector = createSelector(gridDensitySelector, density => DENSITY_FACTORS[density]);
|
|
@@ -2,7 +2,5 @@ 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
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const densityStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'density'>>;
|
|
8
|
-
export declare const useGridDensity: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, 'density'>) => void;
|
|
5
|
+
export declare const densityStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'initialState' | 'density'>>;
|
|
6
|
+
export declare const useGridDensity: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, 'density' | 'onDensityChange'>) => void;
|
|
@@ -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
|
|
@@ -53,9 +53,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
53
53
|
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
54
54
|
const headerHeight = Math.floor(props.columnHeaderHeight * densityFactor);
|
|
55
55
|
const columnsTotalWidth = roundToDecimalPlaces(gridColumnsTotalWidthSelector(apiRef), 6);
|
|
56
|
-
|
|
57
|
-
const hasHeaderFilters = Boolean(props.headerFilters);
|
|
58
|
-
const headersTotalHeight = getTotalHeaderHeight(apiRef, props.columnHeaderHeight) + Number(hasHeaderFilters) * headerHeight;
|
|
56
|
+
const headersTotalHeight = getTotalHeaderHeight(apiRef, props.columnHeaderHeight);
|
|
59
57
|
const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
|
|
60
58
|
const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
|
|
61
59
|
const [savedSize, setSavedSize] = React.useState();
|
|
@@ -68,7 +66,6 @@ export function useGridDimensions(apiRef, props) {
|
|
|
68
66
|
}));
|
|
69
67
|
});
|
|
70
68
|
const resize = React.useCallback(() => {
|
|
71
|
-
var _previousSize$current, _previousSize$current2;
|
|
72
69
|
const element = apiRef.current.mainElementRef.current;
|
|
73
70
|
if (!element) {
|
|
74
71
|
return;
|
|
@@ -76,8 +73,8 @@ export function useGridDimensions(apiRef, props) {
|
|
|
76
73
|
const computedStyle = ownerWindow(element).getComputedStyle(element);
|
|
77
74
|
const height = parseFloat(computedStyle.height) || 0;
|
|
78
75
|
const width = parseFloat(computedStyle.width) || 0;
|
|
79
|
-
const hasHeightChanged = height !==
|
|
80
|
-
const hasWidthChanged = width !==
|
|
76
|
+
const hasHeightChanged = height !== previousSize.current?.height;
|
|
77
|
+
const hasWidthChanged = width !== previousSize.current?.width;
|
|
81
78
|
if (!previousSize.current || hasHeightChanged || hasWidthChanged) {
|
|
82
79
|
const size = {
|
|
83
80
|
width,
|
|
@@ -108,14 +105,14 @@ export function useGridDimensions(apiRef, props) {
|
|
|
108
105
|
return Math.min(maximumPageSizeWithoutScrollBar, currentPage.rows.length);
|
|
109
106
|
}, [apiRef, props.pagination, props.paginationMode, props.getRowHeight, rowHeight]);
|
|
110
107
|
const updateDimensions = React.useCallback(() => {
|
|
111
|
-
var _apiRef$current$updat, _apiRef$current;
|
|
112
108
|
const rootElement = apiRef.current.rootElementRef.current;
|
|
113
109
|
const pinnedRowsHeight = calculatePinnedRowsHeight(apiRef);
|
|
114
110
|
const scrollbarSize = measureScrollbarSize(rootElement, columnsTotalWidth, props.scrollbarSize);
|
|
115
111
|
const topContainerHeight = headersTotalHeight + pinnedRowsHeight.top;
|
|
116
112
|
const bottomContainerHeight = pinnedRowsHeight.bottom;
|
|
113
|
+
const nonPinnedColumnsTotalWidth = columnsTotalWidth - leftPinnedWidth - rightPinnedWidth;
|
|
117
114
|
const contentSize = {
|
|
118
|
-
width:
|
|
115
|
+
width: nonPinnedColumnsTotalWidth,
|
|
119
116
|
height: rowsMeta.currentPageTotalHeight
|
|
120
117
|
};
|
|
121
118
|
let viewportOuterSize;
|
|
@@ -164,7 +161,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
164
161
|
}
|
|
165
162
|
const rowWidth = Math.max(viewportOuterSize.width, columnsTotalWidth + (hasScrollY ? scrollbarSize : 0));
|
|
166
163
|
const minimumSize = {
|
|
167
|
-
width:
|
|
164
|
+
width: columnsTotalWidth,
|
|
168
165
|
height: topContainerHeight + contentSize.height + bottomContainerHeight
|
|
169
166
|
};
|
|
170
167
|
const newDimensions = {
|
|
@@ -192,7 +189,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
192
189
|
if (newDimensions.viewportInnerSize.width !== prevDimensions.viewportInnerSize.width || newDimensions.viewportInnerSize.height !== prevDimensions.viewportInnerSize.height) {
|
|
193
190
|
apiRef.current.publishEvent('viewportInnerSizeChange', newDimensions.viewportInnerSize);
|
|
194
191
|
}
|
|
195
|
-
|
|
192
|
+
apiRef.current.updateRenderContext?.();
|
|
196
193
|
}, [apiRef, setDimensions, props.scrollbarSize, props.autoHeight, rowsMeta.currentPageTotalHeight, rowHeight, headerHeight, columnsTotalWidth, headersTotalHeight, leftPinnedWidth, rightPinnedWidth]);
|
|
197
194
|
const apiPublic = {
|
|
198
195
|
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);
|
|
@@ -234,8 +234,27 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
234
234
|
initialValue
|
|
235
235
|
} = params;
|
|
236
236
|
let newValue = apiRef.current.getCellValue(id, field);
|
|
237
|
-
if (deleteValue
|
|
238
|
-
|
|
237
|
+
if (deleteValue) {
|
|
238
|
+
const fieldType = apiRef.current.getColumn(field).type;
|
|
239
|
+
switch (fieldType) {
|
|
240
|
+
case 'boolean':
|
|
241
|
+
newValue = false;
|
|
242
|
+
break;
|
|
243
|
+
case 'date':
|
|
244
|
+
case 'dateTime':
|
|
245
|
+
case 'number':
|
|
246
|
+
newValue = undefined;
|
|
247
|
+
break;
|
|
248
|
+
case 'singleSelect':
|
|
249
|
+
newValue = null;
|
|
250
|
+
break;
|
|
251
|
+
case 'string':
|
|
252
|
+
default:
|
|
253
|
+
newValue = '';
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
} else if (initialValue) {
|
|
257
|
+
newValue = initialValue;
|
|
239
258
|
}
|
|
240
259
|
const newProps = {
|
|
241
260
|
value: newValue,
|
|
@@ -320,7 +339,6 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
320
339
|
}
|
|
321
340
|
});
|
|
322
341
|
const setCellEditingEditCellValue = React.useCallback(async params => {
|
|
323
|
-
var _editingState$id;
|
|
324
342
|
const {
|
|
325
343
|
id,
|
|
326
344
|
field,
|
|
@@ -370,7 +388,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
370
388
|
newProps.value = column.preProcessEditCellProps ? editingState[id][field].value : parsedValue;
|
|
371
389
|
updateOrDeleteFieldState(id, field, newProps);
|
|
372
390
|
editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
373
|
-
return !
|
|
391
|
+
return !editingState[id]?.[field]?.error;
|
|
374
392
|
}, [apiRef, throwIfNotEditable, throwIfNotInMode, updateOrDeleteFieldState]);
|
|
375
393
|
const getRowWithUpdatedValuesFromCellEditing = React.useCallback((id, field) => {
|
|
376
394
|
const column = apiRef.current.getColumn(field);
|
|
@@ -413,9 +431,8 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
413
431
|
|
|
414
432
|
Object.entries(cellModesModel).forEach(([id, fields]) => {
|
|
415
433
|
Object.entries(fields).forEach(([field, params]) => {
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
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;
|
|
419
436
|
if (params.mode === GridCellModes.Edit && prevMode === GridCellModes.View) {
|
|
420
437
|
updateStateToStartCellEditMode(_extends({
|
|
421
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);
|
|
@@ -76,8 +76,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
76
76
|
// focus we check if the next cell that received focus is from a different row.
|
|
77
77
|
nextFocusedCell.current = null;
|
|
78
78
|
focusTimeout.current = setTimeout(() => {
|
|
79
|
-
|
|
80
|
-
if (((_nextFocusedCell$curr = nextFocusedCell.current) == null ? void 0 : _nextFocusedCell$curr.id) !== params.id) {
|
|
79
|
+
if (nextFocusedCell.current?.id !== params.id) {
|
|
81
80
|
// The row might have been deleted during the click
|
|
82
81
|
if (!apiRef.current.getRow(params.id)) {
|
|
83
82
|
return;
|
|
@@ -541,9 +540,8 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
541
540
|
prevRowModesModel.current = deepClone(rowModesModel); // Do a deep-clone because the attributes might be changed later
|
|
542
541
|
|
|
543
542
|
Object.entries(rowModesModel).forEach(([id, params]) => {
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
const originalId = (_idToIdLookup$id = idToIdLookup[id]) != null ? _idToIdLookup$id : id;
|
|
543
|
+
const prevMode = copyOfPrevRowModesModel[id]?.mode || GridRowModes.View;
|
|
544
|
+
const originalId = idToIdLookup[id] ?? id;
|
|
547
545
|
if (params.mode === GridRowModes.Edit && prevMode === GridRowModes.View) {
|
|
548
546
|
updateStateToStartRowEditMode(_extends({
|
|
549
547
|
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, {
|