@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
@@ -18,18 +18,15 @@ export var GRID_SINGLE_SELECT_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
18
18
  type: 'singleSelect',
19
19
  getOptionLabel: defaultGetOptionLabel,
20
20
  getOptionValue: defaultGetOptionValue,
21
- valueFormatter: function valueFormatter(params) {
22
- var id = params.id,
23
- field = params.field,
24
- value = params.value,
25
- api = params.api;
26
- var colDef = params.api.getColumn(field);
21
+ valueFormatter: function valueFormatter(value, row, colDef, apiRef) {
22
+ // const { id, field, value, api } = params;
23
+ var rowId = apiRef.current.getRowId(row);
27
24
  if (!isSingleSelectColDef(colDef)) {
28
25
  return '';
29
26
  }
30
27
  var valueOptions = getValueOptions(colDef, {
31
- id: id,
32
- row: id ? api.getRow(id) : null
28
+ id: rowId,
29
+ row: row
33
30
  });
34
31
  if (value == null) {
35
32
  return '';
@@ -48,8 +45,8 @@ export var GRID_SINGLE_SELECT_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
48
45
  renderEditCell: renderEditSingleSelectCell,
49
46
  filterOperators: getGridSingleSelectOperators(),
50
47
  // @ts-ignore
51
- pastedValueParser: function pastedValueParser(value, params) {
52
- var colDef = params.colDef;
48
+ pastedValueParser: function pastedValueParser(value, row, column) {
49
+ var colDef = column;
53
50
  var valueOptions = getValueOptions(colDef) || [];
54
51
  var getOptionValue = colDef.getOptionValue;
55
52
  var valueOption = valueOptions.find(function (option) {
@@ -438,106 +438,7 @@ process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
438
438
  onDoubleClick: PropTypes.func,
439
439
  onMouseEnter: PropTypes.func,
440
440
  onMouseLeave: PropTypes.func,
441
- pinnedColumns: PropTypes.shape({
442
- left: PropTypes.arrayOf(PropTypes.shape({
443
- align: PropTypes.oneOf(['center', 'left', 'right']),
444
- cellClassName: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
445
- colSpan: PropTypes.oneOfType([PropTypes.func, PropTypes.number]),
446
- computedWidth: PropTypes.number.isRequired,
447
- description: PropTypes.string,
448
- disableColumnMenu: PropTypes.bool,
449
- disableExport: PropTypes.bool,
450
- disableReorder: PropTypes.bool,
451
- editable: PropTypes.bool,
452
- field: PropTypes.string.isRequired,
453
- filterable: PropTypes.bool,
454
- filterOperators: PropTypes.arrayOf(PropTypes.shape({
455
- getApplyFilterFn: PropTypes.func.isRequired,
456
- getValueAsString: PropTypes.func,
457
- headerLabel: PropTypes.string,
458
- InputComponent: PropTypes.elementType,
459
- InputComponentProps: PropTypes.object,
460
- label: PropTypes.string,
461
- requiresFilterValue: PropTypes.bool,
462
- value: PropTypes.string.isRequired
463
- })),
464
- flex: PropTypes.number,
465
- getApplyQuickFilterFn: PropTypes.func,
466
- groupable: PropTypes.bool,
467
- hasBeenResized: PropTypes.bool,
468
- headerAlign: PropTypes.oneOf(['center', 'left', 'right']),
469
- headerClassName: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
470
- headerName: PropTypes.string,
471
- hideable: PropTypes.bool,
472
- hideSortIcons: PropTypes.bool,
473
- maxWidth: PropTypes.number,
474
- minWidth: PropTypes.number,
475
- pinnable: PropTypes.bool,
476
- preProcessEditCellProps: PropTypes.func,
477
- renderCell: PropTypes.func,
478
- renderEditCell: PropTypes.func,
479
- renderHeader: PropTypes.func,
480
- resizable: PropTypes.bool,
481
- sortable: PropTypes.bool,
482
- sortComparator: PropTypes.func,
483
- sortingOrder: PropTypes.arrayOf(PropTypes.oneOf(['asc', 'desc'])),
484
- type: PropTypes.oneOf(['actions', 'boolean', 'custom', 'date', 'dateTime', 'number', 'singleSelect', 'string']),
485
- valueFormatter: PropTypes.func,
486
- valueGetter: PropTypes.func,
487
- valueParser: PropTypes.func,
488
- valueSetter: PropTypes.func,
489
- width: PropTypes.number
490
- })).isRequired,
491
- right: PropTypes.arrayOf(PropTypes.shape({
492
- align: PropTypes.oneOf(['center', 'left', 'right']),
493
- cellClassName: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
494
- colSpan: PropTypes.oneOfType([PropTypes.func, PropTypes.number]),
495
- computedWidth: PropTypes.number.isRequired,
496
- description: PropTypes.string,
497
- disableColumnMenu: PropTypes.bool,
498
- disableExport: PropTypes.bool,
499
- disableReorder: PropTypes.bool,
500
- editable: PropTypes.bool,
501
- field: PropTypes.string.isRequired,
502
- filterable: PropTypes.bool,
503
- filterOperators: PropTypes.arrayOf(PropTypes.shape({
504
- getApplyFilterFn: PropTypes.func.isRequired,
505
- getValueAsString: PropTypes.func,
506
- headerLabel: PropTypes.string,
507
- InputComponent: PropTypes.elementType,
508
- InputComponentProps: PropTypes.object,
509
- label: PropTypes.string,
510
- requiresFilterValue: PropTypes.bool,
511
- value: PropTypes.string.isRequired
512
- })),
513
- flex: PropTypes.number,
514
- getApplyQuickFilterFn: PropTypes.func,
515
- groupable: PropTypes.bool,
516
- hasBeenResized: PropTypes.bool,
517
- headerAlign: PropTypes.oneOf(['center', 'left', 'right']),
518
- headerClassName: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
519
- headerName: PropTypes.string,
520
- hideable: PropTypes.bool,
521
- hideSortIcons: PropTypes.bool,
522
- maxWidth: PropTypes.number,
523
- minWidth: PropTypes.number,
524
- pinnable: PropTypes.bool,
525
- preProcessEditCellProps: PropTypes.func,
526
- renderCell: PropTypes.func,
527
- renderEditCell: PropTypes.func,
528
- renderHeader: PropTypes.func,
529
- resizable: PropTypes.bool,
530
- sortable: PropTypes.bool,
531
- sortComparator: PropTypes.func,
532
- sortingOrder: PropTypes.arrayOf(PropTypes.oneOf(['asc', 'desc'])),
533
- type: PropTypes.oneOf(['actions', 'boolean', 'custom', 'date', 'dateTime', 'number', 'singleSelect', 'string']),
534
- valueFormatter: PropTypes.func,
535
- valueGetter: PropTypes.func,
536
- valueParser: PropTypes.func,
537
- valueSetter: PropTypes.func,
538
- width: PropTypes.number
539
- })).isRequired
540
- }).isRequired,
441
+ pinnedColumns: PropTypes.object.isRequired,
541
442
  renderedColumns: PropTypes.arrayOf(PropTypes.object).isRequired,
542
443
  row: PropTypes.object,
543
444
  rowHeight: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]).isRequired,
@@ -80,7 +80,7 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
80
80
  column = apiRef.current.getColumn(field);
81
81
  parsedValue = newValue;
82
82
  if (column.valueParser) {
83
- parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
83
+ parsedValue = column.valueParser(newValue, apiRef.current.getRow(id), column, apiRef);
84
84
  }
85
85
  setValueState(parsedValue);
86
86
  apiRef.current.setEditCellValue({
@@ -0,0 +1,307 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ /* eslint-disable @typescript-eslint/no-use-before-define */
5
+ import * as React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import { unstable_composeClasses as composeClasses } from '@mui/utils';
8
+ import FormControlLabel from '@mui/material/FormControlLabel';
9
+ import { styled } from '@mui/material/styles';
10
+ import { gridColumnDefinitionsSelector, gridColumnVisibilityModelSelector } from '../../hooks/features/columns/gridColumnsSelector';
11
+ import { useGridSelector } from '../../hooks/utils/useGridSelector';
12
+ import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
13
+ import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
14
+ import { getDataGridUtilityClass } from '../../constants/gridClasses';
15
+ import { useLazyRef } from '../../hooks/utils/useLazyRef';
16
+ import { checkColumnVisibilityModelsSame, defaultSearchPredicate } from './utils';
17
+ import { jsx as _jsx } from "react/jsx-runtime";
18
+ import { jsxs as _jsxs } from "react/jsx-runtime";
19
+ var useUtilityClasses = function useUtilityClasses(ownerState) {
20
+ var classes = ownerState.classes;
21
+ var slots = {
22
+ root: ['columnsManagement'],
23
+ header: ['columnsManagementHeader'],
24
+ footer: ['columnsManagementFooter'],
25
+ row: ['columnsManagementRow']
26
+ };
27
+ return composeClasses(slots, getDataGridUtilityClass, classes);
28
+ };
29
+ var collator = new Intl.Collator();
30
+ function GridColumnsManagement(props) {
31
+ var _rootProps$slotProps, _rootProps$slotProps3, _rootProps$slotProps4;
32
+ var apiRef = useGridApiContext();
33
+ var searchInputRef = React.useRef(null);
34
+ var columns = useGridSelector(apiRef, gridColumnDefinitionsSelector);
35
+ var initialColumnVisibilityModel = useLazyRef(function () {
36
+ return gridColumnVisibilityModelSelector(apiRef);
37
+ }).current;
38
+ var columnVisibilityModel = useGridSelector(apiRef, gridColumnVisibilityModelSelector);
39
+ var rootProps = useGridRootProps();
40
+ var _React$useState = React.useState(''),
41
+ _React$useState2 = _slicedToArray(_React$useState, 2),
42
+ searchValue = _React$useState2[0],
43
+ setSearchValue = _React$useState2[1];
44
+ var classes = useUtilityClasses(rootProps);
45
+ var sort = props.sort,
46
+ _props$searchPredicat = props.searchPredicate,
47
+ searchPredicate = _props$searchPredicat === void 0 ? defaultSearchPredicate : _props$searchPredicat,
48
+ _props$autoFocusSearc = props.autoFocusSearchField,
49
+ autoFocusSearchField = _props$autoFocusSearc === void 0 ? true : _props$autoFocusSearc,
50
+ _props$disableShowHid = props.disableShowHideToggle,
51
+ disableShowHideToggle = _props$disableShowHid === void 0 ? false : _props$disableShowHid,
52
+ _props$disableResetBu = props.disableResetButton,
53
+ disableResetButton = _props$disableResetBu === void 0 ? false : _props$disableResetBu,
54
+ _props$toggleAllMode = props.toggleAllMode,
55
+ toggleAllMode = _props$toggleAllMode === void 0 ? 'all' : _props$toggleAllMode,
56
+ getTogglableColumns = props.getTogglableColumns;
57
+ var isResetDisabled = React.useMemo(function () {
58
+ return checkColumnVisibilityModelsSame(columnVisibilityModel, initialColumnVisibilityModel);
59
+ }, [columnVisibilityModel, initialColumnVisibilityModel]);
60
+ var sortedColumns = React.useMemo(function () {
61
+ switch (sort) {
62
+ case 'asc':
63
+ return _toConsumableArray(columns).sort(function (a, b) {
64
+ return collator.compare(a.headerName || a.field, b.headerName || b.field);
65
+ });
66
+ case 'desc':
67
+ return _toConsumableArray(columns).sort(function (a, b) {
68
+ return -collator.compare(a.headerName || a.field, b.headerName || b.field);
69
+ });
70
+ default:
71
+ return columns;
72
+ }
73
+ }, [columns, sort]);
74
+ var toggleColumn = function toggleColumn(event) {
75
+ var _ref = event.target,
76
+ field = _ref.name;
77
+ apiRef.current.setColumnVisibility(field, columnVisibilityModel[field] === false);
78
+ };
79
+ var currentColumns = React.useMemo(function () {
80
+ var togglableColumns = getTogglableColumns ? getTogglableColumns(sortedColumns) : null;
81
+ var togglableSortedColumns = togglableColumns ? sortedColumns.filter(function (_ref2) {
82
+ var field = _ref2.field;
83
+ return togglableColumns.includes(field);
84
+ }) : sortedColumns;
85
+ if (!searchValue) {
86
+ return togglableSortedColumns;
87
+ }
88
+ return togglableSortedColumns.filter(function (column) {
89
+ return searchPredicate(column, searchValue.toLowerCase());
90
+ });
91
+ }, [sortedColumns, searchValue, searchPredicate, getTogglableColumns]);
92
+ var toggleAllColumns = React.useCallback(function (isVisible) {
93
+ var currentModel = gridColumnVisibilityModelSelector(apiRef);
94
+ var newModel = _extends({}, currentModel);
95
+ var togglableColumns = getTogglableColumns ? getTogglableColumns(columns) : null;
96
+ (toggleAllMode === 'filteredOnly' ? currentColumns : columns).forEach(function (col) {
97
+ if (col.hideable && (togglableColumns == null || togglableColumns.includes(col.field))) {
98
+ if (isVisible) {
99
+ // delete the key from the model instead of setting it to `true`
100
+ delete newModel[col.field];
101
+ } else {
102
+ newModel[col.field] = false;
103
+ }
104
+ }
105
+ });
106
+ return apiRef.current.setColumnVisibilityModel(newModel);
107
+ }, [apiRef, columns, getTogglableColumns, toggleAllMode, currentColumns]);
108
+ var handleSearchValueChange = React.useCallback(function (event) {
109
+ setSearchValue(event.target.value);
110
+ }, []);
111
+ var hideableColumns = React.useMemo(function () {
112
+ return currentColumns.filter(function (col) {
113
+ return col.hideable;
114
+ });
115
+ }, [currentColumns]);
116
+ var allHideableColumnsVisible = React.useMemo(function () {
117
+ return hideableColumns.every(function (column) {
118
+ return columnVisibilityModel[column.field] == null || columnVisibilityModel[column.field] !== false;
119
+ });
120
+ }, [columnVisibilityModel, hideableColumns]);
121
+ var allHideableColumnsHidden = React.useMemo(function () {
122
+ return hideableColumns.every(function (column) {
123
+ return columnVisibilityModel[column.field] === false;
124
+ });
125
+ }, [columnVisibilityModel, hideableColumns]);
126
+ var firstSwitchRef = React.useRef(null);
127
+ React.useEffect(function () {
128
+ if (autoFocusSearchField) {
129
+ searchInputRef.current.focus();
130
+ } else if (firstSwitchRef.current && typeof firstSwitchRef.current.focus === 'function') {
131
+ firstSwitchRef.current.focus();
132
+ }
133
+ }, [autoFocusSearchField]);
134
+ var firstHideableColumnFound = false;
135
+ var isFirstHideableColumn = function isFirstHideableColumn(column) {
136
+ if (firstHideableColumnFound === false && column.hideable !== false) {
137
+ firstHideableColumnFound = true;
138
+ return true;
139
+ }
140
+ return false;
141
+ };
142
+ return /*#__PURE__*/_jsxs(React.Fragment, {
143
+ children: [/*#__PURE__*/_jsx(GridColumnsManagementHeader, {
144
+ className: classes.header,
145
+ ownerState: rootProps,
146
+ children: /*#__PURE__*/_jsx(rootProps.slots.baseTextField, _extends({
147
+ placeholder: apiRef.current.getLocaleText('columnsManagementSearchTitle'),
148
+ inputRef: searchInputRef,
149
+ value: searchValue,
150
+ onChange: handleSearchValueChange,
151
+ variant: "outlined",
152
+ size: "small",
153
+ InputProps: {
154
+ startAdornment: /*#__PURE__*/_jsx(rootProps.slots.baseInputAdornment, {
155
+ position: "start",
156
+ children: /*#__PURE__*/_jsx(rootProps.slots.quickFilterIcon, {})
157
+ }),
158
+ sx: {
159
+ pl: 1.5
160
+ }
161
+ },
162
+ fullWidth: true
163
+ }, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseTextField))
164
+ }), /*#__PURE__*/_jsxs(GridColumnsManagementBody, {
165
+ className: classes.root,
166
+ ownerState: rootProps,
167
+ children: [currentColumns.map(function (column) {
168
+ var _rootProps$slotProps2;
169
+ return /*#__PURE__*/_jsx(FormControlLabel, {
170
+ className: classes.row,
171
+ control: /*#__PURE__*/_jsx(rootProps.slots.baseCheckbox, _extends({
172
+ disabled: column.hideable === false,
173
+ checked: columnVisibilityModel[column.field] !== false,
174
+ onClick: toggleColumn,
175
+ name: column.field,
176
+ sx: {
177
+ p: 0.5
178
+ },
179
+ inputRef: isFirstHideableColumn(column) ? firstSwitchRef : undefined
180
+ }, (_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.baseCheckbox)),
181
+ label: column.headerName || column.field
182
+ }, column.field);
183
+ }), currentColumns.length === 0 && /*#__PURE__*/_jsx(GridColumnsManagementEmptyText, {
184
+ ownerState: rootProps,
185
+ children: apiRef.current.getLocaleText('columnsManagementNoColumns')
186
+ })]
187
+ }), !disableShowHideToggle && !disableResetButton && currentColumns.length > 0 ? /*#__PURE__*/_jsxs(GridColumnsManagementFooter, {
188
+ ownerState: rootProps,
189
+ className: classes.footer,
190
+ children: [!disableShowHideToggle ? /*#__PURE__*/_jsx(FormControlLabel, {
191
+ control: /*#__PURE__*/_jsx(rootProps.slots.baseCheckbox, _extends({
192
+ disabled: hideableColumns.length === 0,
193
+ checked: allHideableColumnsVisible,
194
+ indeterminate: !allHideableColumnsVisible && !allHideableColumnsHidden,
195
+ onClick: function onClick() {
196
+ return toggleAllColumns(!allHideableColumnsVisible);
197
+ },
198
+ name: apiRef.current.getLocaleText('columnsManagementShowHideAllText'),
199
+ sx: {
200
+ p: 0.5
201
+ }
202
+ }, (_rootProps$slotProps3 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps3.baseCheckbox)),
203
+ label: apiRef.current.getLocaleText('columnsManagementShowHideAllText')
204
+ }) : /*#__PURE__*/_jsx("span", {}), !disableResetButton ? /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
205
+ onClick: function onClick() {
206
+ return apiRef.current.setColumnVisibilityModel(initialColumnVisibilityModel);
207
+ },
208
+ disabled: isResetDisabled
209
+ }, (_rootProps$slotProps4 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps4.baseButton, {
210
+ children: "Reset"
211
+ })) : null]
212
+ }) : null]
213
+ });
214
+ }
215
+ process.env.NODE_ENV !== "production" ? GridColumnsManagement.propTypes = {
216
+ // ----------------------------- Warning --------------------------------
217
+ // | These PropTypes are generated from the TypeScript type definitions |
218
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
219
+ // ----------------------------------------------------------------------
220
+ /**
221
+ * If `true`, the column search field will be focused automatically.
222
+ * If `false`, the first column switch input will be focused automatically.
223
+ * This helps to avoid input keyboard panel to popup automatically on touch devices.
224
+ * @default true
225
+ */
226
+ autoFocusSearchField: PropTypes.bool,
227
+ /**
228
+ * If `true`, the `Reset` button will not be disabled
229
+ * @default false
230
+ */
231
+ disableResetButton: PropTypes.bool,
232
+ /**
233
+ * If `true`, the `Show/Hide all` toggle checkbox will not be displayed.
234
+ * @default false
235
+ */
236
+ disableShowHideToggle: PropTypes.bool,
237
+ /**
238
+ * Returns the list of togglable columns.
239
+ * If used, only those columns will be displayed in the panel
240
+ * which are passed as the return value of the function.
241
+ * @param {GridColDef[]} columns The `ColDef` list of all columns.
242
+ * @returns {GridColDef['field'][]} The list of togglable columns' field names.
243
+ */
244
+ getTogglableColumns: PropTypes.func,
245
+ searchPredicate: PropTypes.func,
246
+ sort: PropTypes.oneOf(['asc', 'desc']),
247
+ /**
248
+ * Changes the behavior of the `Show/Hide All` toggle when the search field is used:
249
+ * - `all`: Will toggle all columns.
250
+ * - `filteredOnly`: Will only toggle columns that match the search criteria.
251
+ * @default 'all'
252
+ */
253
+ toggleAllMode: PropTypes.oneOf(['all', 'filteredOnly'])
254
+ } : void 0;
255
+ var GridColumnsManagementBody = styled('div', {
256
+ name: 'MuiDataGrid',
257
+ slot: 'ColumnsManagement',
258
+ overridesResolver: function overridesResolver(props, styles) {
259
+ return styles.columnsManagement;
260
+ }
261
+ })(function (_ref3) {
262
+ var theme = _ref3.theme;
263
+ return {
264
+ padding: theme.spacing(0, 3, 1.5),
265
+ display: 'flex',
266
+ flexDirection: 'column',
267
+ overflow: 'auto',
268
+ flex: '1 1',
269
+ maxHeight: 400,
270
+ alignItems: 'flex-start'
271
+ };
272
+ });
273
+ var GridColumnsManagementHeader = styled('div', {
274
+ name: 'MuiDataGrid',
275
+ slot: 'ColumnsManagementHeader',
276
+ overridesResolver: function overridesResolver(props, styles) {
277
+ return styles.columnsManagementHeader;
278
+ }
279
+ })(function (_ref4) {
280
+ var theme = _ref4.theme;
281
+ return {
282
+ padding: theme.spacing(1.5, 3)
283
+ };
284
+ });
285
+ var GridColumnsManagementFooter = styled('div', {
286
+ name: 'MuiDataGrid',
287
+ slot: 'ColumnsManagementFooter',
288
+ overridesResolver: function overridesResolver(props, styles) {
289
+ return styles.columnsManagementFooter;
290
+ }
291
+ })(function (_ref5) {
292
+ var theme = _ref5.theme;
293
+ return {
294
+ padding: theme.spacing(0.5, 1, 0.5, 3),
295
+ display: 'flex',
296
+ justifyContent: 'space-between',
297
+ borderTop: "1px solid ".concat(theme.palette.divider)
298
+ };
299
+ });
300
+ var GridColumnsManagementEmptyText = styled('div')(function (_ref6) {
301
+ var theme = _ref6.theme;
302
+ return {
303
+ padding: theme.spacing(0.5, 0),
304
+ color: theme.palette.grey[500]
305
+ };
306
+ });
307
+ export { GridColumnsManagement };
@@ -0,0 +1 @@
1
+ export * from './GridColumnsManagement';
@@ -0,0 +1,22 @@
1
+ export var checkColumnVisibilityModelsSame = function checkColumnVisibilityModelsSame(a, b) {
2
+ // Filter `false` values only, as `true` and not having a key are the same
3
+ var aFalseValues = new Set(Object.keys(a).filter(function (key) {
4
+ return a[key] === false;
5
+ }));
6
+ var bFalseValues = new Set(Object.keys(b).filter(function (key) {
7
+ return b[key] === false;
8
+ }));
9
+ if (aFalseValues.size !== bFalseValues.size) {
10
+ return false;
11
+ }
12
+ var result = true;
13
+ aFalseValues.forEach(function (key) {
14
+ if (!bFalseValues.has(key)) {
15
+ result = false;
16
+ }
17
+ });
18
+ return result;
19
+ };
20
+ export var defaultSearchPredicate = function defaultSearchPredicate(column, searchValue) {
21
+ return (column.headerName || column.field).toLowerCase().indexOf(searchValue) > -1;
22
+ };
@@ -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';