@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.
Files changed (246) hide show
  1. package/CHANGELOG.md +386 -38
  2. package/DataGrid/useDataGridComponent.js +1 -1
  3. package/README.md +2 -2
  4. package/colDef/gridBooleanColDef.js +3 -6
  5. package/colDef/gridCheckboxSelectionColDef.js +4 -3
  6. package/colDef/gridDateColDef.d.ts +3 -4
  7. package/colDef/gridDateColDef.js +10 -16
  8. package/colDef/gridNumericColDef.js +1 -3
  9. package/colDef/gridSingleSelectColDef.js +7 -12
  10. package/components/GridRow.js +1 -100
  11. package/components/cell/GridEditInputCell.js +1 -1
  12. package/components/columnsManagement/GridColumnsManagement.d.ts +43 -0
  13. package/components/columnsManagement/GridColumnsManagement.js +265 -0
  14. package/components/columnsManagement/index.d.ts +1 -0
  15. package/components/columnsManagement/index.js +1 -0
  16. package/components/columnsManagement/utils.d.ts +4 -0
  17. package/components/columnsManagement/utils.js +16 -0
  18. package/components/index.d.ts +1 -0
  19. package/components/index.js +1 -0
  20. package/components/panel/GridColumnsPanel.d.ts +0 -28
  21. package/components/panel/GridColumnsPanel.js +5 -213
  22. package/constants/defaultGridSlotsComponents.js +2 -1
  23. package/constants/gridClasses.d.ts +12 -4
  24. package/constants/gridClasses.js +1 -1
  25. package/constants/localeTextConstants.js +4 -6
  26. package/hooks/core/useGridApiInitialization.js +4 -0
  27. package/hooks/features/columns/useGridColumnSpanning.js +3 -1
  28. package/hooks/features/editing/useGridCellEditing.js +2 -5
  29. package/hooks/features/editing/useGridRowEditing.js +2 -5
  30. package/hooks/features/filter/gridFilterUtils.js +1 -1
  31. package/hooks/features/rows/gridRowsUtils.js +4 -1
  32. package/hooks/features/rows/useGridParamsApi.d.ts +1 -2
  33. package/hooks/features/rows/useGridParamsApi.js +14 -49
  34. package/index.js +1 -1
  35. package/legacy/DataGrid/useDataGridComponent.js +1 -1
  36. package/legacy/colDef/gridBooleanColDef.js +3 -5
  37. package/legacy/colDef/gridCheckboxSelectionColDef.js +4 -3
  38. package/legacy/colDef/gridDateColDef.js +10 -14
  39. package/legacy/colDef/gridNumericColDef.js +1 -2
  40. package/legacy/colDef/gridSingleSelectColDef.js +7 -10
  41. package/legacy/components/GridRow.js +1 -100
  42. package/legacy/components/cell/GridEditInputCell.js +1 -1
  43. package/legacy/components/columnsManagement/GridColumnsManagement.js +307 -0
  44. package/legacy/components/columnsManagement/index.js +1 -0
  45. package/legacy/components/columnsManagement/utils.js +22 -0
  46. package/legacy/components/index.js +1 -0
  47. package/legacy/components/panel/GridColumnsPanel.js +5 -233
  48. package/legacy/constants/defaultGridSlotsComponents.js +2 -1
  49. package/legacy/constants/gridClasses.js +1 -1
  50. package/legacy/constants/localeTextConstants.js +4 -6
  51. package/legacy/hooks/core/useGridApiInitialization.js +4 -0
  52. package/legacy/hooks/features/columns/useGridColumnSpanning.js +3 -1
  53. package/legacy/hooks/features/editing/useGridCellEditing.js +2 -5
  54. package/legacy/hooks/features/editing/useGridRowEditing.js +2 -5
  55. package/legacy/hooks/features/filter/gridFilterUtils.js +2 -2
  56. package/legacy/hooks/features/rows/gridRowsUtils.js +4 -1
  57. package/legacy/hooks/features/rows/useGridParamsApi.js +14 -47
  58. package/legacy/index.js +1 -1
  59. package/legacy/locales/arSD.js +5 -6
  60. package/legacy/locales/beBY.js +5 -6
  61. package/legacy/locales/bgBG.js +5 -6
  62. package/legacy/locales/csCZ.js +5 -6
  63. package/legacy/locales/daDK.js +5 -6
  64. package/legacy/locales/deDE.js +5 -6
  65. package/legacy/locales/elGR.js +5 -6
  66. package/legacy/locales/esES.js +5 -6
  67. package/legacy/locales/faIR.js +5 -6
  68. package/legacy/locales/fiFI.js +5 -6
  69. package/legacy/locales/frFR.js +5 -6
  70. package/legacy/locales/heIL.js +12 -14
  71. package/legacy/locales/hrHR.js +5 -6
  72. package/legacy/locales/huHU.js +5 -6
  73. package/legacy/locales/itIT.js +5 -6
  74. package/legacy/locales/jaJP.js +5 -6
  75. package/legacy/locales/koKR.js +5 -6
  76. package/legacy/locales/nbNO.js +5 -6
  77. package/legacy/locales/nlNL.js +5 -6
  78. package/legacy/locales/plPL.js +5 -6
  79. package/legacy/locales/ptBR.js +5 -6
  80. package/legacy/locales/ptPT.js +5 -6
  81. package/legacy/locales/roRO.js +5 -6
  82. package/legacy/locales/ruRU.js +5 -6
  83. package/legacy/locales/skSK.js +5 -6
  84. package/legacy/locales/svSE.js +5 -6
  85. package/legacy/locales/trTR.js +5 -6
  86. package/legacy/locales/ukUA.js +5 -6
  87. package/legacy/locales/urPK.js +5 -6
  88. package/legacy/locales/viVN.js +5 -6
  89. package/legacy/locales/zhCN.js +5 -6
  90. package/legacy/locales/zhHK.js +5 -6
  91. package/legacy/locales/zhTW.js +5 -6
  92. package/locales/arSD.js +5 -6
  93. package/locales/beBY.js +5 -6
  94. package/locales/bgBG.js +5 -6
  95. package/locales/csCZ.js +5 -6
  96. package/locales/daDK.js +5 -6
  97. package/locales/deDE.js +5 -6
  98. package/locales/elGR.js +5 -6
  99. package/locales/esES.js +5 -6
  100. package/locales/faIR.js +5 -6
  101. package/locales/fiFI.js +5 -6
  102. package/locales/frFR.js +5 -6
  103. package/locales/heIL.js +12 -14
  104. package/locales/hrHR.js +5 -6
  105. package/locales/huHU.js +5 -6
  106. package/locales/itIT.js +5 -6
  107. package/locales/jaJP.js +5 -6
  108. package/locales/koKR.js +5 -6
  109. package/locales/nbNO.js +5 -6
  110. package/locales/nlNL.js +5 -6
  111. package/locales/plPL.js +5 -6
  112. package/locales/ptBR.js +5 -6
  113. package/locales/ptPT.js +5 -6
  114. package/locales/roRO.js +5 -6
  115. package/locales/ruRU.js +5 -6
  116. package/locales/skSK.js +5 -6
  117. package/locales/svSE.js +5 -6
  118. package/locales/trTR.js +5 -6
  119. package/locales/ukUA.js +5 -6
  120. package/locales/urPK.js +5 -6
  121. package/locales/viVN.js +5 -6
  122. package/locales/zhCN.js +5 -6
  123. package/locales/zhHK.js +5 -6
  124. package/locales/zhTW.js +5 -6
  125. package/models/api/gridLocaleTextApi.d.ts +3 -5
  126. package/models/colDef/gridColDef.d.ts +11 -17
  127. package/models/colDef/gridColType.d.ts +11 -2
  128. package/models/colDef/index.d.ts +1 -1
  129. package/models/gridSlotsComponent.d.ts +5 -0
  130. package/models/gridSlotsComponentsProps.d.ts +4 -0
  131. package/models/params/gridCellParams.d.ts +0 -26
  132. package/modern/DataGrid/useDataGridComponent.js +1 -1
  133. package/modern/colDef/gridBooleanColDef.js +3 -6
  134. package/modern/colDef/gridCheckboxSelectionColDef.js +4 -3
  135. package/modern/colDef/gridDateColDef.js +10 -16
  136. package/modern/colDef/gridNumericColDef.js +1 -3
  137. package/modern/colDef/gridSingleSelectColDef.js +7 -12
  138. package/modern/components/GridRow.js +1 -100
  139. package/modern/components/cell/GridEditInputCell.js +1 -1
  140. package/modern/components/columnsManagement/GridColumnsManagement.js +261 -0
  141. package/modern/components/columnsManagement/index.js +1 -0
  142. package/modern/components/columnsManagement/utils.js +16 -0
  143. package/modern/components/index.js +1 -0
  144. package/modern/components/panel/GridColumnsPanel.js +4 -209
  145. package/modern/constants/defaultGridSlotsComponents.js +2 -1
  146. package/modern/constants/gridClasses.js +1 -1
  147. package/modern/constants/localeTextConstants.js +4 -6
  148. package/modern/hooks/core/useGridApiInitialization.js +3 -0
  149. package/modern/hooks/features/columns/useGridColumnSpanning.js +3 -1
  150. package/modern/hooks/features/editing/useGridCellEditing.js +2 -5
  151. package/modern/hooks/features/editing/useGridRowEditing.js +2 -5
  152. package/modern/hooks/features/filter/gridFilterUtils.js +1 -1
  153. package/modern/hooks/features/rows/gridRowsUtils.js +4 -1
  154. package/modern/hooks/features/rows/useGridParamsApi.js +14 -47
  155. package/modern/index.js +1 -1
  156. package/modern/locales/arSD.js +5 -6
  157. package/modern/locales/beBY.js +5 -6
  158. package/modern/locales/bgBG.js +5 -6
  159. package/modern/locales/csCZ.js +5 -6
  160. package/modern/locales/daDK.js +5 -6
  161. package/modern/locales/deDE.js +5 -6
  162. package/modern/locales/elGR.js +5 -6
  163. package/modern/locales/esES.js +5 -6
  164. package/modern/locales/faIR.js +5 -6
  165. package/modern/locales/fiFI.js +5 -6
  166. package/modern/locales/frFR.js +5 -6
  167. package/modern/locales/heIL.js +12 -14
  168. package/modern/locales/hrHR.js +5 -6
  169. package/modern/locales/huHU.js +5 -6
  170. package/modern/locales/itIT.js +5 -6
  171. package/modern/locales/jaJP.js +5 -6
  172. package/modern/locales/koKR.js +5 -6
  173. package/modern/locales/nbNO.js +5 -6
  174. package/modern/locales/nlNL.js +5 -6
  175. package/modern/locales/plPL.js +5 -6
  176. package/modern/locales/ptBR.js +5 -6
  177. package/modern/locales/ptPT.js +5 -6
  178. package/modern/locales/roRO.js +5 -6
  179. package/modern/locales/ruRU.js +5 -6
  180. package/modern/locales/skSK.js +5 -6
  181. package/modern/locales/svSE.js +5 -6
  182. package/modern/locales/trTR.js +5 -6
  183. package/modern/locales/ukUA.js +5 -6
  184. package/modern/locales/urPK.js +5 -6
  185. package/modern/locales/viVN.js +5 -6
  186. package/modern/locales/zhCN.js +5 -6
  187. package/modern/locales/zhHK.js +5 -6
  188. package/modern/locales/zhTW.js +5 -6
  189. package/node/DataGrid/useDataGridComponent.js +1 -1
  190. package/node/colDef/gridBooleanColDef.js +3 -6
  191. package/node/colDef/gridCheckboxSelectionColDef.js +4 -3
  192. package/node/colDef/gridDateColDef.js +13 -19
  193. package/node/colDef/gridNumericColDef.js +1 -3
  194. package/node/colDef/gridSingleSelectColDef.js +7 -12
  195. package/node/components/GridRow.js +1 -100
  196. package/node/components/cell/GridEditInputCell.js +1 -1
  197. package/node/components/columnsManagement/GridColumnsManagement.js +269 -0
  198. package/node/components/columnsManagement/index.js +16 -0
  199. package/node/components/columnsManagement/utils.js +24 -0
  200. package/node/components/index.js +11 -0
  201. package/node/components/panel/GridColumnsPanel.js +4 -208
  202. package/node/constants/defaultGridSlotsComponents.js +1 -0
  203. package/node/constants/gridClasses.js +1 -1
  204. package/node/constants/localeTextConstants.js +4 -6
  205. package/node/hooks/core/useGridApiInitialization.js +3 -0
  206. package/node/hooks/features/columns/useGridColumnSpanning.js +3 -1
  207. package/node/hooks/features/editing/useGridCellEditing.js +2 -5
  208. package/node/hooks/features/editing/useGridRowEditing.js +2 -5
  209. package/node/hooks/features/filter/gridFilterUtils.js +1 -1
  210. package/node/hooks/features/rows/gridRowsUtils.js +4 -1
  211. package/node/hooks/features/rows/useGridParamsApi.js +14 -47
  212. package/node/index.js +1 -1
  213. package/node/locales/arSD.js +5 -6
  214. package/node/locales/beBY.js +5 -6
  215. package/node/locales/bgBG.js +5 -6
  216. package/node/locales/csCZ.js +5 -6
  217. package/node/locales/daDK.js +5 -6
  218. package/node/locales/deDE.js +5 -6
  219. package/node/locales/elGR.js +5 -6
  220. package/node/locales/esES.js +5 -6
  221. package/node/locales/faIR.js +5 -6
  222. package/node/locales/fiFI.js +5 -6
  223. package/node/locales/frFR.js +5 -6
  224. package/node/locales/heIL.js +12 -14
  225. package/node/locales/hrHR.js +5 -6
  226. package/node/locales/huHU.js +5 -6
  227. package/node/locales/itIT.js +5 -6
  228. package/node/locales/jaJP.js +5 -6
  229. package/node/locales/koKR.js +5 -6
  230. package/node/locales/nbNO.js +5 -6
  231. package/node/locales/nlNL.js +5 -6
  232. package/node/locales/plPL.js +5 -6
  233. package/node/locales/ptBR.js +5 -6
  234. package/node/locales/ptPT.js +5 -6
  235. package/node/locales/roRO.js +5 -6
  236. package/node/locales/ruRU.js +5 -6
  237. package/node/locales/skSK.js +5 -6
  238. package/node/locales/svSE.js +5 -6
  239. package/node/locales/trTR.js +5 -6
  240. package/node/locales/ukUA.js +5 -6
  241. package/node/locales/urPK.js +5 -6
  242. package/node/locales/viVN.js +5 -6
  243. package/node/locales/zhCN.js +5 -6
  244. package/node/locales/zhHK.js +5 -6
  245. package/node/locales/zhTW.js +5 -6
  246. package/package.json +4 -4
