@mui/x-data-grid 7.0.0-alpha.9 → 7.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +386 -38
- package/DataGrid/useDataGridComponent.js +1 -1
- package/README.md +2 -2
- package/colDef/gridBooleanColDef.js +3 -6
- package/colDef/gridCheckboxSelectionColDef.js +4 -3
- package/colDef/gridDateColDef.d.ts +3 -4
- package/colDef/gridDateColDef.js +10 -16
- package/colDef/gridNumericColDef.js +1 -3
- package/colDef/gridSingleSelectColDef.js +7 -12
- package/components/GridRow.js +1 -100
- package/components/cell/GridEditInputCell.js +1 -1
- package/components/columnsManagement/GridColumnsManagement.d.ts +43 -0
- package/components/columnsManagement/GridColumnsManagement.js +265 -0
- package/components/columnsManagement/index.d.ts +1 -0
- package/components/columnsManagement/index.js +1 -0
- package/components/columnsManagement/utils.d.ts +4 -0
- package/components/columnsManagement/utils.js +16 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +1 -0
- package/components/panel/GridColumnsPanel.d.ts +0 -28
- package/components/panel/GridColumnsPanel.js +5 -213
- package/constants/defaultGridSlotsComponents.js +2 -1
- package/constants/gridClasses.d.ts +12 -4
- package/constants/gridClasses.js +1 -1
- package/constants/localeTextConstants.js +4 -6
- package/hooks/core/useGridApiInitialization.js +4 -0
- package/hooks/features/columns/useGridColumnSpanning.js +3 -1
- package/hooks/features/editing/useGridCellEditing.js +2 -5
- package/hooks/features/editing/useGridRowEditing.js +2 -5
- package/hooks/features/filter/gridFilterUtils.js +1 -1
- package/hooks/features/rows/gridRowsUtils.js +4 -1
- package/hooks/features/rows/useGridParamsApi.d.ts +1 -2
- package/hooks/features/rows/useGridParamsApi.js +14 -49
- package/index.js +1 -1
- package/legacy/DataGrid/useDataGridComponent.js +1 -1
- package/legacy/colDef/gridBooleanColDef.js +3 -5
- package/legacy/colDef/gridCheckboxSelectionColDef.js +4 -3
- package/legacy/colDef/gridDateColDef.js +10 -14
- package/legacy/colDef/gridNumericColDef.js +1 -2
- package/legacy/colDef/gridSingleSelectColDef.js +7 -10
- package/legacy/components/GridRow.js +1 -100
- package/legacy/components/cell/GridEditInputCell.js +1 -1
- package/legacy/components/columnsManagement/GridColumnsManagement.js +307 -0
- package/legacy/components/columnsManagement/index.js +1 -0
- package/legacy/components/columnsManagement/utils.js +22 -0
- package/legacy/components/index.js +1 -0
- package/legacy/components/panel/GridColumnsPanel.js +5 -233
- package/legacy/constants/defaultGridSlotsComponents.js +2 -1
- package/legacy/constants/gridClasses.js +1 -1
- package/legacy/constants/localeTextConstants.js +4 -6
- package/legacy/hooks/core/useGridApiInitialization.js +4 -0
- package/legacy/hooks/features/columns/useGridColumnSpanning.js +3 -1
- package/legacy/hooks/features/editing/useGridCellEditing.js +2 -5
- package/legacy/hooks/features/editing/useGridRowEditing.js +2 -5
- package/legacy/hooks/features/filter/gridFilterUtils.js +2 -2
- package/legacy/hooks/features/rows/gridRowsUtils.js +4 -1
- package/legacy/hooks/features/rows/useGridParamsApi.js +14 -47
- package/legacy/index.js +1 -1
- package/legacy/locales/arSD.js +5 -6
- package/legacy/locales/beBY.js +5 -6
- package/legacy/locales/bgBG.js +5 -6
- package/legacy/locales/csCZ.js +5 -6
- package/legacy/locales/daDK.js +5 -6
- package/legacy/locales/deDE.js +5 -6
- package/legacy/locales/elGR.js +5 -6
- package/legacy/locales/esES.js +5 -6
- package/legacy/locales/faIR.js +5 -6
- package/legacy/locales/fiFI.js +5 -6
- package/legacy/locales/frFR.js +5 -6
- package/legacy/locales/heIL.js +12 -14
- package/legacy/locales/hrHR.js +5 -6
- package/legacy/locales/huHU.js +5 -6
- package/legacy/locales/itIT.js +5 -6
- package/legacy/locales/jaJP.js +5 -6
- package/legacy/locales/koKR.js +5 -6
- package/legacy/locales/nbNO.js +5 -6
- package/legacy/locales/nlNL.js +5 -6
- package/legacy/locales/plPL.js +5 -6
- package/legacy/locales/ptBR.js +5 -6
- package/legacy/locales/ptPT.js +5 -6
- package/legacy/locales/roRO.js +5 -6
- package/legacy/locales/ruRU.js +5 -6
- package/legacy/locales/skSK.js +5 -6
- package/legacy/locales/svSE.js +5 -6
- package/legacy/locales/trTR.js +5 -6
- package/legacy/locales/ukUA.js +5 -6
- package/legacy/locales/urPK.js +5 -6
- package/legacy/locales/viVN.js +5 -6
- package/legacy/locales/zhCN.js +5 -6
- package/legacy/locales/zhHK.js +5 -6
- package/legacy/locales/zhTW.js +5 -6
- package/locales/arSD.js +5 -6
- package/locales/beBY.js +5 -6
- package/locales/bgBG.js +5 -6
- package/locales/csCZ.js +5 -6
- package/locales/daDK.js +5 -6
- package/locales/deDE.js +5 -6
- package/locales/elGR.js +5 -6
- package/locales/esES.js +5 -6
- package/locales/faIR.js +5 -6
- package/locales/fiFI.js +5 -6
- package/locales/frFR.js +5 -6
- package/locales/heIL.js +12 -14
- package/locales/hrHR.js +5 -6
- package/locales/huHU.js +5 -6
- package/locales/itIT.js +5 -6
- package/locales/jaJP.js +5 -6
- package/locales/koKR.js +5 -6
- package/locales/nbNO.js +5 -6
- package/locales/nlNL.js +5 -6
- package/locales/plPL.js +5 -6
- package/locales/ptBR.js +5 -6
- package/locales/ptPT.js +5 -6
- package/locales/roRO.js +5 -6
- package/locales/ruRU.js +5 -6
- package/locales/skSK.js +5 -6
- package/locales/svSE.js +5 -6
- package/locales/trTR.js +5 -6
- package/locales/ukUA.js +5 -6
- package/locales/urPK.js +5 -6
- package/locales/viVN.js +5 -6
- package/locales/zhCN.js +5 -6
- package/locales/zhHK.js +5 -6
- package/locales/zhTW.js +5 -6
- package/models/api/gridLocaleTextApi.d.ts +3 -5
- package/models/colDef/gridColDef.d.ts +11 -17
- package/models/colDef/gridColType.d.ts +11 -2
- package/models/colDef/index.d.ts +1 -1
- package/models/gridSlotsComponent.d.ts +5 -0
- package/models/gridSlotsComponentsProps.d.ts +4 -0
- package/models/params/gridCellParams.d.ts +0 -26
- package/modern/DataGrid/useDataGridComponent.js +1 -1
- package/modern/colDef/gridBooleanColDef.js +3 -6
- package/modern/colDef/gridCheckboxSelectionColDef.js +4 -3
- package/modern/colDef/gridDateColDef.js +10 -16
- package/modern/colDef/gridNumericColDef.js +1 -3
- package/modern/colDef/gridSingleSelectColDef.js +7 -12
- package/modern/components/GridRow.js +1 -100
- package/modern/components/cell/GridEditInputCell.js +1 -1
- package/modern/components/columnsManagement/GridColumnsManagement.js +261 -0
- package/modern/components/columnsManagement/index.js +1 -0
- package/modern/components/columnsManagement/utils.js +16 -0
- package/modern/components/index.js +1 -0
- package/modern/components/panel/GridColumnsPanel.js +4 -209
- package/modern/constants/defaultGridSlotsComponents.js +2 -1
- package/modern/constants/gridClasses.js +1 -1
- package/modern/constants/localeTextConstants.js +4 -6
- package/modern/hooks/core/useGridApiInitialization.js +3 -0
- package/modern/hooks/features/columns/useGridColumnSpanning.js +3 -1
- package/modern/hooks/features/editing/useGridCellEditing.js +2 -5
- package/modern/hooks/features/editing/useGridRowEditing.js +2 -5
- package/modern/hooks/features/filter/gridFilterUtils.js +1 -1
- package/modern/hooks/features/rows/gridRowsUtils.js +4 -1
- package/modern/hooks/features/rows/useGridParamsApi.js +14 -47
- package/modern/index.js +1 -1
- package/modern/locales/arSD.js +5 -6
- package/modern/locales/beBY.js +5 -6
- package/modern/locales/bgBG.js +5 -6
- package/modern/locales/csCZ.js +5 -6
- package/modern/locales/daDK.js +5 -6
- package/modern/locales/deDE.js +5 -6
- package/modern/locales/elGR.js +5 -6
- package/modern/locales/esES.js +5 -6
- package/modern/locales/faIR.js +5 -6
- package/modern/locales/fiFI.js +5 -6
- package/modern/locales/frFR.js +5 -6
- package/modern/locales/heIL.js +12 -14
- package/modern/locales/hrHR.js +5 -6
- package/modern/locales/huHU.js +5 -6
- package/modern/locales/itIT.js +5 -6
- package/modern/locales/jaJP.js +5 -6
- package/modern/locales/koKR.js +5 -6
- package/modern/locales/nbNO.js +5 -6
- package/modern/locales/nlNL.js +5 -6
- package/modern/locales/plPL.js +5 -6
- package/modern/locales/ptBR.js +5 -6
- package/modern/locales/ptPT.js +5 -6
- package/modern/locales/roRO.js +5 -6
- package/modern/locales/ruRU.js +5 -6
- package/modern/locales/skSK.js +5 -6
- package/modern/locales/svSE.js +5 -6
- package/modern/locales/trTR.js +5 -6
- package/modern/locales/ukUA.js +5 -6
- package/modern/locales/urPK.js +5 -6
- package/modern/locales/viVN.js +5 -6
- package/modern/locales/zhCN.js +5 -6
- package/modern/locales/zhHK.js +5 -6
- package/modern/locales/zhTW.js +5 -6
- package/node/DataGrid/useDataGridComponent.js +1 -1
- package/node/colDef/gridBooleanColDef.js +3 -6
- package/node/colDef/gridCheckboxSelectionColDef.js +4 -3
- package/node/colDef/gridDateColDef.js +13 -19
- package/node/colDef/gridNumericColDef.js +1 -3
- package/node/colDef/gridSingleSelectColDef.js +7 -12
- package/node/components/GridRow.js +1 -100
- package/node/components/cell/GridEditInputCell.js +1 -1
- package/node/components/columnsManagement/GridColumnsManagement.js +269 -0
- package/node/components/columnsManagement/index.js +16 -0
- package/node/components/columnsManagement/utils.js +24 -0
- package/node/components/index.js +11 -0
- package/node/components/panel/GridColumnsPanel.js +4 -208
- package/node/constants/defaultGridSlotsComponents.js +1 -0
- package/node/constants/gridClasses.js +1 -1
- package/node/constants/localeTextConstants.js +4 -6
- package/node/hooks/core/useGridApiInitialization.js +3 -0
- package/node/hooks/features/columns/useGridColumnSpanning.js +3 -1
- package/node/hooks/features/editing/useGridCellEditing.js +2 -5
- package/node/hooks/features/editing/useGridRowEditing.js +2 -5
- package/node/hooks/features/filter/gridFilterUtils.js +1 -1
- package/node/hooks/features/rows/gridRowsUtils.js +4 -1
- package/node/hooks/features/rows/useGridParamsApi.js +14 -47
- package/node/index.js +1 -1
- package/node/locales/arSD.js +5 -6
- package/node/locales/beBY.js +5 -6
- package/node/locales/bgBG.js +5 -6
- package/node/locales/csCZ.js +5 -6
- package/node/locales/daDK.js +5 -6
- package/node/locales/deDE.js +5 -6
- package/node/locales/elGR.js +5 -6
- package/node/locales/esES.js +5 -6
- package/node/locales/faIR.js +5 -6
- package/node/locales/fiFI.js +5 -6
- package/node/locales/frFR.js +5 -6
- package/node/locales/heIL.js +12 -14
- package/node/locales/hrHR.js +5 -6
- package/node/locales/huHU.js +5 -6
- package/node/locales/itIT.js +5 -6
- package/node/locales/jaJP.js +5 -6
- package/node/locales/koKR.js +5 -6
- package/node/locales/nbNO.js +5 -6
- package/node/locales/nlNL.js +5 -6
- package/node/locales/plPL.js +5 -6
- package/node/locales/ptBR.js +5 -6
- package/node/locales/ptPT.js +5 -6
- package/node/locales/roRO.js +5 -6
- package/node/locales/ruRU.js +5 -6
- package/node/locales/skSK.js +5 -6
- package/node/locales/svSE.js +5 -6
- package/node/locales/trTR.js +5 -6
- package/node/locales/ukUA.js +5 -6
- package/node/locales/urPK.js +5 -6
- package/node/locales/viVN.js +5 -6
- package/node/locales/zhCN.js +5 -6
- package/node/locales/zhHK.js +5 -6
- package/node/locales/zhTW.js +5 -6
- package/package.json +4 -4
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
6
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
7
|
+
import { styled } from '@mui/material/styles';
|
|
8
|
+
import { gridColumnDefinitionsSelector, gridColumnVisibilityModelSelector } from '../../hooks/features/columns/gridColumnsSelector';
|
|
9
|
+
import { useGridSelector } from '../../hooks/utils/useGridSelector';
|
|
10
|
+
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
|
|
11
|
+
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
|
|
12
|
+
import { getDataGridUtilityClass } from '../../constants/gridClasses';
|
|
13
|
+
import { useLazyRef } from '../../hooks/utils/useLazyRef';
|
|
14
|
+
import { checkColumnVisibilityModelsSame, defaultSearchPredicate } from './utils';
|
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
const useUtilityClasses = ownerState => {
|
|
18
|
+
const {
|
|
19
|
+
classes
|
|
20
|
+
} = ownerState;
|
|
21
|
+
const slots = {
|
|
22
|
+
root: ['columnsManagement'],
|
|
23
|
+
header: ['columnsManagementHeader'],
|
|
24
|
+
footer: ['columnsManagementFooter'],
|
|
25
|
+
row: ['columnsManagementRow']
|
|
26
|
+
};
|
|
27
|
+
return composeClasses(slots, getDataGridUtilityClass, classes);
|
|
28
|
+
};
|
|
29
|
+
const collator = new Intl.Collator();
|
|
30
|
+
function GridColumnsManagement(props) {
|
|
31
|
+
const apiRef = useGridApiContext();
|
|
32
|
+
const searchInputRef = React.useRef(null);
|
|
33
|
+
const columns = useGridSelector(apiRef, gridColumnDefinitionsSelector);
|
|
34
|
+
const initialColumnVisibilityModel = useLazyRef(() => gridColumnVisibilityModelSelector(apiRef)).current;
|
|
35
|
+
const columnVisibilityModel = useGridSelector(apiRef, gridColumnVisibilityModelSelector);
|
|
36
|
+
const rootProps = useGridRootProps();
|
|
37
|
+
const [searchValue, setSearchValue] = React.useState('');
|
|
38
|
+
const classes = useUtilityClasses(rootProps);
|
|
39
|
+
const {
|
|
40
|
+
sort,
|
|
41
|
+
searchPredicate = defaultSearchPredicate,
|
|
42
|
+
autoFocusSearchField = true,
|
|
43
|
+
disableShowHideToggle = false,
|
|
44
|
+
disableResetButton = false,
|
|
45
|
+
toggleAllMode = 'all',
|
|
46
|
+
getTogglableColumns
|
|
47
|
+
} = props;
|
|
48
|
+
const isResetDisabled = React.useMemo(() => checkColumnVisibilityModelsSame(columnVisibilityModel, initialColumnVisibilityModel), [columnVisibilityModel, initialColumnVisibilityModel]);
|
|
49
|
+
const sortedColumns = React.useMemo(() => {
|
|
50
|
+
switch (sort) {
|
|
51
|
+
case 'asc':
|
|
52
|
+
return [...columns].sort((a, b) => collator.compare(a.headerName || a.field, b.headerName || b.field));
|
|
53
|
+
case 'desc':
|
|
54
|
+
return [...columns].sort((a, b) => -collator.compare(a.headerName || a.field, b.headerName || b.field));
|
|
55
|
+
default:
|
|
56
|
+
return columns;
|
|
57
|
+
}
|
|
58
|
+
}, [columns, sort]);
|
|
59
|
+
const toggleColumn = event => {
|
|
60
|
+
const {
|
|
61
|
+
name: field
|
|
62
|
+
} = event.target;
|
|
63
|
+
apiRef.current.setColumnVisibility(field, columnVisibilityModel[field] === false);
|
|
64
|
+
};
|
|
65
|
+
const currentColumns = React.useMemo(() => {
|
|
66
|
+
const togglableColumns = getTogglableColumns ? getTogglableColumns(sortedColumns) : null;
|
|
67
|
+
const togglableSortedColumns = togglableColumns ? sortedColumns.filter(({
|
|
68
|
+
field
|
|
69
|
+
}) => togglableColumns.includes(field)) : sortedColumns;
|
|
70
|
+
if (!searchValue) {
|
|
71
|
+
return togglableSortedColumns;
|
|
72
|
+
}
|
|
73
|
+
return togglableSortedColumns.filter(column => searchPredicate(column, searchValue.toLowerCase()));
|
|
74
|
+
}, [sortedColumns, searchValue, searchPredicate, getTogglableColumns]);
|
|
75
|
+
const toggleAllColumns = React.useCallback(isVisible => {
|
|
76
|
+
const currentModel = gridColumnVisibilityModelSelector(apiRef);
|
|
77
|
+
const newModel = _extends({}, currentModel);
|
|
78
|
+
const togglableColumns = getTogglableColumns ? getTogglableColumns(columns) : null;
|
|
79
|
+
(toggleAllMode === 'filteredOnly' ? currentColumns : columns).forEach(col => {
|
|
80
|
+
if (col.hideable && (togglableColumns == null || togglableColumns.includes(col.field))) {
|
|
81
|
+
if (isVisible) {
|
|
82
|
+
// delete the key from the model instead of setting it to `true`
|
|
83
|
+
delete newModel[col.field];
|
|
84
|
+
} else {
|
|
85
|
+
newModel[col.field] = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return apiRef.current.setColumnVisibilityModel(newModel);
|
|
90
|
+
}, [apiRef, columns, getTogglableColumns, toggleAllMode, currentColumns]);
|
|
91
|
+
const handleSearchValueChange = React.useCallback(event => {
|
|
92
|
+
setSearchValue(event.target.value);
|
|
93
|
+
}, []);
|
|
94
|
+
const hideableColumns = React.useMemo(() => currentColumns.filter(col => col.hideable), [currentColumns]);
|
|
95
|
+
const allHideableColumnsVisible = React.useMemo(() => hideableColumns.every(column => columnVisibilityModel[column.field] == null || columnVisibilityModel[column.field] !== false), [columnVisibilityModel, hideableColumns]);
|
|
96
|
+
const allHideableColumnsHidden = React.useMemo(() => hideableColumns.every(column => columnVisibilityModel[column.field] === false), [columnVisibilityModel, hideableColumns]);
|
|
97
|
+
const firstSwitchRef = React.useRef(null);
|
|
98
|
+
React.useEffect(() => {
|
|
99
|
+
if (autoFocusSearchField) {
|
|
100
|
+
searchInputRef.current.focus();
|
|
101
|
+
} else if (firstSwitchRef.current && typeof firstSwitchRef.current.focus === 'function') {
|
|
102
|
+
firstSwitchRef.current.focus();
|
|
103
|
+
}
|
|
104
|
+
}, [autoFocusSearchField]);
|
|
105
|
+
let firstHideableColumnFound = false;
|
|
106
|
+
const isFirstHideableColumn = column => {
|
|
107
|
+
if (firstHideableColumnFound === false && column.hideable !== false) {
|
|
108
|
+
firstHideableColumnFound = true;
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
};
|
|
113
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
114
|
+
children: [/*#__PURE__*/_jsx(GridColumnsManagementHeader, {
|
|
115
|
+
className: classes.header,
|
|
116
|
+
ownerState: rootProps,
|
|
117
|
+
children: /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
|
|
118
|
+
placeholder: apiRef.current.getLocaleText('columnsManagementSearchTitle'),
|
|
119
|
+
inputRef: searchInputRef,
|
|
120
|
+
value: searchValue,
|
|
121
|
+
onChange: handleSearchValueChange,
|
|
122
|
+
variant: "outlined",
|
|
123
|
+
size: "small",
|
|
124
|
+
InputProps: {
|
|
125
|
+
startAdornment: /*#__PURE__*/_jsx(rootProps.slots.baseInputAdornment, {
|
|
126
|
+
position: "start",
|
|
127
|
+
children: /*#__PURE__*/_jsx(rootProps.slots.quickFilterIcon, {})
|
|
128
|
+
}),
|
|
129
|
+
sx: {
|
|
130
|
+
pl: 1.5
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
fullWidth: true
|
|
134
|
+
}, rootProps.slotProps?.baseTextField))
|
|
135
|
+
}), /*#__PURE__*/_jsxs(GridColumnsManagementBody, {
|
|
136
|
+
className: classes.root,
|
|
137
|
+
ownerState: rootProps,
|
|
138
|
+
children: [currentColumns.map(column => /*#__PURE__*/_jsx(FormControlLabel, {
|
|
139
|
+
className: classes.row,
|
|
140
|
+
control: /*#__PURE__*/_jsx(rootProps.slots.baseCheckbox, _extends({
|
|
141
|
+
disabled: column.hideable === false,
|
|
142
|
+
checked: columnVisibilityModel[column.field] !== false,
|
|
143
|
+
onClick: toggleColumn,
|
|
144
|
+
name: column.field,
|
|
145
|
+
sx: {
|
|
146
|
+
p: 0.5
|
|
147
|
+
},
|
|
148
|
+
inputRef: isFirstHideableColumn(column) ? firstSwitchRef : undefined
|
|
149
|
+
}, rootProps.slotProps?.baseCheckbox)),
|
|
150
|
+
label: column.headerName || column.field
|
|
151
|
+
}, column.field)), currentColumns.length === 0 && /*#__PURE__*/_jsx(GridColumnsManagementEmptyText, {
|
|
152
|
+
ownerState: rootProps,
|
|
153
|
+
children: apiRef.current.getLocaleText('columnsManagementNoColumns')
|
|
154
|
+
})]
|
|
155
|
+
}), !disableShowHideToggle && !disableResetButton && currentColumns.length > 0 ? /*#__PURE__*/_jsxs(GridColumnsManagementFooter, {
|
|
156
|
+
ownerState: rootProps,
|
|
157
|
+
className: classes.footer,
|
|
158
|
+
children: [!disableShowHideToggle ? /*#__PURE__*/_jsx(FormControlLabel, {
|
|
159
|
+
control: /*#__PURE__*/_jsx(rootProps.slots.baseCheckbox, _extends({
|
|
160
|
+
disabled: hideableColumns.length === 0,
|
|
161
|
+
checked: allHideableColumnsVisible,
|
|
162
|
+
indeterminate: !allHideableColumnsVisible && !allHideableColumnsHidden,
|
|
163
|
+
onClick: () => toggleAllColumns(!allHideableColumnsVisible),
|
|
164
|
+
name: apiRef.current.getLocaleText('columnsManagementShowHideAllText'),
|
|
165
|
+
sx: {
|
|
166
|
+
p: 0.5
|
|
167
|
+
}
|
|
168
|
+
}, rootProps.slotProps?.baseCheckbox)),
|
|
169
|
+
label: apiRef.current.getLocaleText('columnsManagementShowHideAllText')
|
|
170
|
+
}) : /*#__PURE__*/_jsx("span", {}), !disableResetButton ? /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
|
|
171
|
+
onClick: () => apiRef.current.setColumnVisibilityModel(initialColumnVisibilityModel),
|
|
172
|
+
disabled: isResetDisabled
|
|
173
|
+
}, rootProps.slotProps?.baseButton, {
|
|
174
|
+
children: "Reset"
|
|
175
|
+
})) : null]
|
|
176
|
+
}) : null]
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
process.env.NODE_ENV !== "production" ? GridColumnsManagement.propTypes = {
|
|
180
|
+
// ----------------------------- Warning --------------------------------
|
|
181
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
182
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
183
|
+
// ----------------------------------------------------------------------
|
|
184
|
+
/**
|
|
185
|
+
* If `true`, the column search field will be focused automatically.
|
|
186
|
+
* If `false`, the first column switch input will be focused automatically.
|
|
187
|
+
* This helps to avoid input keyboard panel to popup automatically on touch devices.
|
|
188
|
+
* @default true
|
|
189
|
+
*/
|
|
190
|
+
autoFocusSearchField: PropTypes.bool,
|
|
191
|
+
/**
|
|
192
|
+
* If `true`, the `Reset` button will not be disabled
|
|
193
|
+
* @default false
|
|
194
|
+
*/
|
|
195
|
+
disableResetButton: PropTypes.bool,
|
|
196
|
+
/**
|
|
197
|
+
* If `true`, the `Show/Hide all` toggle checkbox will not be displayed.
|
|
198
|
+
* @default false
|
|
199
|
+
*/
|
|
200
|
+
disableShowHideToggle: PropTypes.bool,
|
|
201
|
+
/**
|
|
202
|
+
* Returns the list of togglable columns.
|
|
203
|
+
* If used, only those columns will be displayed in the panel
|
|
204
|
+
* which are passed as the return value of the function.
|
|
205
|
+
* @param {GridColDef[]} columns The `ColDef` list of all columns.
|
|
206
|
+
* @returns {GridColDef['field'][]} The list of togglable columns' field names.
|
|
207
|
+
*/
|
|
208
|
+
getTogglableColumns: PropTypes.func,
|
|
209
|
+
searchPredicate: PropTypes.func,
|
|
210
|
+
sort: PropTypes.oneOf(['asc', 'desc']),
|
|
211
|
+
/**
|
|
212
|
+
* Changes the behavior of the `Show/Hide All` toggle when the search field is used:
|
|
213
|
+
* - `all`: Will toggle all columns.
|
|
214
|
+
* - `filteredOnly`: Will only toggle columns that match the search criteria.
|
|
215
|
+
* @default 'all'
|
|
216
|
+
*/
|
|
217
|
+
toggleAllMode: PropTypes.oneOf(['all', 'filteredOnly'])
|
|
218
|
+
} : void 0;
|
|
219
|
+
const GridColumnsManagementBody = styled('div', {
|
|
220
|
+
name: 'MuiDataGrid',
|
|
221
|
+
slot: 'ColumnsManagement',
|
|
222
|
+
overridesResolver: (props, styles) => styles.columnsManagement
|
|
223
|
+
})(({
|
|
224
|
+
theme
|
|
225
|
+
}) => ({
|
|
226
|
+
padding: theme.spacing(0, 3, 1.5),
|
|
227
|
+
display: 'flex',
|
|
228
|
+
flexDirection: 'column',
|
|
229
|
+
overflow: 'auto',
|
|
230
|
+
flex: '1 1',
|
|
231
|
+
maxHeight: 400,
|
|
232
|
+
alignItems: 'flex-start'
|
|
233
|
+
}));
|
|
234
|
+
const GridColumnsManagementHeader = styled('div', {
|
|
235
|
+
name: 'MuiDataGrid',
|
|
236
|
+
slot: 'ColumnsManagementHeader',
|
|
237
|
+
overridesResolver: (props, styles) => styles.columnsManagementHeader
|
|
238
|
+
})(({
|
|
239
|
+
theme
|
|
240
|
+
}) => ({
|
|
241
|
+
padding: theme.spacing(1.5, 3)
|
|
242
|
+
}));
|
|
243
|
+
const GridColumnsManagementFooter = styled('div', {
|
|
244
|
+
name: 'MuiDataGrid',
|
|
245
|
+
slot: 'ColumnsManagementFooter',
|
|
246
|
+
overridesResolver: (props, styles) => styles.columnsManagementFooter
|
|
247
|
+
})(({
|
|
248
|
+
theme
|
|
249
|
+
}) => ({
|
|
250
|
+
padding: theme.spacing(0.5, 1, 0.5, 3),
|
|
251
|
+
display: 'flex',
|
|
252
|
+
justifyContent: 'space-between',
|
|
253
|
+
borderTop: `1px solid ${theme.palette.divider}`
|
|
254
|
+
}));
|
|
255
|
+
const GridColumnsManagementEmptyText = styled('div')(({
|
|
256
|
+
theme
|
|
257
|
+
}) => ({
|
|
258
|
+
padding: theme.spacing(0.5, 0),
|
|
259
|
+
color: theme.palette.grey[500]
|
|
260
|
+
}));
|
|
261
|
+
export { GridColumnsManagement };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GridColumnsManagement';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const checkColumnVisibilityModelsSame = (a, b) => {
|
|
2
|
+
// Filter `false` values only, as `true` and not having a key are the same
|
|
3
|
+
const aFalseValues = new Set(Object.keys(a).filter(key => a[key] === false));
|
|
4
|
+
const bFalseValues = new Set(Object.keys(b).filter(key => b[key] === false));
|
|
5
|
+
if (aFalseValues.size !== bFalseValues.size) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
let result = true;
|
|
9
|
+
aFalseValues.forEach(key => {
|
|
10
|
+
if (!bFalseValues.has(key)) {
|
|
11
|
+
result = false;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
export const defaultSearchPredicate = (column, searchValue) => (column.headerName || column.field).toLowerCase().indexOf(searchValue) > -1;
|
|
@@ -1,192 +1,14 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["sort", "searchPredicate", "autoFocusSearchField", "disableHideAllButton", "disableShowAllButton", "getTogglableColumns"];
|
|
4
2
|
import * as React from 'react';
|
|
5
3
|
import PropTypes from 'prop-types';
|
|
6
|
-
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
7
|
-
import IconButton from '@mui/material/IconButton';
|
|
8
|
-
import { switchClasses } from '@mui/material/Switch';
|
|
9
|
-
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
10
|
-
import { styled } from '@mui/material/styles';
|
|
11
|
-
import { gridColumnDefinitionsSelector, gridColumnVisibilityModelSelector } from '../../hooks/features/columns/gridColumnsSelector';
|
|
12
|
-
import { useGridSelector } from '../../hooks/utils/useGridSelector';
|
|
13
|
-
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
|
|
14
|
-
import { GridPanelContent } from './GridPanelContent';
|
|
15
|
-
import { GridPanelFooter } from './GridPanelFooter';
|
|
16
|
-
import { GridPanelHeader } from './GridPanelHeader';
|
|
17
4
|
import { GridPanelWrapper } from './GridPanelWrapper';
|
|
18
|
-
import {
|
|
5
|
+
import { GridColumnsManagement } from '../columnsManagement';
|
|
19
6
|
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
|
|
20
|
-
import { getDataGridUtilityClass } from '../../constants/gridClasses';
|
|
21
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
|
-
const useUtilityClasses = ownerState => {
|
|
24
|
-
const {
|
|
25
|
-
classes
|
|
26
|
-
} = ownerState;
|
|
27
|
-
const slots = {
|
|
28
|
-
root: ['columnsPanel'],
|
|
29
|
-
columnsPanelRow: ['columnsPanelRow']
|
|
30
|
-
};
|
|
31
|
-
return composeClasses(slots, getDataGridUtilityClass, classes);
|
|
32
|
-
};
|
|
33
|
-
const GridColumnsPanelRoot = styled('div', {
|
|
34
|
-
name: 'MuiDataGrid',
|
|
35
|
-
slot: 'ColumnsPanel',
|
|
36
|
-
overridesResolver: (props, styles) => styles.columnsPanel
|
|
37
|
-
})({
|
|
38
|
-
padding: '8px 0px 8px 8px'
|
|
39
|
-
});
|
|
40
|
-
const GridColumnsPanelRowRoot = styled('div', {
|
|
41
|
-
name: 'MuiDataGrid',
|
|
42
|
-
slot: 'ColumnsPanelRow',
|
|
43
|
-
overridesResolver: (props, styles) => styles.columnsPanelRow
|
|
44
|
-
})(({
|
|
45
|
-
theme
|
|
46
|
-
}) => ({
|
|
47
|
-
display: 'flex',
|
|
48
|
-
justifyContent: 'space-between',
|
|
49
|
-
padding: '1px 8px 1px 7px',
|
|
50
|
-
[`& .${switchClasses.root}`]: {
|
|
51
|
-
marginRight: theme.spacing(0.5)
|
|
52
|
-
}
|
|
53
|
-
}));
|
|
54
|
-
const GridIconButtonRoot = styled(IconButton)({
|
|
55
|
-
justifyContent: 'flex-end'
|
|
56
|
-
});
|
|
57
|
-
const collator = new Intl.Collator();
|
|
58
|
-
const defaultSearchPredicate = (column, searchValue) => {
|
|
59
|
-
return (column.headerName || column.field).toLowerCase().indexOf(searchValue) > -1;
|
|
60
|
-
};
|
|
61
8
|
function GridColumnsPanel(props) {
|
|
62
|
-
const apiRef = useGridApiContext();
|
|
63
|
-
const searchInputRef = React.useRef(null);
|
|
64
|
-
const columns = useGridSelector(apiRef, gridColumnDefinitionsSelector);
|
|
65
|
-
const columnVisibilityModel = useGridSelector(apiRef, gridColumnVisibilityModelSelector);
|
|
66
9
|
const rootProps = useGridRootProps();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const {
|
|
70
|
-
sort,
|
|
71
|
-
searchPredicate = defaultSearchPredicate,
|
|
72
|
-
autoFocusSearchField = true,
|
|
73
|
-
disableHideAllButton = false,
|
|
74
|
-
disableShowAllButton = false,
|
|
75
|
-
getTogglableColumns
|
|
76
|
-
} = props,
|
|
77
|
-
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
78
|
-
const sortedColumns = React.useMemo(() => {
|
|
79
|
-
switch (sort) {
|
|
80
|
-
case 'asc':
|
|
81
|
-
return [...columns].sort((a, b) => collator.compare(a.headerName || a.field, b.headerName || b.field));
|
|
82
|
-
case 'desc':
|
|
83
|
-
return [...columns].sort((a, b) => -collator.compare(a.headerName || a.field, b.headerName || b.field));
|
|
84
|
-
default:
|
|
85
|
-
return columns;
|
|
86
|
-
}
|
|
87
|
-
}, [columns, sort]);
|
|
88
|
-
const toggleColumn = event => {
|
|
89
|
-
const {
|
|
90
|
-
name: field
|
|
91
|
-
} = event.target;
|
|
92
|
-
apiRef.current.setColumnVisibility(field, columnVisibilityModel[field] === false);
|
|
93
|
-
};
|
|
94
|
-
const toggleAllColumns = React.useCallback(isVisible => {
|
|
95
|
-
const currentModel = gridColumnVisibilityModelSelector(apiRef);
|
|
96
|
-
const newModel = _extends({}, currentModel);
|
|
97
|
-
const togglableColumns = getTogglableColumns ? getTogglableColumns(columns) : null;
|
|
98
|
-
columns.forEach(col => {
|
|
99
|
-
if (col.hideable && (togglableColumns == null || togglableColumns.includes(col.field))) {
|
|
100
|
-
if (isVisible) {
|
|
101
|
-
// delete the key from the model instead of setting it to `true`
|
|
102
|
-
delete newModel[col.field];
|
|
103
|
-
} else {
|
|
104
|
-
newModel[col.field] = false;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
return apiRef.current.setColumnVisibilityModel(newModel);
|
|
109
|
-
}, [apiRef, columns, getTogglableColumns]);
|
|
110
|
-
const handleSearchValueChange = React.useCallback(event => {
|
|
111
|
-
setSearchValue(event.target.value);
|
|
112
|
-
}, []);
|
|
113
|
-
const currentColumns = React.useMemo(() => {
|
|
114
|
-
const togglableColumns = getTogglableColumns ? getTogglableColumns(sortedColumns) : null;
|
|
115
|
-
const togglableSortedColumns = togglableColumns ? sortedColumns.filter(({
|
|
116
|
-
field
|
|
117
|
-
}) => togglableColumns.includes(field)) : sortedColumns;
|
|
118
|
-
if (!searchValue) {
|
|
119
|
-
return togglableSortedColumns;
|
|
120
|
-
}
|
|
121
|
-
return togglableSortedColumns.filter(column => searchPredicate(column, searchValue.toLowerCase()));
|
|
122
|
-
}, [sortedColumns, searchValue, searchPredicate, getTogglableColumns]);
|
|
123
|
-
const firstSwitchRef = React.useRef(null);
|
|
124
|
-
React.useEffect(() => {
|
|
125
|
-
if (autoFocusSearchField) {
|
|
126
|
-
searchInputRef.current.focus();
|
|
127
|
-
} else if (firstSwitchRef.current && typeof firstSwitchRef.current.focus === 'function') {
|
|
128
|
-
firstSwitchRef.current.focus();
|
|
129
|
-
}
|
|
130
|
-
}, [autoFocusSearchField]);
|
|
131
|
-
let firstHideableColumnFound = false;
|
|
132
|
-
const isFirstHideableColumn = column => {
|
|
133
|
-
if (firstHideableColumnFound === false && column.hideable !== false) {
|
|
134
|
-
firstHideableColumnFound = true;
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
return false;
|
|
138
|
-
};
|
|
139
|
-
return /*#__PURE__*/_jsxs(GridPanelWrapper, _extends({}, other, {
|
|
140
|
-
children: [/*#__PURE__*/_jsx(GridPanelHeader, {
|
|
141
|
-
children: /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
|
|
142
|
-
label: apiRef.current.getLocaleText('columnsPanelTextFieldLabel'),
|
|
143
|
-
placeholder: apiRef.current.getLocaleText('columnsPanelTextFieldPlaceholder'),
|
|
144
|
-
inputRef: searchInputRef,
|
|
145
|
-
value: searchValue,
|
|
146
|
-
onChange: handleSearchValueChange,
|
|
147
|
-
variant: "standard",
|
|
148
|
-
fullWidth: true
|
|
149
|
-
}, rootProps.slotProps?.baseTextField))
|
|
150
|
-
}), /*#__PURE__*/_jsx(GridPanelContent, {
|
|
151
|
-
children: /*#__PURE__*/_jsx(GridColumnsPanelRoot, {
|
|
152
|
-
className: classes.root,
|
|
153
|
-
ownerState: rootProps,
|
|
154
|
-
children: currentColumns.map(column => /*#__PURE__*/_jsxs(GridColumnsPanelRowRoot, {
|
|
155
|
-
className: classes.columnsPanelRow,
|
|
156
|
-
ownerState: rootProps,
|
|
157
|
-
children: [/*#__PURE__*/_jsx(FormControlLabel, {
|
|
158
|
-
control: /*#__PURE__*/_jsx(rootProps.slots.baseSwitch, _extends({
|
|
159
|
-
disabled: column.hideable === false,
|
|
160
|
-
checked: columnVisibilityModel[column.field] !== false,
|
|
161
|
-
onClick: toggleColumn,
|
|
162
|
-
name: column.field,
|
|
163
|
-
size: "small",
|
|
164
|
-
inputRef: isFirstHideableColumn(column) ? firstSwitchRef : undefined
|
|
165
|
-
}, rootProps.slotProps?.baseSwitch)),
|
|
166
|
-
label: column.headerName || column.field
|
|
167
|
-
}), !rootProps.disableColumnReorder && GRID_EXPERIMENTAL_ENABLED && /*#__PURE__*/_jsx(GridIconButtonRoot, {
|
|
168
|
-
draggable: true,
|
|
169
|
-
"aria-label": apiRef.current.getLocaleText('columnsPanelDragIconLabel'),
|
|
170
|
-
title: apiRef.current.getLocaleText('columnsPanelDragIconLabel'),
|
|
171
|
-
size: "small",
|
|
172
|
-
disabled: true,
|
|
173
|
-
children: /*#__PURE__*/_jsx(rootProps.slots.columnReorderIcon, {})
|
|
174
|
-
})]
|
|
175
|
-
}, column.field))
|
|
176
|
-
})
|
|
177
|
-
}), disableShowAllButton && disableHideAllButton ? null : /*#__PURE__*/_jsxs(GridPanelFooter, {
|
|
178
|
-
children: [!disableHideAllButton ? /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
|
|
179
|
-
onClick: () => toggleAllColumns(false)
|
|
180
|
-
}, rootProps.slotProps?.baseButton, {
|
|
181
|
-
disabled: disableHideAllButton,
|
|
182
|
-
children: apiRef.current.getLocaleText('columnsPanelHideAllButton')
|
|
183
|
-
})) : /*#__PURE__*/_jsx("span", {}), !disableShowAllButton ? /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
|
|
184
|
-
onClick: () => toggleAllColumns(true)
|
|
185
|
-
}, rootProps.slotProps?.baseButton, {
|
|
186
|
-
disabled: disableShowAllButton,
|
|
187
|
-
children: apiRef.current.getLocaleText('columnsPanelShowAllButton')
|
|
188
|
-
})) : null]
|
|
189
|
-
})]
|
|
10
|
+
return /*#__PURE__*/_jsx(GridPanelWrapper, _extends({}, props, {
|
|
11
|
+
children: /*#__PURE__*/_jsx(GridColumnsManagement, _extends({}, rootProps.slotProps?.columnsManagement))
|
|
190
12
|
}));
|
|
191
13
|
}
|
|
192
14
|
process.env.NODE_ENV !== "production" ? GridColumnsPanel.propTypes = {
|
|
@@ -194,33 +16,6 @@ process.env.NODE_ENV !== "production" ? GridColumnsPanel.propTypes = {
|
|
|
194
16
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
195
17
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
196
18
|
// ----------------------------------------------------------------------
|
|
197
|
-
|
|
198
|
-
* If `true`, the column search field will be focused automatically.
|
|
199
|
-
* If `false`, the first column switch input will be focused automatically.
|
|
200
|
-
* This helps to avoid input keyboard panel to popup automatically on touch devices.
|
|
201
|
-
* @default true
|
|
202
|
-
*/
|
|
203
|
-
autoFocusSearchField: PropTypes.bool,
|
|
204
|
-
/**
|
|
205
|
-
* If `true`, the `Hide all` button will not be displayed.
|
|
206
|
-
* @default false
|
|
207
|
-
*/
|
|
208
|
-
disableHideAllButton: PropTypes.bool,
|
|
209
|
-
/**
|
|
210
|
-
* If `true`, the `Show all` button will be disabled
|
|
211
|
-
* @default false
|
|
212
|
-
*/
|
|
213
|
-
disableShowAllButton: PropTypes.bool,
|
|
214
|
-
/**
|
|
215
|
-
* Returns the list of togglable columns.
|
|
216
|
-
* If used, only those columns will be displayed in the panel
|
|
217
|
-
* which are passed as the return value of the function.
|
|
218
|
-
* @param {GridColDef[]} columns The `ColDef` list of all columns.
|
|
219
|
-
* @returns {GridColDef['field'][]} The list of togglable columns' field names.
|
|
220
|
-
*/
|
|
221
|
-
getTogglableColumns: PropTypes.func,
|
|
222
|
-
searchPredicate: PropTypes.func,
|
|
223
|
-
slotProps: PropTypes.object,
|
|
224
|
-
sort: PropTypes.oneOf(['asc', 'desc'])
|
|
19
|
+
slotProps: PropTypes.object
|
|
225
20
|
} : void 0;
|
|
226
21
|
export { GridColumnsPanel };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import { GridSkeletonCell, GridColumnsPanel, GridFilterPanel, GridFooter, GridLoadingOverlay, GridNoRowsOverlay, GridPagination, GridPanel, GridRow, GridColumnHeaderFilterIconButton, GridRowCount } from '../components';
|
|
2
|
+
import { GridSkeletonCell, GridColumnsPanel, GridFilterPanel, GridFooter, GridLoadingOverlay, GridNoRowsOverlay, GridPagination, GridPanel, GridRow, GridColumnHeaderFilterIconButton, GridRowCount, GridColumnsManagement } from '../components';
|
|
3
3
|
import { GridCell } from '../components/cell/GridCell';
|
|
4
4
|
import { GridColumnHeaders } from '../components/GridColumnHeaders';
|
|
5
5
|
import { GridColumnMenu } from '../components/menu/columnMenu/GridColumnMenu';
|
|
@@ -27,6 +27,7 @@ export const DATA_GRID_DEFAULT_SLOTS_COMPONENTS = _extends({}, materialSlots, {
|
|
|
27
27
|
pagination: GridPagination,
|
|
28
28
|
filterPanel: GridFilterPanel,
|
|
29
29
|
columnsPanel: GridColumnsPanel,
|
|
30
|
+
columnsManagement: GridColumnsManagement,
|
|
30
31
|
panel: GridPanel,
|
|
31
32
|
row: GridRow
|
|
32
33
|
});
|
|
@@ -2,4 +2,4 @@ import { unstable_generateUtilityClasses as generateUtilityClasses, unstable_gen
|
|
|
2
2
|
export function getDataGridUtilityClass(slot) {
|
|
3
3
|
return generateUtilityClass('MuiDataGrid', slot);
|
|
4
4
|
}
|
|
5
|
-
export const gridClasses = generateUtilityClasses('MuiDataGrid', ['actionsCell', 'aggregationColumnHeader', 'aggregationColumnHeader--alignLeft', 'aggregationColumnHeader--alignCenter', 'aggregationColumnHeader--alignRight', 'aggregationColumnHeaderLabel', 'autoHeight', 'autosizing', 'booleanCell', 'cell--editable', 'cell--editing', 'cell--textCenter', 'cell--textLeft', 'cell--textRight', 'cell--withRenderer', 'cell--rangeTop', 'cell--rangeBottom', 'cell--rangeLeft', 'cell--rangeRight', 'cell--pinnedLeft', 'cell--pinnedRight', 'cell--selectionMode', 'cell', 'cellContent', 'cellCheckbox', 'cellEmpty', 'cellSkeleton', 'checkboxInput', 'columnHeader--alignCenter', 'columnHeader--alignLeft', 'columnHeader--alignRight', 'columnHeader--dragging', 'columnHeader--moving', 'columnHeader--numeric', 'columnHeader--sortable', 'columnHeader--sorted', 'columnHeader--filtered', 'columnHeader', 'columnHeaderCheckbox', 'columnHeaderDraggableContainer', 'columnHeaderDropZone', 'columnHeaderTitle', 'columnHeaderTitleContainer', 'columnHeaderTitleContainerContent', 'columnGroupHeader', 'columnHeader--filledGroup', 'columnHeader--emptyGroup', 'columnHeader--showColumnBorder', 'columnHeaders', 'columnHeadersInner', 'columnHeadersInner--scrollable', 'columnSeparator--resizable', 'columnSeparator--resizing', 'columnSeparator--sideLeft', 'columnSeparator--sideRight', 'columnSeparator', '
|
|
5
|
+
export const gridClasses = generateUtilityClasses('MuiDataGrid', ['actionsCell', 'aggregationColumnHeader', 'aggregationColumnHeader--alignLeft', 'aggregationColumnHeader--alignCenter', 'aggregationColumnHeader--alignRight', 'aggregationColumnHeaderLabel', 'autoHeight', 'autosizing', 'booleanCell', 'cell--editable', 'cell--editing', 'cell--textCenter', 'cell--textLeft', 'cell--textRight', 'cell--withRenderer', 'cell--rangeTop', 'cell--rangeBottom', 'cell--rangeLeft', 'cell--rangeRight', 'cell--pinnedLeft', 'cell--pinnedRight', 'cell--selectionMode', 'cell', 'cellContent', 'cellCheckbox', 'cellEmpty', 'cellSkeleton', 'checkboxInput', 'columnHeader--alignCenter', 'columnHeader--alignLeft', 'columnHeader--alignRight', 'columnHeader--dragging', 'columnHeader--moving', 'columnHeader--numeric', 'columnHeader--sortable', 'columnHeader--sorted', 'columnHeader--filtered', 'columnHeader', 'columnHeaderCheckbox', 'columnHeaderDraggableContainer', 'columnHeaderDropZone', 'columnHeaderTitle', 'columnHeaderTitleContainer', 'columnHeaderTitleContainerContent', 'columnGroupHeader', 'columnHeader--filledGroup', 'columnHeader--emptyGroup', 'columnHeader--showColumnBorder', 'columnHeaders', 'columnHeadersInner', 'columnHeadersInner--scrollable', 'columnSeparator--resizable', 'columnSeparator--resizing', 'columnSeparator--sideLeft', 'columnSeparator--sideRight', 'columnSeparator', 'columnsManagement', 'columnsManagementRow', 'columnsManagementHeader', 'columnsManagementFooter', 'container--top', 'container--bottom', 'detailPanel', 'detailPanels', 'detailPanelToggleCell', 'detailPanelToggleCell--expanded', 'footerCell', 'panel', 'panelHeader', 'panelWrapper', 'panelContent', 'panelFooter', 'paper', 'editBooleanCell', 'editInputCell', 'filler', 'filler--pinnedLeft', 'filler--pinnedRight', 'filterForm', 'filterFormDeleteIcon', 'filterFormLogicOperatorInput', 'filterFormColumnInput', 'filterFormOperatorInput', 'filterFormValueInput', 'filterIcon', 'footerContainer', 'headerFilterRow', 'iconButtonContainer', 'iconSeparator', 'main', 'main--hasPinnedRight', 'menu', 'menuIcon', 'menuIconButton', 'menuOpen', 'menuList', 'overlay', 'overlayWrapper', 'overlayWrapperInner', 'root', 'root--densityStandard', 'root--densityComfortable', 'root--densityCompact', 'root--disableUserSelection', 'row', 'row--editable', 'row--editing', 'row--firstVisible', 'row--lastVisible', 'row--dragging', 'row--dynamicHeight', 'row--detailPanelExpanded', 'rowReorderCellPlaceholder', 'rowCount', 'rowReorderCellContainer', 'rowReorderCell', 'rowReorderCell--draggable', 'scrollArea--left', 'scrollArea--right', 'scrollArea', 'scrollbar', 'scrollbar--vertical', 'scrollbar--horizontal', 'selectedRowCount', 'sortIcon', 'toolbarContainer', 'toolbarFilterList', 'virtualScroller', 'virtualScrollerContent', 'virtualScrollerContent--overflowed', 'virtualScrollerRenderZone', 'pinnedColumns', 'pinnedColumnHeaders', 'pinnedColumnHeaders--left', 'pinnedColumnHeaders--right', 'withVerticalBorder', 'withBorderColor', 'cell--withRightBorder', 'cell--withLeftBorder', 'columnHeader--withRightBorder', 'treeDataGroupingCell', 'treeDataGroupingCellToggle', 'groupingCriteriaCell', 'groupingCriteriaCellToggle', 'pinnedRows', 'pinnedRows--top', 'pinnedRows--bottom', 'pinnedRowsRenderZone']);
|
|
@@ -27,12 +27,10 @@ export const GRID_DEFAULT_LOCALE_TEXT = {
|
|
|
27
27
|
toolbarExportCSV: 'Download as CSV',
|
|
28
28
|
toolbarExportPrint: 'Print',
|
|
29
29
|
toolbarExportExcel: 'Download as Excel',
|
|
30
|
-
// Columns
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
columnsPanelShowAllButton: 'Show all',
|
|
35
|
-
columnsPanelHideAllButton: 'Hide all',
|
|
30
|
+
// Columns management text
|
|
31
|
+
columnsManagementSearchTitle: 'Search',
|
|
32
|
+
columnsManagementNoColumns: 'No columns',
|
|
33
|
+
columnsManagementShowHideAllText: 'Show/Hide All',
|
|
36
34
|
// Filter panel text
|
|
37
35
|
filterPanelAddFilter: 'Add filter',
|
|
38
36
|
filterPanelRemoveAll: 'Remove all',
|
|
@@ -98,6 +98,9 @@ export function useGridApiInitialization(inputApiRef, props) {
|
|
|
98
98
|
subscribeEvent,
|
|
99
99
|
publishEvent
|
|
100
100
|
}, 'public');
|
|
101
|
+
if (inputApiRef && !inputApiRef.current?.state) {
|
|
102
|
+
inputApiRef.current = publicApiRef.current;
|
|
103
|
+
}
|
|
101
104
|
React.useImperativeHandle(inputApiRef, () => publicApiRef.current, [publicApiRef]);
|
|
102
105
|
React.useEffect(() => {
|
|
103
106
|
const api = privateApiRef.current;
|
|
@@ -59,7 +59,9 @@ function calculateCellColSpan(params) {
|
|
|
59
59
|
} = params;
|
|
60
60
|
const columnsLength = columns.length;
|
|
61
61
|
const column = columns[columnIndex];
|
|
62
|
-
const
|
|
62
|
+
const row = apiRef.current.getRow(rowId);
|
|
63
|
+
const value = apiRef.current.getRowValue(row, column);
|
|
64
|
+
const colSpan = typeof column.colSpan === 'function' ? column.colSpan(value, row, column, apiRef) : column.colSpan;
|
|
63
65
|
if (!colSpan || colSpan === 1) {
|
|
64
66
|
setCellColSpanInfo(lookup, rowId, columnIndex, {
|
|
65
67
|
spannedByColSpan: false,
|
|
@@ -334,7 +334,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
334
334
|
const row = apiRef.current.getRow(id);
|
|
335
335
|
let parsedValue = value;
|
|
336
336
|
if (column.valueParser && !skipValueParser) {
|
|
337
|
-
parsedValue = column.valueParser(value,
|
|
337
|
+
parsedValue = column.valueParser(value, row, column, apiRef);
|
|
338
338
|
}
|
|
339
339
|
let editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
340
340
|
let newProps = _extends({}, editingState[id][field], {
|
|
@@ -382,10 +382,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
382
382
|
const {
|
|
383
383
|
value
|
|
384
384
|
} = editingState[id][field];
|
|
385
|
-
return column.valueSetter ? column.valueSetter({
|
|
386
|
-
value,
|
|
387
|
-
row
|
|
388
|
-
}) : _extends({}, row, {
|
|
385
|
+
return column.valueSetter ? column.valueSetter(value, row, column, apiRef) : _extends({}, row, {
|
|
389
386
|
[field]: value
|
|
390
387
|
});
|
|
391
388
|
}, [apiRef]);
|
|
@@ -409,7 +409,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
409
409
|
const row = apiRef.current.getRow(id);
|
|
410
410
|
let parsedValue = value;
|
|
411
411
|
if (column.valueParser && !skipValueParser) {
|
|
412
|
-
parsedValue = column.valueParser(value,
|
|
412
|
+
parsedValue = column.valueParser(value, row, column, apiRef);
|
|
413
413
|
}
|
|
414
414
|
let editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
415
415
|
let newProps = _extends({}, editingState[id][field], {
|
|
@@ -509,10 +509,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
509
509
|
Object.entries(editingState[id]).forEach(([field, fieldProps]) => {
|
|
510
510
|
const column = apiRef.current.getColumn(field);
|
|
511
511
|
if (column.valueSetter) {
|
|
512
|
-
rowUpdate = column.valueSetter(
|
|
513
|
-
value: fieldProps.value,
|
|
514
|
-
row: rowUpdate
|
|
515
|
-
});
|
|
512
|
+
rowUpdate = column.valueSetter(fieldProps.value, rowUpdate, column, apiRef);
|
|
516
513
|
} else {
|
|
517
514
|
rowUpdate[field] = fieldProps.value;
|
|
518
515
|
}
|
|
@@ -88,7 +88,7 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
|
|
|
88
88
|
let parsedValue;
|
|
89
89
|
if (column.valueParser) {
|
|
90
90
|
const parser = column.valueParser;
|
|
91
|
-
parsedValue = Array.isArray(filterItem.value) ? filterItem.value?.map(x => parser(x)) : parser(filterItem.value);
|
|
91
|
+
parsedValue = Array.isArray(filterItem.value) ? filterItem.value?.map(x => parser(x, undefined, column, apiRef)) : parser(filterItem.value, undefined, column, apiRef);
|
|
92
92
|
} else {
|
|
93
93
|
parsedValue = filterItem.value;
|
|
94
94
|
}
|