@mui/x-data-grid 7.0.0-beta.6 → 7.0.0-beta.7
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 +117 -1
- package/DataGrid/DataGrid.js +44 -0
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +3 -2
- package/components/GridColumnHeaders.d.ts +1 -2
- package/components/GridColumnHeaders.js +6 -17
- package/components/GridHeaders.js +1 -4
- package/components/GridPagination.js +2 -7
- package/components/GridRow.d.ts +1 -1
- package/components/GridRow.js +4 -19
- package/components/GridScrollArea.d.ts +10 -0
- package/components/GridScrollArea.js +150 -0
- package/components/cell/GridCell.d.ts +7 -0
- package/components/cell/GridCell.js +11 -3
- package/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/components/columnHeaders/GridColumnGroupHeader.d.ts +5 -0
- package/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/components/columnHeaders/GridColumnHeaderItem.d.ts +5 -0
- package/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/components/columnHeaders/GridGenericColumnHeaderItem.d.ts +1 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/components/containers/GridRootStyles.js +12 -20
- package/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/components/virtualization/GridVirtualScroller.js +6 -1
- package/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/constants/gridClasses.d.ts +6 -32
- package/constants/gridClasses.js +1 -1
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +23 -7
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +186 -99
- 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 +563 -0
- package/hooks/features/columns/gridColumnsUtils.js +4 -1
- package/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/hooks/features/editing/useGridCellEditing.js +21 -2
- package/hooks/features/export/useGridPrintExport.js +8 -7
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +1 -0
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +6 -0
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +30 -7
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- package/hooks/features/pagination/gridPaginationInterfaces.d.ts +19 -2
- package/hooks/features/pagination/gridPaginationSelector.d.ts +5 -0
- package/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/hooks/features/pagination/useGridPagination.d.ts +1 -6
- package/hooks/features/pagination/useGridPagination.js +9 -157
- package/hooks/features/pagination/useGridPaginationModel.d.ts +11 -0
- package/hooks/features/pagination/useGridPaginationModel.js +170 -0
- package/hooks/features/pagination/useGridRowCount.d.ts +8 -0
- package/hooks/features/pagination/useGridRowCount.js +97 -0
- package/hooks/features/scroll/useGridScroll.js +1 -1
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +4 -4
- package/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +2 -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 +1 -1
- package/internals/index.js +1 -1
- package/internals/utils/getPinnedCellOffset.d.ts +3 -0
- package/internals/utils/getPinnedCellOffset.js +17 -0
- package/joy/joySlots.js +13 -52
- 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/events/gridEventLookup.d.ts +6 -0
- package/models/gridHeaderFilteringModel.d.ts +1 -0
- package/models/gridSlotsComponent.d.ts +0 -5
- package/models/gridStateCommunity.d.ts +2 -0
- package/models/params/gridScrollParams.d.ts +5 -3
- package/models/props/DataGridProps.d.ts +35 -1
- package/modern/DataGrid/DataGrid.js +44 -0
- package/modern/DataGrid/useDataGridComponent.js +3 -0
- package/modern/DataGrid/useDataGridProps.js +3 -2
- package/modern/components/GridColumnHeaders.js +6 -17
- package/modern/components/GridHeaders.js +1 -4
- package/modern/components/GridPagination.js +2 -4
- package/modern/components/GridRow.js +4 -19
- package/modern/components/GridScrollArea.js +150 -0
- 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/GridRootStyles.js +12 -20
- 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/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 -1
- package/modern/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/modern/hooks/features/editing/useGridCellEditing.js +21 -2
- package/modern/hooks/features/export/useGridPrintExport.js +8 -7
- 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/scroll/useGridScroll.js +1 -1
- package/modern/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- 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 +1 -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/utils/cellBorderUtils.js +8 -0
- package/modern/utils/domUtils.js +144 -0
- package/node/DataGrid/DataGrid.js +44 -0
- package/node/DataGrid/useDataGridComponent.js +3 -0
- package/node/DataGrid/useDataGridProps.js +3 -2
- package/node/components/GridColumnHeaders.js +6 -16
- package/node/components/GridHeaders.js +1 -4
- package/node/components/GridPagination.js +1 -3
- package/node/components/GridRow.js +3 -18
- package/node/components/GridScrollArea.js +158 -0
- 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/GridRootStyles.js +12 -20
- 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/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 -1
- package/node/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/node/hooks/features/editing/useGridCellEditing.js +21 -2
- package/node/hooks/features/export/useGridPrintExport.js +8 -7
- 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/scroll/useGridScroll.js +1 -1
- package/node/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- 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 +15 -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/utils/cellBorderUtils.js +16 -0
- package/node/utils/domUtils.js +155 -0
- package/package.json +1 -1
- package/utils/cellBorderUtils.d.ts +3 -0
- package/utils/cellBorderUtils.js +8 -0
- package/utils/domUtils.d.ts +14 -1
- package/utils/domUtils.js +147 -0
- 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
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { unstable_ownerDocument as ownerDocument, unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
4
|
+
import { useTheme } from '@mui/material/styles';
|
|
5
|
+
import { findGridCellElementsFromCol, findGridElement, findLeftPinnedCellsAfterCol, findRightPinnedCellsBeforeCol, getFieldFromHeaderElem, findHeaderElementFromField, findGroupHeaderElementsFromField, findGridHeader, findGridCells, findParentElementFromClassName, findLeftPinnedHeadersAfterCol, findRightPinnedHeadersBeforeCol } from '../../../utils/domUtils';
|
|
6
|
+
import { DEFAULT_GRID_AUTOSIZE_OPTIONS } from './gridColumnResizeApi';
|
|
7
|
+
import { gridClasses } from '../../../constants/gridClasses';
|
|
8
|
+
import { useGridApiEventHandler, useGridApiMethod, useGridApiOptionHandler, useGridLogger, useGridNativeEventListener, useGridSelector, useOnMount } from '../../utils';
|
|
9
|
+
import { gridVirtualizationColumnEnabledSelector } from '../virtualization';
|
|
10
|
+
import { createControllablePromise } from '../../../utils/createControllablePromise';
|
|
11
|
+
import { clamp } from '../../../utils/utils';
|
|
12
|
+
import { useTimeout } from '../../utils/useTimeout';
|
|
13
|
+
import { GridPinnedColumnPosition } from '../columns/gridColumnsInterfaces';
|
|
14
|
+
import { gridColumnsStateSelector } from '../columns';
|
|
15
|
+
// TODO: remove support for Safari < 13.
|
|
16
|
+
// https://caniuse.com/#search=touch-action
|
|
17
|
+
//
|
|
18
|
+
// Safari, on iOS, supports touch action since v13.
|
|
19
|
+
// Over 80% of the iOS phones are compatible
|
|
20
|
+
// in August 2020.
|
|
21
|
+
// Utilizing the CSS.supports method to check if touch-action is supported.
|
|
22
|
+
// Since CSS.supports is supported on all but Edge@12 and IE and touch-action
|
|
23
|
+
// is supported on both Edge@12 and IE if CSS.supports is not available that means that
|
|
24
|
+
// touch-action will be supported
|
|
25
|
+
let cachedSupportsTouchActionNone = false;
|
|
26
|
+
function doesSupportTouchActionNone() {
|
|
27
|
+
if (cachedSupportsTouchActionNone === undefined) {
|
|
28
|
+
if (typeof CSS !== 'undefined' && typeof CSS.supports === 'function') {
|
|
29
|
+
cachedSupportsTouchActionNone = CSS.supports('touch-action', 'none');
|
|
30
|
+
} else {
|
|
31
|
+
cachedSupportsTouchActionNone = true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return cachedSupportsTouchActionNone;
|
|
35
|
+
}
|
|
36
|
+
function trackFinger(event, currentTouchId) {
|
|
37
|
+
if (currentTouchId !== undefined && event.changedTouches) {
|
|
38
|
+
for (let i = 0; i < event.changedTouches.length; i += 1) {
|
|
39
|
+
const touch = event.changedTouches[i];
|
|
40
|
+
if (touch.identifier === currentTouchId) {
|
|
41
|
+
return {
|
|
42
|
+
x: touch.clientX,
|
|
43
|
+
y: touch.clientY
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
x: event.clientX,
|
|
51
|
+
y: event.clientY
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function computeNewWidth(initialOffsetToSeparator, clickX, columnBounds, resizeDirection) {
|
|
55
|
+
let newWidth = initialOffsetToSeparator;
|
|
56
|
+
if (resizeDirection === 'Right') {
|
|
57
|
+
newWidth += clickX - columnBounds.left;
|
|
58
|
+
} else {
|
|
59
|
+
newWidth += columnBounds.right - clickX;
|
|
60
|
+
}
|
|
61
|
+
return newWidth;
|
|
62
|
+
}
|
|
63
|
+
function computeOffsetToSeparator(clickX, columnBounds, resizeDirection) {
|
|
64
|
+
if (resizeDirection === 'Left') {
|
|
65
|
+
return clickX - columnBounds.left;
|
|
66
|
+
}
|
|
67
|
+
return columnBounds.right - clickX;
|
|
68
|
+
}
|
|
69
|
+
function flipResizeDirection(side) {
|
|
70
|
+
if (side === 'Right') {
|
|
71
|
+
return 'Left';
|
|
72
|
+
}
|
|
73
|
+
return 'Right';
|
|
74
|
+
}
|
|
75
|
+
function getResizeDirection(separator, direction) {
|
|
76
|
+
const side = separator.classList.contains(gridClasses['columnSeparator--sideRight']) ? 'Right' : 'Left';
|
|
77
|
+
if (direction === 'rtl') {
|
|
78
|
+
// Resizing logic should be mirrored in the RTL case
|
|
79
|
+
return flipResizeDirection(side);
|
|
80
|
+
}
|
|
81
|
+
return side;
|
|
82
|
+
}
|
|
83
|
+
function preventClick(event) {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
event.stopImmediatePropagation();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Checker that returns a promise that resolves when the column virtualization
|
|
90
|
+
* is disabled.
|
|
91
|
+
*/
|
|
92
|
+
function useColumnVirtualizationDisabled(apiRef) {
|
|
93
|
+
const promise = React.useRef();
|
|
94
|
+
const selector = () => gridVirtualizationColumnEnabledSelector(apiRef);
|
|
95
|
+
const value = useGridSelector(apiRef, selector);
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
if (promise.current && value === false) {
|
|
98
|
+
promise.current.resolve();
|
|
99
|
+
promise.current = undefined;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const asyncCheck = () => {
|
|
103
|
+
if (!promise.current) {
|
|
104
|
+
if (selector() === false) {
|
|
105
|
+
return Promise.resolve();
|
|
106
|
+
}
|
|
107
|
+
promise.current = createControllablePromise();
|
|
108
|
+
}
|
|
109
|
+
return promise.current;
|
|
110
|
+
};
|
|
111
|
+
return asyncCheck;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Basic statistical outlier detection, checks if the value is `F * IQR` away from
|
|
116
|
+
* the Q1 and Q3 boundaries. IQR: interquartile range.
|
|
117
|
+
*/
|
|
118
|
+
function excludeOutliers(inputValues, factor) {
|
|
119
|
+
if (inputValues.length < 4) {
|
|
120
|
+
return inputValues;
|
|
121
|
+
}
|
|
122
|
+
const values = inputValues.slice();
|
|
123
|
+
values.sort((a, b) => a - b);
|
|
124
|
+
const q1 = values[Math.floor(values.length * 0.25)];
|
|
125
|
+
const q3 = values[Math.floor(values.length * 0.75) - 1];
|
|
126
|
+
const iqr = q3 - q1;
|
|
127
|
+
|
|
128
|
+
// We make a small adjustment if `iqr < 5` for the cases where the IQR is
|
|
129
|
+
// very small (e.g. zero) due to very close by values in the input data.
|
|
130
|
+
// Otherwise, with an IQR of `0`, anything outside that would be considered
|
|
131
|
+
// an outlier, but it makes more sense visually to allow for this 5px variance
|
|
132
|
+
// rather than showing a cropped cell.
|
|
133
|
+
const deviation = iqr < 5 ? 5 : iqr * factor;
|
|
134
|
+
return values.filter(v => v > q1 - deviation && v < q3 + deviation);
|
|
135
|
+
}
|
|
136
|
+
function extractColumnWidths(apiRef, options, columns) {
|
|
137
|
+
const widthByField = {};
|
|
138
|
+
const root = apiRef.current.rootElementRef.current;
|
|
139
|
+
root.classList.add(gridClasses.autosizing);
|
|
140
|
+
columns.forEach(column => {
|
|
141
|
+
const cells = findGridCells(apiRef.current, column.field);
|
|
142
|
+
const widths = cells.map(cell => {
|
|
143
|
+
return cell.getBoundingClientRect().width ?? 0;
|
|
144
|
+
});
|
|
145
|
+
const filteredWidths = options.includeOutliers ? widths : excludeOutliers(widths, options.outliersFactor);
|
|
146
|
+
if (options.includeHeaders) {
|
|
147
|
+
const header = findGridHeader(apiRef.current, column.field);
|
|
148
|
+
if (header) {
|
|
149
|
+
const title = header.querySelector(`.${gridClasses.columnHeaderTitle}`);
|
|
150
|
+
const content = header.querySelector(`.${gridClasses.columnHeaderTitleContainerContent}`);
|
|
151
|
+
const iconContainer = header.querySelector(`.${gridClasses.iconButtonContainer}`);
|
|
152
|
+
const menuContainer = header.querySelector(`.${gridClasses.menuIcon}`);
|
|
153
|
+
const element = title ?? content;
|
|
154
|
+
const style = window.getComputedStyle(header, null);
|
|
155
|
+
const paddingWidth = parseInt(style.paddingLeft, 10) + parseInt(style.paddingRight, 10);
|
|
156
|
+
const contentWidth = element.scrollWidth + 1;
|
|
157
|
+
const width = contentWidth + paddingWidth + (iconContainer?.clientWidth ?? 0) + (menuContainer?.clientWidth ?? 0);
|
|
158
|
+
filteredWidths.push(width);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const hasColumnMin = column.minWidth !== -Infinity && column.minWidth !== undefined;
|
|
162
|
+
const hasColumnMax = column.maxWidth !== Infinity && column.maxWidth !== undefined;
|
|
163
|
+
const min = hasColumnMin ? column.minWidth : 0;
|
|
164
|
+
const max = hasColumnMax ? column.maxWidth : Infinity;
|
|
165
|
+
const maxContent = filteredWidths.length === 0 ? 0 : Math.max(...filteredWidths);
|
|
166
|
+
widthByField[column.field] = clamp(maxContent, min, max);
|
|
167
|
+
});
|
|
168
|
+
root.classList.remove(gridClasses.autosizing);
|
|
169
|
+
return widthByField;
|
|
170
|
+
}
|
|
171
|
+
export const columnResizeStateInitializer = state => _extends({}, state, {
|
|
172
|
+
columnResize: {
|
|
173
|
+
resizingColumnField: ''
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
/**
|
|
177
|
+
* @requires useGridColumns (method, event)
|
|
178
|
+
* TODO: improve experience for last column
|
|
179
|
+
*/
|
|
180
|
+
export const useGridColumnResize = (apiRef, props) => {
|
|
181
|
+
const theme = useTheme();
|
|
182
|
+
const logger = useGridLogger(apiRef, 'useGridColumnResize');
|
|
183
|
+
const colDefRef = React.useRef();
|
|
184
|
+
const previousMouseClickEvent = React.useRef();
|
|
185
|
+
const columnHeaderElementRef = React.useRef();
|
|
186
|
+
const headerFilterElementRef = React.useRef();
|
|
187
|
+
const groupHeaderElementsRef = React.useRef([]);
|
|
188
|
+
const cellElementsRef = React.useRef([]);
|
|
189
|
+
const leftPinnedCellsAfterRef = React.useRef([]);
|
|
190
|
+
const rightPinnedCellsBeforeRef = React.useRef([]);
|
|
191
|
+
const fillerLeftRef = React.useRef();
|
|
192
|
+
const fillerRightRef = React.useRef();
|
|
193
|
+
const leftPinnedHeadersAfterRef = React.useRef([]);
|
|
194
|
+
const rightPinnedHeadersBeforeRef = React.useRef([]);
|
|
195
|
+
|
|
196
|
+
// To improve accessibility, the separator has padding on both sides.
|
|
197
|
+
// Clicking inside the padding area should be treated as a click in the separator.
|
|
198
|
+
// This ref stores the offset between the click and the separator.
|
|
199
|
+
const initialOffsetToSeparator = React.useRef();
|
|
200
|
+
const resizeDirection = React.useRef();
|
|
201
|
+
const stopResizeEventTimeout = useTimeout();
|
|
202
|
+
const touchId = React.useRef();
|
|
203
|
+
const updateWidth = newWidth => {
|
|
204
|
+
logger.debug(`Updating width to ${newWidth} for col ${colDefRef.current.field}`);
|
|
205
|
+
const prevWidth = columnHeaderElementRef.current.offsetWidth;
|
|
206
|
+
const widthDiff = newWidth - prevWidth;
|
|
207
|
+
colDefRef.current.computedWidth = newWidth;
|
|
208
|
+
colDefRef.current.width = newWidth;
|
|
209
|
+
colDefRef.current.flex = 0;
|
|
210
|
+
columnHeaderElementRef.current.style.width = `${newWidth}px`;
|
|
211
|
+
columnHeaderElementRef.current.style.minWidth = `${newWidth}px`;
|
|
212
|
+
columnHeaderElementRef.current.style.maxWidth = `${newWidth}px`;
|
|
213
|
+
const headerFilterElement = headerFilterElementRef.current;
|
|
214
|
+
if (headerFilterElement) {
|
|
215
|
+
headerFilterElement.style.width = `${newWidth}px`;
|
|
216
|
+
headerFilterElement.style.minWidth = `${newWidth}px`;
|
|
217
|
+
headerFilterElement.style.maxWidth = `${newWidth}px`;
|
|
218
|
+
}
|
|
219
|
+
groupHeaderElementsRef.current.forEach(element => {
|
|
220
|
+
const div = element;
|
|
221
|
+
let finalWidth;
|
|
222
|
+
if (div.getAttribute('aria-colspan') === '1') {
|
|
223
|
+
finalWidth = `${newWidth}px`;
|
|
224
|
+
} else {
|
|
225
|
+
// Cell with colspan > 1 cannot be just updated width new width.
|
|
226
|
+
// Instead, we add width diff to the current width.
|
|
227
|
+
finalWidth = `${div.offsetWidth + widthDiff}px`;
|
|
228
|
+
}
|
|
229
|
+
div.style.width = finalWidth;
|
|
230
|
+
div.style.minWidth = finalWidth;
|
|
231
|
+
div.style.maxWidth = finalWidth;
|
|
232
|
+
});
|
|
233
|
+
cellElementsRef.current.forEach(element => {
|
|
234
|
+
const div = element;
|
|
235
|
+
let finalWidth;
|
|
236
|
+
if (div.getAttribute('aria-colspan') === '1') {
|
|
237
|
+
finalWidth = `${newWidth}px`;
|
|
238
|
+
} else {
|
|
239
|
+
// Cell with colspan > 1 cannot be just updated width new width.
|
|
240
|
+
// Instead, we add width diff to the current width.
|
|
241
|
+
finalWidth = `${div.offsetWidth + widthDiff}px`;
|
|
242
|
+
}
|
|
243
|
+
div.style.setProperty('--width', finalWidth);
|
|
244
|
+
});
|
|
245
|
+
const pinnedPosition = apiRef.current.unstable_applyPipeProcessors('isColumnPinned', false, colDefRef.current.field);
|
|
246
|
+
if (pinnedPosition === GridPinnedColumnPosition.LEFT) {
|
|
247
|
+
updateProperty(fillerLeftRef.current, 'width', widthDiff);
|
|
248
|
+
leftPinnedCellsAfterRef.current.forEach(cell => {
|
|
249
|
+
updateProperty(cell, 'left', widthDiff);
|
|
250
|
+
});
|
|
251
|
+
leftPinnedHeadersAfterRef.current.forEach(header => {
|
|
252
|
+
updateProperty(header, 'left', widthDiff);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (pinnedPosition === GridPinnedColumnPosition.RIGHT) {
|
|
256
|
+
updateProperty(fillerRightRef.current, 'width', widthDiff);
|
|
257
|
+
rightPinnedCellsBeforeRef.current.forEach(cell => {
|
|
258
|
+
updateProperty(cell, 'right', widthDiff);
|
|
259
|
+
});
|
|
260
|
+
rightPinnedHeadersBeforeRef.current.forEach(header => {
|
|
261
|
+
updateProperty(header, 'right', widthDiff);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const finishResize = nativeEvent => {
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
267
|
+
stopListening();
|
|
268
|
+
|
|
269
|
+
// Prevent double-clicks from being interpreted as two separate clicks
|
|
270
|
+
if (previousMouseClickEvent.current) {
|
|
271
|
+
const prevEvent = previousMouseClickEvent.current;
|
|
272
|
+
const prevTimeStamp = prevEvent.timeStamp;
|
|
273
|
+
const prevClientX = prevEvent.clientX;
|
|
274
|
+
const prevClientY = prevEvent.clientY;
|
|
275
|
+
|
|
276
|
+
// Check if the current event is part of a double-click
|
|
277
|
+
if (nativeEvent.timeStamp - prevTimeStamp < 300 && nativeEvent.clientX === prevClientX && nativeEvent.clientY === prevClientY) {
|
|
278
|
+
previousMouseClickEvent.current = undefined;
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (colDefRef.current) {
|
|
283
|
+
apiRef.current.setColumnWidth(colDefRef.current.field, colDefRef.current.width);
|
|
284
|
+
logger.debug(`Updating col ${colDefRef.current.field} with new width: ${colDefRef.current.width}`);
|
|
285
|
+
}
|
|
286
|
+
stopResizeEventTimeout.start(0, () => {
|
|
287
|
+
apiRef.current.publishEvent('columnResizeStop', null, nativeEvent);
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
const storeReferences = (colDef, separator, xStart) => {
|
|
291
|
+
const root = apiRef.current.rootElementRef.current;
|
|
292
|
+
colDefRef.current = colDef;
|
|
293
|
+
columnHeaderElementRef.current = findHeaderElementFromField(apiRef.current.columnHeadersContainerRef.current, colDef.field);
|
|
294
|
+
const headerFilterElement = root.querySelector(`.${gridClasses.headerFilterRow} [data-field="${colDef.field}"]`);
|
|
295
|
+
if (headerFilterElement) {
|
|
296
|
+
headerFilterElementRef.current = headerFilterElement;
|
|
297
|
+
}
|
|
298
|
+
groupHeaderElementsRef.current = findGroupHeaderElementsFromField(apiRef.current.columnHeadersContainerRef?.current, colDef.field);
|
|
299
|
+
cellElementsRef.current = findGridCellElementsFromCol(columnHeaderElementRef.current, apiRef.current);
|
|
300
|
+
fillerLeftRef.current = findGridElement(apiRef.current, 'filler--pinnedLeft');
|
|
301
|
+
fillerRightRef.current = findGridElement(apiRef.current, 'filler--pinnedRight');
|
|
302
|
+
const pinnedPosition = apiRef.current.unstable_applyPipeProcessors('isColumnPinned', false, colDefRef.current.field);
|
|
303
|
+
leftPinnedCellsAfterRef.current = pinnedPosition !== GridPinnedColumnPosition.LEFT ? [] : findLeftPinnedCellsAfterCol(apiRef.current, columnHeaderElementRef.current);
|
|
304
|
+
rightPinnedCellsBeforeRef.current = pinnedPosition !== GridPinnedColumnPosition.RIGHT ? [] : findRightPinnedCellsBeforeCol(apiRef.current, columnHeaderElementRef.current);
|
|
305
|
+
leftPinnedHeadersAfterRef.current = pinnedPosition !== GridPinnedColumnPosition.LEFT ? [] : findLeftPinnedHeadersAfterCol(apiRef.current, columnHeaderElementRef.current);
|
|
306
|
+
rightPinnedHeadersBeforeRef.current = pinnedPosition !== GridPinnedColumnPosition.RIGHT ? [] : findRightPinnedHeadersBeforeCol(apiRef.current, columnHeaderElementRef.current);
|
|
307
|
+
resizeDirection.current = getResizeDirection(separator, theme.direction);
|
|
308
|
+
initialOffsetToSeparator.current = computeOffsetToSeparator(xStart, columnHeaderElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
309
|
+
};
|
|
310
|
+
const handleResizeMouseUp = useEventCallback(finishResize);
|
|
311
|
+
const handleResizeMouseMove = useEventCallback(nativeEvent => {
|
|
312
|
+
// Cancel move in case some other element consumed a mouseup event and it was not fired.
|
|
313
|
+
if (nativeEvent.buttons === 0) {
|
|
314
|
+
handleResizeMouseUp(nativeEvent);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
let newWidth = computeNewWidth(initialOffsetToSeparator.current, nativeEvent.clientX, columnHeaderElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
318
|
+
newWidth = clamp(newWidth, colDefRef.current.minWidth, colDefRef.current.maxWidth);
|
|
319
|
+
updateWidth(newWidth);
|
|
320
|
+
const params = {
|
|
321
|
+
element: columnHeaderElementRef.current,
|
|
322
|
+
colDef: colDefRef.current,
|
|
323
|
+
width: newWidth
|
|
324
|
+
};
|
|
325
|
+
apiRef.current.publishEvent('columnResize', params, nativeEvent);
|
|
326
|
+
});
|
|
327
|
+
const handleTouchEnd = useEventCallback(nativeEvent => {
|
|
328
|
+
const finger = trackFinger(nativeEvent, touchId.current);
|
|
329
|
+
if (!finger) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
finishResize(nativeEvent);
|
|
333
|
+
});
|
|
334
|
+
const handleTouchMove = useEventCallback(nativeEvent => {
|
|
335
|
+
const finger = trackFinger(nativeEvent, touchId.current);
|
|
336
|
+
if (!finger) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Cancel move in case some other element consumed a touchmove event and it was not fired.
|
|
341
|
+
if (nativeEvent.type === 'mousemove' && nativeEvent.buttons === 0) {
|
|
342
|
+
handleTouchEnd(nativeEvent);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
let newWidth = computeNewWidth(initialOffsetToSeparator.current, finger.x, columnHeaderElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
346
|
+
newWidth = clamp(newWidth, colDefRef.current.minWidth, colDefRef.current.maxWidth);
|
|
347
|
+
updateWidth(newWidth);
|
|
348
|
+
const params = {
|
|
349
|
+
element: columnHeaderElementRef.current,
|
|
350
|
+
colDef: colDefRef.current,
|
|
351
|
+
width: newWidth
|
|
352
|
+
};
|
|
353
|
+
apiRef.current.publishEvent('columnResize', params, nativeEvent);
|
|
354
|
+
});
|
|
355
|
+
const handleTouchStart = useEventCallback(event => {
|
|
356
|
+
const cellSeparator = findParentElementFromClassName(event.target, gridClasses['columnSeparator--resizable']);
|
|
357
|
+
// Let the event bubble if the target is not a col separator
|
|
358
|
+
if (!cellSeparator) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
// If touch-action: none; is not supported we need to prevent the scroll manually.
|
|
362
|
+
if (!doesSupportTouchActionNone()) {
|
|
363
|
+
event.preventDefault();
|
|
364
|
+
}
|
|
365
|
+
const touch = event.changedTouches[0];
|
|
366
|
+
if (touch != null) {
|
|
367
|
+
// A number that uniquely identifies the current finger in the touch session.
|
|
368
|
+
touchId.current = touch.identifier;
|
|
369
|
+
}
|
|
370
|
+
const columnHeaderElement = findParentElementFromClassName(event.target, gridClasses.columnHeader);
|
|
371
|
+
const field = getFieldFromHeaderElem(columnHeaderElement);
|
|
372
|
+
const colDef = apiRef.current.getColumn(field);
|
|
373
|
+
logger.debug(`Start Resize on col ${colDef.field}`);
|
|
374
|
+
apiRef.current.publishEvent('columnResizeStart', {
|
|
375
|
+
field
|
|
376
|
+
}, event);
|
|
377
|
+
storeReferences(colDef, cellSeparator, touch.clientX);
|
|
378
|
+
const doc = ownerDocument(event.currentTarget);
|
|
379
|
+
doc.addEventListener('touchmove', handleTouchMove);
|
|
380
|
+
doc.addEventListener('touchend', handleTouchEnd);
|
|
381
|
+
});
|
|
382
|
+
const stopListening = React.useCallback(() => {
|
|
383
|
+
const doc = ownerDocument(apiRef.current.rootElementRef.current);
|
|
384
|
+
doc.body.style.removeProperty('cursor');
|
|
385
|
+
doc.removeEventListener('mousemove', handleResizeMouseMove);
|
|
386
|
+
doc.removeEventListener('mouseup', handleResizeMouseUp);
|
|
387
|
+
doc.removeEventListener('touchmove', handleTouchMove);
|
|
388
|
+
doc.removeEventListener('touchend', handleTouchEnd);
|
|
389
|
+
// The click event runs right after the mouseup event, we want to wait until it
|
|
390
|
+
// has been canceled before removing our handler.
|
|
391
|
+
setTimeout(() => {
|
|
392
|
+
doc.removeEventListener('click', preventClick, true);
|
|
393
|
+
}, 100);
|
|
394
|
+
if (columnHeaderElementRef.current) {
|
|
395
|
+
columnHeaderElementRef.current.style.pointerEvents = 'unset';
|
|
396
|
+
}
|
|
397
|
+
}, [apiRef, columnHeaderElementRef, handleResizeMouseMove, handleResizeMouseUp, handleTouchMove, handleTouchEnd]);
|
|
398
|
+
const handleResizeStart = React.useCallback(({
|
|
399
|
+
field
|
|
400
|
+
}) => {
|
|
401
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
402
|
+
columnResize: _extends({}, state.columnResize, {
|
|
403
|
+
resizingColumnField: field
|
|
404
|
+
})
|
|
405
|
+
}));
|
|
406
|
+
apiRef.current.forceUpdate();
|
|
407
|
+
}, [apiRef]);
|
|
408
|
+
const handleResizeStop = React.useCallback(() => {
|
|
409
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
410
|
+
columnResize: _extends({}, state.columnResize, {
|
|
411
|
+
resizingColumnField: ''
|
|
412
|
+
})
|
|
413
|
+
}));
|
|
414
|
+
apiRef.current.forceUpdate();
|
|
415
|
+
}, [apiRef]);
|
|
416
|
+
const handleColumnResizeMouseDown = useEventCallback(({
|
|
417
|
+
colDef
|
|
418
|
+
}, event) => {
|
|
419
|
+
// Only handle left clicks
|
|
420
|
+
if (event.button !== 0) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Skip if the column isn't resizable
|
|
425
|
+
if (!event.currentTarget.classList.contains(gridClasses['columnSeparator--resizable'])) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Avoid text selection
|
|
430
|
+
event.preventDefault();
|
|
431
|
+
logger.debug(`Start Resize on col ${colDef.field}`);
|
|
432
|
+
apiRef.current.publishEvent('columnResizeStart', {
|
|
433
|
+
field: colDef.field
|
|
434
|
+
}, event);
|
|
435
|
+
storeReferences(colDef, event.currentTarget, event.clientX);
|
|
436
|
+
const doc = ownerDocument(apiRef.current.rootElementRef.current);
|
|
437
|
+
doc.body.style.cursor = 'col-resize';
|
|
438
|
+
previousMouseClickEvent.current = event.nativeEvent;
|
|
439
|
+
doc.addEventListener('mousemove', handleResizeMouseMove);
|
|
440
|
+
doc.addEventListener('mouseup', handleResizeMouseUp);
|
|
441
|
+
|
|
442
|
+
// Prevent the click event if we have resized the column.
|
|
443
|
+
// Fixes https://github.com/mui/mui-x/issues/4777
|
|
444
|
+
doc.addEventListener('click', preventClick, true);
|
|
445
|
+
});
|
|
446
|
+
const handleColumnSeparatorDoubleClick = useEventCallback((params, event) => {
|
|
447
|
+
if (props.disableAutosize) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// Only handle left clicks
|
|
452
|
+
if (event.button !== 0) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const column = apiRef.current.state.columns.lookup[params.field];
|
|
456
|
+
if (column.resizable === false) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
apiRef.current.autosizeColumns(_extends({}, props.autosizeOptions, {
|
|
460
|
+
columns: [column.field]
|
|
461
|
+
}));
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* API METHODS
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
const columnVirtualizationDisabled = useColumnVirtualizationDisabled(apiRef);
|
|
469
|
+
const isAutosizingRef = React.useRef(false);
|
|
470
|
+
const autosizeColumns = React.useCallback(async userOptions => {
|
|
471
|
+
const root = apiRef.current.rootElementRef?.current;
|
|
472
|
+
if (!root) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if (isAutosizingRef.current) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
isAutosizingRef.current = true;
|
|
479
|
+
const state = gridColumnsStateSelector(apiRef.current.state);
|
|
480
|
+
const options = _extends({}, DEFAULT_GRID_AUTOSIZE_OPTIONS, userOptions, {
|
|
481
|
+
columns: userOptions?.columns ?? state.orderedFields
|
|
482
|
+
});
|
|
483
|
+
options.columns = options.columns.filter(c => state.columnVisibilityModel[c] !== false);
|
|
484
|
+
const columns = options.columns.map(c => apiRef.current.state.columns.lookup[c]);
|
|
485
|
+
try {
|
|
486
|
+
apiRef.current.unstable_setColumnVirtualization(false);
|
|
487
|
+
await columnVirtualizationDisabled();
|
|
488
|
+
const widthByField = extractColumnWidths(apiRef, options, columns);
|
|
489
|
+
const newColumns = columns.map(column => _extends({}, column, {
|
|
490
|
+
width: widthByField[column.field],
|
|
491
|
+
computedWidth: widthByField[column.field]
|
|
492
|
+
}));
|
|
493
|
+
if (options.expand) {
|
|
494
|
+
const visibleColumns = state.orderedFields.map(field => state.lookup[field]).filter(c => state.columnVisibilityModel[c.field] !== false);
|
|
495
|
+
const totalWidth = visibleColumns.reduce((total, column) => total + (widthByField[column.field] ?? column.computedWidth ?? column.width), 0);
|
|
496
|
+
const availableWidth = apiRef.current.getRootDimensions().viewportInnerSize.width;
|
|
497
|
+
const remainingWidth = availableWidth - totalWidth;
|
|
498
|
+
if (remainingWidth > 0) {
|
|
499
|
+
const widthPerColumn = remainingWidth / (newColumns.length || 1);
|
|
500
|
+
newColumns.forEach(column => {
|
|
501
|
+
column.width += widthPerColumn;
|
|
502
|
+
column.computedWidth += widthPerColumn;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
apiRef.current.updateColumns(newColumns);
|
|
507
|
+
newColumns.forEach((newColumn, index) => {
|
|
508
|
+
if (newColumn.width !== columns[index].width) {
|
|
509
|
+
const width = newColumn.width;
|
|
510
|
+
apiRef.current.publishEvent('columnWidthChange', {
|
|
511
|
+
element: apiRef.current.getColumnHeaderElement(newColumn.field),
|
|
512
|
+
colDef: newColumn,
|
|
513
|
+
width
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
} finally {
|
|
518
|
+
apiRef.current.unstable_setColumnVirtualization(true);
|
|
519
|
+
isAutosizingRef.current = false;
|
|
520
|
+
}
|
|
521
|
+
}, [apiRef, columnVirtualizationDisabled]);
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* EFFECTS
|
|
525
|
+
*/
|
|
526
|
+
|
|
527
|
+
React.useEffect(() => stopListening, [stopListening]);
|
|
528
|
+
useOnMount(() => {
|
|
529
|
+
if (props.autosizeOnMount) {
|
|
530
|
+
Promise.resolve().then(() => {
|
|
531
|
+
apiRef.current.autosizeColumns(props.autosizeOptions);
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
useGridNativeEventListener(apiRef, () => apiRef.current.columnHeadersContainerRef?.current, 'touchstart', handleTouchStart, {
|
|
536
|
+
passive: doesSupportTouchActionNone()
|
|
537
|
+
});
|
|
538
|
+
useGridApiMethod(apiRef, {
|
|
539
|
+
autosizeColumns
|
|
540
|
+
}, 'public');
|
|
541
|
+
useGridApiEventHandler(apiRef, 'columnResizeStop', handleResizeStop);
|
|
542
|
+
useGridApiEventHandler(apiRef, 'columnResizeStart', handleResizeStart);
|
|
543
|
+
useGridApiEventHandler(apiRef, 'columnSeparatorMouseDown', handleColumnResizeMouseDown);
|
|
544
|
+
useGridApiEventHandler(apiRef, 'columnSeparatorDoubleClick', handleColumnSeparatorDoubleClick);
|
|
545
|
+
useGridApiOptionHandler(apiRef, 'columnResize', props.onColumnResize);
|
|
546
|
+
useGridApiOptionHandler(apiRef, 'columnWidthChange', props.onColumnWidthChange);
|
|
547
|
+
};
|
|
548
|
+
function updateProperty(element, property, delta) {
|
|
549
|
+
if (!element) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
element.style[property] = `${parseInt(element.style[property], 10) + delta}px`;
|
|
553
|
+
}
|
|
@@ -3,6 +3,7 @@ import { DEFAULT_GRID_COL_TYPE_KEY, GRID_STRING_COL_DEF, getGridDefaultColumnTyp
|
|
|
3
3
|
import { gridColumnsStateSelector, gridColumnVisibilityModelSelector } from './gridColumnsSelector';
|
|
4
4
|
import { clamp } from '../../../utils/utils';
|
|
5
5
|
import { gridDensityFactorSelector } from '../density/densitySelector';
|
|
6
|
+
import { gridHeaderFilteringEnabledSelector } from '../headerFiltering/gridHeaderFilteringSelectors';
|
|
6
7
|
import { gridColumnGroupsHeaderMaxDepthSelector } from '../columnGrouping/gridColumnGroupsSelector';
|
|
7
8
|
export const COLUMNS_DIMENSION_PROPERTIES = ['maxWidth', 'minWidth', 'width', 'flex'];
|
|
8
9
|
const COLUMN_TYPES = getGridDefaultColumnTypes();
|
|
@@ -325,5 +326,7 @@ export function getFirstColumnIndexToRender({
|
|
|
325
326
|
export function getTotalHeaderHeight(apiRef, headerHeight) {
|
|
326
327
|
const densityFactor = gridDensityFactorSelector(apiRef);
|
|
327
328
|
const maxDepth = gridColumnGroupsHeaderMaxDepthSelector(apiRef);
|
|
328
|
-
|
|
329
|
+
const isHeaderFilteringEnabled = gridHeaderFilteringEnabledSelector(apiRef);
|
|
330
|
+
const multiplicationFactor = isHeaderFilteringEnabled ? 2 : 1;
|
|
331
|
+
return Math.floor(headerHeight * densityFactor) * ((maxDepth ?? 0) + multiplicationFactor);
|
|
329
332
|
}
|
|
@@ -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();
|
|
@@ -112,8 +110,9 @@ export function useGridDimensions(apiRef, props) {
|
|
|
112
110
|
const scrollbarSize = measureScrollbarSize(rootElement, columnsTotalWidth, props.scrollbarSize);
|
|
113
111
|
const topContainerHeight = headersTotalHeight + pinnedRowsHeight.top;
|
|
114
112
|
const bottomContainerHeight = pinnedRowsHeight.bottom;
|
|
113
|
+
const nonPinnedColumnsTotalWidth = columnsTotalWidth - leftPinnedWidth - rightPinnedWidth;
|
|
115
114
|
const contentSize = {
|
|
116
|
-
width:
|
|
115
|
+
width: nonPinnedColumnsTotalWidth,
|
|
117
116
|
height: rowsMeta.currentPageTotalHeight
|
|
118
117
|
};
|
|
119
118
|
let viewportOuterSize;
|
|
@@ -162,7 +161,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
162
161
|
}
|
|
163
162
|
const rowWidth = Math.max(viewportOuterSize.width, columnsTotalWidth + (hasScrollY ? scrollbarSize : 0));
|
|
164
163
|
const minimumSize = {
|
|
165
|
-
width:
|
|
164
|
+
width: columnsTotalWidth,
|
|
166
165
|
height: topContainerHeight + contentSize.height + bottomContainerHeight
|
|
167
166
|
};
|
|
168
167
|
const newDimensions = {
|
|
@@ -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,
|
|
@@ -8,7 +8,7 @@ import { gridClasses } from '../../../constants/gridClasses';
|
|
|
8
8
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
9
9
|
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
|
|
10
10
|
import { defaultGetRowsToExport, getColumnsToExport } from './utils';
|
|
11
|
-
import {
|
|
11
|
+
import { getDerivedPaginationModel } from '../pagination/useGridPaginationModel';
|
|
12
12
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
13
13
|
import { GridPrintExportMenuItem } from '../../../components/toolbar/GridToolbarExport';
|
|
14
14
|
import { getTotalHeaderHeight } from '../columns/gridColumnsUtils';
|
|
@@ -95,9 +95,6 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
95
95
|
|
|
96
96
|
// See https://support.google.com/chrome/thread/191619088?hl=en&msgid=193009642
|
|
97
97
|
gridClone.style.contain = 'size';
|
|
98
|
-
const columnHeaders = gridClone.querySelector(`.${gridClasses.columnHeaders}`);
|
|
99
|
-
const columnHeadersInner = columnHeaders.querySelector(`.${gridClasses.columnHeadersInner}`);
|
|
100
|
-
columnHeadersInner.style.width = '100%';
|
|
101
98
|
let gridToolbarElementHeight = gridRootElement.querySelector(`.${gridClasses.toolbarContainer}`)?.offsetHeight || 0;
|
|
102
99
|
let gridFooterElementHeight = gridRootElement.querySelector(`.${gridClasses.footerContainer}`)?.offsetHeight || 0;
|
|
103
100
|
if (normalizeOptions.hideToolbar) {
|
|
@@ -218,9 +215,13 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
218
215
|
page: 0,
|
|
219
216
|
pageSize: visibleRowCount
|
|
220
217
|
};
|
|
221
|
-
apiRef.current.
|
|
222
|
-
|
|
223
|
-
|
|
218
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
219
|
+
pagination: _extends({}, state.pagination, {
|
|
220
|
+
paginationModel: getDerivedPaginationModel(state.pagination,
|
|
221
|
+
// Using signature `DataGridPro` to allow more than 100 rows in the print export
|
|
222
|
+
'DataGridPro', paginationModel)
|
|
223
|
+
})
|
|
224
|
+
}));
|
|
224
225
|
apiRef.current.forceUpdate();
|
|
225
226
|
}
|
|
226
227
|
await updateGridColumnsForPrint(options?.fields, options?.allColumns, options?.includeCheckboxes);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { createSelector } from '../../../utils/createSelector';
|
|
2
2
|
export const gridHeaderFilteringStateSelector = state => state.headerFiltering;
|
|
3
|
+
export const gridHeaderFilteringEnabledSelector = createSelector(gridHeaderFilteringStateSelector,
|
|
4
|
+
// No initialization in MIT, so we need to default to false to be used by `getTotalHeaderHeight`
|
|
5
|
+
headerFilteringState => headerFilteringState?.enabled ?? false);
|
|
3
6
|
export const gridHeaderFilteringEditFieldSelector = createSelector(gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.editing);
|
|
4
7
|
export const gridHeaderFilteringMenuSelector = createSelector(gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.menuOpen);
|