@@ -4,12 +4,9 @@ import { renderBooleanCell } from '../components/cell/GridBooleanCell';
4
4
  import { renderEditBooleanCell } from '../components/cell/GridEditBooleanCell';
5
5
  import { gridNumberComparator } from '../hooks/features/sorting/gridSortingUtils';
6
6
  import { getGridBooleanOperators } from './gridBooleanOperators';
7
- function gridBooleanFormatter({
8
- value,
9
- api
10
- }) {
11
- return value ? api.getLocaleText('booleanCellTrueLabel') : api.getLocaleText('booleanCellFalseLabel');
12
- }
7
+ const gridBooleanFormatter = (value, row, column, apiRef) => {
8
+ return value ? apiRef.current.getLocaleText('booleanCellTrueLabel') : apiRef.current.getLocaleText('booleanCellFalseLabel');
9
+ };
13
10
  const stringToBoolean = value => {
14
11
  switch (value.toLowerCase().trim()) {
15
12
  case 'true':
@@ -19,9 +19,10 @@ export const GRID_CHECKBOX_SELECTION_COL_DEF = _extends({}, GRID_BOOLEAN_COL_DEF
19
19
  disableReorder: true,
20
20
  disableExport: true,
21
21
  getApplyQuickFilterFn: undefined,
22
- valueGetter: params => {
23
- const selectionLookup = selectedIdsLookupSelector(params.api.state, params.api.instanceId);
24
- return selectionLookup[params.id] !== undefined;
22
+ valueGetter: (value, row, column, apiRef) => {
23
+ const selectionLookup = selectedIdsLookupSelector(apiRef);
24
+ const rowId = apiRef.current.getRowId(row);
25
+ return selectionLookup[rowId] !== undefined;
25
26
  },
26
27
  renderHeader: params => /*#__PURE__*/_jsx(GridHeaderCheckbox, _extends({}, params)),
27
28
  renderCell: params => /*#__PURE__*/_jsx(GridCellCheckboxRenderer, _extends({}, params))
@@ -1,6 +1,5 @@
1
- import { GridColTypeDef } from '../models/colDef/gridColDef';
2
- import { GridValueFormatterParams } from '../models/params/gridCellParams';
3
- export declare function gridDateFormatter({ value, field, id }: GridValueFormatterParams<Date>): string;
4
- export declare function gridDateTimeFormatter({ value, field, id }: GridValueFormatterParams<Date>): string;
1
+ import { GridColTypeDef, GridValueFormatter } from '../models/colDef/gridColDef';
2
+ export declare const gridDateFormatter: GridValueFormatter;
3
+ export declare const gridDateTimeFormatter: GridValueFormatter;
5
4
  export declare const GRID_DATE_COL_DEF: GridColTypeDef<Date, string>;
6
5
  export declare const GRID_DATETIME_COL_DEF: GridColTypeDef<Date, string>;
@@ -13,38 +13,32 @@ function throwIfNotDateObject({
13
13
  throw new Error([`MUI X: \`${columnType}\` column type only accepts \`Date\` objects as values.`, 'Use `valueGetter` to transform the value into a `Date` object.', `Row ID: ${rowId}, field: "${field}".`].join('\n'));
14
14
  }
15
15
  }
16
- export function gridDateFormatter({
17
- value,
18
- field,
19
- id
20
- }) {
16
+ export const gridDateFormatter = (value, row, column, apiRef) => {
21
17
  if (!value) {
22
18
  return '';
23
19
  }
20
+ const rowId = apiRef.current.getRowId(row);
24
21
  throwIfNotDateObject({
25
22
  value,
26
23
  columnType: 'date',
27
- rowId: id,
28
- field
24
+ rowId,
25
+ field: column.field
29
26
  });
30
27
  return value.toLocaleDateString();
31
- }
32
- export function gridDateTimeFormatter({
33
- value,
34
- field,
35
- id
36
- }) {
28
+ };
29
+ export const gridDateTimeFormatter = (value, row, column, apiRef) => {
37
30
  if (!value) {
38
31
  return '';
39
32
  }
33
+ const rowId = apiRef.current.getRowId(row);
40
34
  throwIfNotDateObject({
41
35
  value,
42
36
  columnType: 'dateTime',
43
- rowId: id,
44
- field
37
+ rowId,
38
+ field: column.field
45
39
  });
46
40
  return value.toLocaleString();
47
- }
41
+ };
48
42
  export const GRID_DATE_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
49
43
  type: 'date',
50
44
  sortComparator: gridDateComparator,
@@ -9,9 +9,7 @@ export const GRID_NUMERIC_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
9
9
  headerAlign: 'right',
10
10
  sortComparator: gridNumberComparator,
11
11
  valueParser: value => value === '' ? null : Number(value),
12
- valueFormatter: ({
13
- value
14
- }) => isNumber(value) ? value.toLocaleString() : value || '',
12
+ valueFormatter: value => isNumber(value) ? value.toLocaleString() : value || '',
15
13
  filterOperators: getGridNumericOperators(),
16
14
  getApplyQuickFilterFn: getGridNumericQuickFilterFn
17
15
  });
@@ -17,20 +17,15 @@ export const GRID_SINGLE_SELECT_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
17
17
  type: 'singleSelect',
18
18
  getOptionLabel: defaultGetOptionLabel,
19
19
  getOptionValue: defaultGetOptionValue,
20
- valueFormatter(params) {
21
- const {
22
- id,
23
- field,
24
- value,
25
- api
26
- } = params;
27
- const colDef = params.api.getColumn(field);
20
+ valueFormatter(value, row, colDef, apiRef) {
21
+ // const { id, field, value, api } = params;
22
+ const rowId = apiRef.current.getRowId(row);
28
23
  if (!isSingleSelectColDef(colDef)) {
29
24
  return '';
30
25
  }
31
26
  const valueOptions = getValueOptions(colDef, {
32
- id,
33
- row: id ? api.getRow(id) : null
27
+ id: rowId,
28
+ row
34
29
  });
35
30
  if (value == null) {
36
31
  return '';
@@ -47,8 +42,8 @@ export const GRID_SINGLE_SELECT_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
47
42
  renderEditCell: renderEditSingleSelectCell,
48
43
  filterOperators: getGridSingleSelectOperators(),
49
44
  // @ts-ignore
50
- pastedValueParser: (value, params) => {
51
- const colDef = params.colDef;
45
+ pastedValueParser: (value, row, column) => {
46
+ const colDef = column;
52
47
  const valueOptions = getValueOptions(colDef) || [];
53
48
  const getOptionValue = colDef.getOptionValue;
54
49
  const valueOption = valueOptions.find(option => {
@@ -436,106 +436,7 @@ process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
436
436
  onDoubleClick: PropTypes.func,
437
437
  onMouseEnter: PropTypes.func,
438
438
  onMouseLeave: PropTypes.func,
439
- pinnedColumns: PropTypes.shape({
440
- left: PropTypes.arrayOf(PropTypes.shape({
441
- align: PropTypes.oneOf(['center', 'left', 'right']),
442
- cellClassName: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
443
- colSpan: PropTypes.oneOfType([PropTypes.func, PropTypes.number]),
444
- computedWidth: PropTypes.number.isRequired,
445
- description: PropTypes.string,
446
- disableColumnMenu: PropTypes.bool,
447
- disableExport: PropTypes.bool,
448
- disableReorder: PropTypes.bool,
449
- editable: PropTypes.bool,
450
- field: PropTypes.string.isRequired,
451
- filterable: PropTypes.bool,
452
- filterOperators: PropTypes.arrayOf(PropTypes.shape({
453
- getApplyFilterFn: PropTypes.func.isRequired,
454
- getValueAsString: PropTypes.func,
455
- headerLabel: PropTypes.string,
456
- InputComponent: PropTypes.elementType,
457
- InputComponentProps: PropTypes.object,
458
- label: PropTypes.string,
459
- requiresFilterValue: PropTypes.bool,
460
- value: PropTypes.string.isRequired
461
- })),
462
- flex: PropTypes.number,
463
- getApplyQuickFilterFn: PropTypes.func,
464
- groupable: PropTypes.bool,
465
- hasBeenResized: PropTypes.bool,
466
- headerAlign: PropTypes.oneOf(['center', 'left', 'right']),
467
- headerClassName: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
468
- headerName: PropTypes.string,
469
- hideable: PropTypes.bool,
470
- hideSortIcons: PropTypes.bool,
471
- maxWidth: PropTypes.number,
472
- minWidth: PropTypes.number,
473
- pinnable: PropTypes.bool,
474
- preProcessEditCellProps: PropTypes.func,
475
- renderCell: PropTypes.func,
476
- renderEditCell: PropTypes.func,
477
- renderHeader: PropTypes.func,
478
- resizable: PropTypes.bool,
479
- sortable: PropTypes.bool,
480
- sortComparator: PropTypes.func,
481
- sortingOrder: PropTypes.arrayOf(PropTypes.oneOf(['asc', 'desc'])),
482
- type: PropTypes.oneOf(['actions', 'boolean', 'custom', 'date', 'dateTime', 'number', 'singleSelect', 'string']),
483
- valueFormatter: PropTypes.func,
484
- valueGetter: PropTypes.func,
485
- valueParser: PropTypes.func,
486
- valueSetter: PropTypes.func,
487
- width: PropTypes.number
488
- })).isRequired,
489
- right: PropTypes.arrayOf(PropTypes.shape({
490
- align: PropTypes.oneOf(['center', 'left', 'right']),
491
- cellClassName: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
492
- colSpan: PropTypes.oneOfType([PropTypes.func, PropTypes.number]),
493
- computedWidth: PropTypes.number.isRequired,
494
- description: PropTypes.string,
495
- disableColumnMenu: PropTypes.bool,
496
- disableExport: PropTypes.bool,
497
- disableReorder: PropTypes.bool,
498
- editable: PropTypes.bool,
499
- field: PropTypes.string.isRequired,
500
- filterable: PropTypes.bool,
501
- filterOperators: PropTypes.arrayOf(PropTypes.shape({
502
- getApplyFilterFn: PropTypes.func.isRequired,
503
- getValueAsString: PropTypes.func,
504
- headerLabel: PropTypes.string,
505
- InputComponent: PropTypes.elementType,
506
- InputComponentProps: PropTypes.object,
507
- label: PropTypes.string,
508
- requiresFilterValue: PropTypes.bool,
509
- value: PropTypes.string.isRequired
510
- })),
511
- flex: PropTypes.number,
512
- getApplyQuickFilterFn: PropTypes.func,
513
- groupable: PropTypes.bool,
514
- hasBeenResized: PropTypes.bool,
515
- headerAlign: PropTypes.oneOf(['center', 'left', 'right']),
516
- headerClassName: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
517
- headerName: PropTypes.string,
518
- hideable: PropTypes.bool,
519
- hideSortIcons: PropTypes.bool,
520
- maxWidth: PropTypes.number,
521
- minWidth: PropTypes.number,
522
- pinnable: PropTypes.bool,
523
- preProcessEditCellProps: PropTypes.func,
524
- renderCell: PropTypes.func,
525
- renderEditCell: PropTypes.func,
526
- renderHeader: PropTypes.func,
527
- resizable: PropTypes.bool,
528
- sortable: PropTypes.bool,
529
- sortComparator: PropTypes.func,
530
- sortingOrder: PropTypes.arrayOf(PropTypes.oneOf(['asc', 'desc'])),
531
- type: PropTypes.oneOf(['actions', 'boolean', 'custom', 'date', 'dateTime', 'number', 'singleSelect', 'string']),
532
- valueFormatter: PropTypes.func,
533
- valueGetter: PropTypes.func,
534
- valueParser: PropTypes.func,
535
- valueSetter: PropTypes.func,
536
- width: PropTypes.number
537
- })).isRequired
538
- }).isRequired,
439
+ pinnedColumns: PropTypes.object.isRequired,
539
440
  renderedColumns: PropTypes.arrayOf(PropTypes.object).isRequired,
540
441
  row: PropTypes.object,
541
442
  rowHeight: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]).isRequired,
@@ -57,7 +57,7 @@ const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
57
57
  const column = apiRef.current.getColumn(field);
58
58
  let parsedValue = newValue;
59
59
  if (column.valueParser) {
60
- parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
60
+ parsedValue = column.valueParser(newValue, apiRef.current.getRow(id), column, apiRef);
61
61
  }
62
62
  setValueState(parsedValue);
63
63
  apiRef.current.setEditCellValue({
@@ -0,0 +1,43 @@
1
+ import * as React from 'react';
2
+ import type { GridColDef } from '../../models/colDef/gridColDef';
3
+ export interface GridColumnsManagementProps {
4
+ sort?: 'asc' | 'desc';
5
+ searchPredicate?: (column: GridColDef, searchValue: string) => boolean;
6
+ /**
7
+ * If `true`, the column search field will be focused automatically.
8
+ * If `false`, the first column switch input will be focused automatically.
9
+ * This helps to avoid input keyboard panel to popup automatically on touch devices.
10
+ * @default true
11
+ */
12
+ autoFocusSearchField?: boolean;
13
+ /**
14
+ * If `true`, the `Show/Hide all` toggle checkbox will not be displayed.
15
+ * @default false
16
+ */
17
+ disableShowHideToggle?: boolean;
18
+ /**
19
+ * If `true`, the `Reset` button will not be disabled
20
+ * @default false
21
+ */
22
+ disableResetButton?: boolean;
23
+ /**
24
+ * Changes the behavior of the `Show/Hide All` toggle when the search field is used:
25
+ * - `all`: Will toggle all columns.
26
+ * - `filteredOnly`: Will only toggle columns that match the search criteria.
27
+ * @default 'all'
28
+ */
29
+ toggleAllMode?: 'all' | 'filteredOnly';
30
+ /**
31
+ * Returns the list of togglable columns.
32
+ * If used, only those columns will be displayed in the panel
33
+ * which are passed as the return value of the function.
34
+ * @param {GridColDef[]} columns The `ColDef` list of all columns.
35
+ * @returns {GridColDef['field'][]} The list of togglable columns' field names.
36
+ */
37
+ getTogglableColumns?: (columns: GridColDef[]) => GridColDef['field'][];
38
+ }
39
+ declare function GridColumnsManagement(props: GridColumnsManagementProps): React.JSX.Element;
40
+ declare namespace GridColumnsManagement {
41
+ var propTypes: any;
42
+ }
43
+ export { GridColumnsManagement };
@@ -0,0 +1,265 @@
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
+ var _rootProps$slotProps, _rootProps$slotProps3, _rootProps$slotProps4;
32
+ const apiRef = useGridApiContext();
33
+ const searchInputRef = React.useRef(null);
34
+ const columns = useGridSelector(apiRef, gridColumnDefinitionsSelector);
35
+ const initialColumnVisibilityModel = useLazyRef(() => gridColumnVisibilityModelSelector(apiRef)).current;
36
+ const columnVisibilityModel = useGridSelector(apiRef, gridColumnVisibilityModelSelector);
37
+ const rootProps = useGridRootProps();
38
+ const [searchValue, setSearchValue] = React.useState('');
39
+ const classes = useUtilityClasses(rootProps);
40
+ const {
41
+ sort,
42
+ searchPredicate = defaultSearchPredicate,
43
+ autoFocusSearchField = true,
44
+ disableShowHideToggle = false,
45
+ disableResetButton = false,
46
+ toggleAllMode = 'all',
47
+ getTogglableColumns
48
+ } = props;
49
+ const isResetDisabled = React.useMemo(() => checkColumnVisibilityModelsSame(columnVisibilityModel, initialColumnVisibilityModel), [columnVisibilityModel, initialColumnVisibilityModel]);
50
+ const sortedColumns = React.useMemo(() => {
51
+ switch (sort) {
52
+ case 'asc':
53
+ return [...columns].sort((a, b) => collator.compare(a.headerName || a.field, b.headerName || b.field));
54
+ case 'desc':
55
+ return [...columns].sort((a, b) => -collator.compare(a.headerName || a.field, b.headerName || b.field));
56
+ default:
57
+ return columns;
58
+ }
59
+ }, [columns, sort]);
60
+ const toggleColumn = event => {
61
+ const {
62
+ name: field
63
+ } = event.target;
64
+ apiRef.current.setColumnVisibility(field, columnVisibilityModel[field] === false);
65
+ };
66
+ const currentColumns = React.useMemo(() => {
67
+ const togglableColumns = getTogglableColumns ? getTogglableColumns(sortedColumns) : null;
68
+ const togglableSortedColumns = togglableColumns ? sortedColumns.filter(({
69
+ field
70
+ }) => togglableColumns.includes(field)) : sortedColumns;
71
+ if (!searchValue) {
72
+ return togglableSortedColumns;
73
+ }
74
+ return togglableSortedColumns.filter(column => searchPredicate(column, searchValue.toLowerCase()));
75
+ }, [sortedColumns, searchValue, searchPredicate, getTogglableColumns]);
76
+ const toggleAllColumns = React.useCallback(isVisible => {
77
+ const currentModel = gridColumnVisibilityModelSelector(apiRef);
78
+ const newModel = _extends({}, currentModel);
79
+ const togglableColumns = getTogglableColumns ? getTogglableColumns(columns) : null;
80
+ (toggleAllMode === 'filteredOnly' ? currentColumns : columns).forEach(col => {
81
+ if (col.hideable && (togglableColumns == null || togglableColumns.includes(col.field))) {
82
+ if (isVisible) {
83
+ // delete the key from the model instead of setting it to `true`
84
+ delete newModel[col.field];
85
+ } else {
86
+ newModel[col.field] = false;
87
+ }
88
+ }
89
+ });
90
+ return apiRef.current.setColumnVisibilityModel(newModel);
91
+ }, [apiRef, columns, getTogglableColumns, toggleAllMode, currentColumns]);
92
+ const handleSearchValueChange = React.useCallback(event => {
93
+ setSearchValue(event.target.value);
94
+ }, []);
95
+ const hideableColumns = React.useMemo(() => currentColumns.filter(col => col.hideable), [currentColumns]);
96
+ const allHideableColumnsVisible = React.useMemo(() => hideableColumns.every(column => columnVisibilityModel[column.field] == null || columnVisibilityModel[column.field] !== false), [columnVisibilityModel, hideableColumns]);
97
+ const allHideableColumnsHidden = React.useMemo(() => hideableColumns.every(column => columnVisibilityModel[column.field] === false), [columnVisibilityModel, hideableColumns]);
98
+ const firstSwitchRef = React.useRef(null);
99
+ React.useEffect(() => {
100
+ if (autoFocusSearchField) {
101
+ searchInputRef.current.focus();
102
+ } else if (firstSwitchRef.current && typeof firstSwitchRef.current.focus === 'function') {
103
+ firstSwitchRef.current.focus();
104
+ }
105
+ }, [autoFocusSearchField]);
106
+ let firstHideableColumnFound = false;
107
+ const isFirstHideableColumn = column => {
108
+ if (firstHideableColumnFound === false && column.hideable !== false) {
109
+ firstHideableColumnFound = true;
110
+ return true;
111
+ }
112
+ return false;
113
+ };
114
+ return /*#__PURE__*/_jsxs(React.Fragment, {
115
+ children: [/*#__PURE__*/_jsx(GridColumnsManagementHeader, {
116
+ className: classes.header,
117
+ ownerState: rootProps,
118
+ children: /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
119
+ placeholder: apiRef.current.getLocaleText('columnsManagementSearchTitle'),
120
+ inputRef: searchInputRef,
121
+ value: searchValue,
122
+ onChange: handleSearchValueChange,
123
+ variant: "outlined",
124
+ size: "small",
125
+ InputProps: {
126
+ startAdornment: /*#__PURE__*/_jsx(rootProps.slots.baseInputAdornment, {
127
+ position: "start",
128
+ children: /*#__PURE__*/_jsx(rootProps.slots.quickFilterIcon, {})
129
+ }),
130
+ sx: {
131
+ pl: 1.5
132
+ }
133
+ },
134
+ fullWidth: true
135
+ }, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseTextField))
136
+ }), /*#__PURE__*/_jsxs(GridColumnsManagementBody, {
137
+ className: classes.root,
138
+ ownerState: rootProps,
139
+ children: [currentColumns.map(column => {
140
+ var _rootProps$slotProps2;
141
+ return /*#__PURE__*/_jsx(FormControlLabel, {
142
+ className: classes.row,
143
+ control: /*#__PURE__*/_jsx(rootProps.slots.baseCheckbox, _extends({
144
+ disabled: column.hideable === false,
145
+ checked: columnVisibilityModel[column.field] !== false,
146
+ onClick: toggleColumn,
147
+ name: column.field,
148
+ sx: {
149
+ p: 0.5
150
+ },
151
+ inputRef: isFirstHideableColumn(column) ? firstSwitchRef : undefined
152
+ }, (_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseCheckbox)),
153
+ label: column.headerName || column.field
154
+ }, column.field);
155
+ }), currentColumns.length === 0 && /*#__PURE__*/_jsx(GridColumnsManagementEmptyText, {
156
+ ownerState: rootProps,
157
+ children: apiRef.current.getLocaleText('columnsManagementNoColumns')
158
+ })]
159
+ }), !disableShowHideToggle && !disableResetButton && currentColumns.length > 0 ? /*#__PURE__*/_jsxs(GridColumnsManagementFooter, {
160
+ ownerState: rootProps,
161
+ className: classes.footer,
162
+ children: [!disableShowHideToggle ? /*#__PURE__*/_jsx(FormControlLabel, {
163
+ control: /*#__PURE__*/_jsx(rootProps.slots.baseCheckbox, _extends({
164
+ disabled: hideableColumns.length === 0,
165
+ checked: allHideableColumnsVisible,
166
+ indeterminate: !allHideableColumnsVisible && !allHideableColumnsHidden,
167
+ onClick: () => toggleAllColumns(!allHideableColumnsVisible),
168
+ name: apiRef.current.getLocaleText('columnsManagementShowHideAllText'),
169
+ sx: {
170
+ p: 0.5
171
+ }
172
+ }, (_rootProps$slotProps3 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps3.baseCheckbox)),
173
+ label: apiRef.current.getLocaleText('columnsManagementShowHideAllText')
174
+ }) : /*#__PURE__*/_jsx("span", {}), !disableResetButton ? /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
175
+ onClick: () => apiRef.current.setColumnVisibilityModel(initialColumnVisibilityModel),
176
+ disabled: isResetDisabled
177
+ }, (_rootProps$slotProps4 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps4.baseButton, {
178
+ children: "Reset"
179
+ })) : null]
180
+ }) : null]
181
+ });
182
+ }
183
+ process.env.NODE_ENV !== "production" ? GridColumnsManagement.propTypes = {
184
+ // ----------------------------- Warning --------------------------------
185
+ // | These PropTypes are generated from the TypeScript type definitions |
186
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
187
+ // ----------------------------------------------------------------------
188
+ /**
189
+ * If `true`, the column search field will be focused automatically.
190
+ * If `false`, the first column switch input will be focused automatically.
191
+ * This helps to avoid input keyboard panel to popup automatically on touch devices.
192
+ * @default true
193
+ */
194
+ autoFocusSearchField: PropTypes.bool,
195
+ /**
196
+ * If `true`, the `Reset` button will not be disabled
197
+ * @default false
198
+ */
199
+ disableResetButton: PropTypes.bool,
200
+ /**
201
+ * If `true`, the `Show/Hide all` toggle checkbox will not be displayed.
202
+ * @default false
203
+ */
204
+ disableShowHideToggle: PropTypes.bool,
205
+ /**
206
+ * Returns the list of togglable columns.
207
+ * If used, only those columns will be displayed in the panel
208
+ * which are passed as the return value of the function.
209
+ * @param {GridColDef[]} columns The `ColDef` list of all columns.
210
+ * @returns {GridColDef['field'][]} The list of togglable columns' field names.
211
+ */
212
+ getTogglableColumns: PropTypes.func,
213
+ searchPredicate: PropTypes.func,
214
+ sort: PropTypes.oneOf(['asc', 'desc']),
215
+ /**
216
+ * Changes the behavior of the `Show/Hide All` toggle when the search field is used:
217
+ * - `all`: Will toggle all columns.
218
+ * - `filteredOnly`: Will only toggle columns that match the search criteria.
219
+ * @default 'all'
220
+ */
221
+ toggleAllMode: PropTypes.oneOf(['all', 'filteredOnly'])
222
+ } : void 0;
223
+ const GridColumnsManagementBody = styled('div', {
224
+ name: 'MuiDataGrid',
225
+ slot: 'ColumnsManagement',
226
+ overridesResolver: (props, styles) => styles.columnsManagement
227
+ })(({
228
+ theme
229
+ }) => ({
230
+ padding: theme.spacing(0, 3, 1.5),
231
+ display: 'flex',
232
+ flexDirection: 'column',
233
+ overflow: 'auto',
234
+ flex: '1 1',
235
+ maxHeight: 400,
236
+ alignItems: 'flex-start'
237
+ }));
238
+ const GridColumnsManagementHeader = styled('div', {
239
+ name: 'MuiDataGrid',
240
+ slot: 'ColumnsManagementHeader',
241
+ overridesResolver: (props, styles) => styles.columnsManagementHeader
242
+ })(({
243
+ theme
244
+ }) => ({
245
+ padding: theme.spacing(1.5, 3)
246
+ }));
247
+ const GridColumnsManagementFooter = styled('div', {
248
+ name: 'MuiDataGrid',
249
+ slot: 'ColumnsManagementFooter',
250
+ overridesResolver: (props, styles) => styles.columnsManagementFooter
251
+ })(({
252
+ theme
253
+ }) => ({
254
+ padding: theme.spacing(0.5, 1, 0.5, 3),
255
+ display: 'flex',
256
+ justifyContent: 'space-between',
257
+ borderTop: `1px solid ${theme.palette.divider}`
258
+ }));
259
+ const GridColumnsManagementEmptyText = styled('div')(({
260
+ theme
261
+ }) => ({
262
+ padding: theme.spacing(0.5, 0),
263
+ color: theme.palette.grey[500]
264
+ }));
265
+ export { GridColumnsManagement };
@@ -0,0 +1 @@
1
+ export * from './GridColumnsManagement';
@@ -0,0 +1 @@
1
+ export * from './GridColumnsManagement';
@@ -0,0 +1,4 @@
1
+ import { GridColumnVisibilityModel } from '../../hooks/features/columns/gridColumnsInterfaces';
2
+ import { GridColumnsManagementProps } from './GridColumnsManagement';
3
+ export declare const checkColumnVisibilityModelsSame: (a: GridColumnVisibilityModel, b: GridColumnVisibilityModel) => boolean;
4
+ export declare const defaultSearchPredicate: NonNullable<GridColumnsManagementProps['searchPredicate']>;
@@ -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;
@@ -6,6 +6,7 @@ export * from './columnSelection';
6
6
  export * from '../material/icons';
7
7
  export * from './menu';
8
8
  export * from './panel';
9
+ export * from './columnsManagement';
9
10
  export * from './toolbar';
10
11
  export * from './GridApiContext';
11
12
  export * from './GridFooter';
@@ -6,6 +6,7 @@ export * from './columnSelection';
6
6
  export * from '../material/icons';
7
7
  export * from './menu';
8
8
  export * from './panel';
9
+ export * from './columnsManagement';
9
10
  export * from './toolbar';
10
11
  export * from './GridApiContext';
11
12
  export * from './GridFooter';
@@ -1,34 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { GridPanelWrapperProps } from './GridPanelWrapper';
3
- import type { GridColDef } from '../../models/colDef/gridColDef';
4
3
  export interface GridColumnsPanelProps extends GridPanelWrapperProps {
5
- sort?: 'asc' | 'desc';
6
- searchPredicate?: (column: GridColDef, searchValue: string) => boolean;
7
- /**
8
- * If `true`, the column search field will be focused automatically.
9
- * If `false`, the first column switch input will be focused automatically.
10
- * This helps to avoid input keyboard panel to popup automatically on touch devices.
11
- * @default true
12
- */
13
- autoFocusSearchField?: boolean;
14
- /**
15
- * If `true`, the `Hide all` button will not be displayed.
16
- * @default false
17
- */
18
- disableHideAllButton?: boolean;
19
- /**
20
- * If `true`, the `Show all` button will be disabled
21
- * @default false
22
- */
23
- disableShowAllButton?: boolean;
24
- /**
25
- * Returns the list of togglable columns.
26
- * If used, only those columns will be displayed in the panel
27
- * which are passed as the return value of the function.
28
- * @param {GridColDef[]} columns The `ColDef` list of all columns.
29
- * @returns {GridColDef['field'][]} The list of togglable columns' field names.
30
- */
31
- getTogglableColumns?: (columns: GridColDef[]) => GridColDef['field'][];
32
4
  }
33
5
  declare function GridColumnsPanel(props: GridColumnsPanelProps): React.JSX.Element;
34
6
  declare namespace GridColumnsPanel {