@mui/x-data-grid 9.13.0 → 9.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. package/CHANGELOG.md +325 -0
  2. package/DataGrid/DataGrid.js +8 -0
  3. package/DataGrid/DataGrid.mjs +9 -1
  4. package/DataGrid/useDataGridComponent.js +2 -2
  5. package/DataGrid/useDataGridComponent.mjs +2 -2
  6. package/DataGrid/useDataGridProps.mjs +1 -1
  7. package/colDef/gridActionsColDef.mjs +1 -1
  8. package/colDef/gridBooleanColDef.mjs +1 -1
  9. package/colDef/gridCheckboxSelectionColDef.mjs +1 -1
  10. package/colDef/gridDateColDef.mjs +1 -1
  11. package/colDef/gridDefaultColumnTypes.mjs +1 -1
  12. package/colDef/gridLongTextColDef.mjs +1 -1
  13. package/colDef/gridNumericColDef.mjs +1 -1
  14. package/colDef/gridSingleSelectColDef.mjs +1 -1
  15. package/components/GridColumnHeaders.mjs +2 -2
  16. package/components/GridColumnSortButton.mjs +2 -2
  17. package/components/GridColumnUnsortedIcon.mjs +2 -2
  18. package/components/GridFooter.mjs +1 -1
  19. package/components/GridHeader.mjs +1 -1
  20. package/components/GridHeaders.mjs +1 -1
  21. package/components/GridLoadingOverlay.mjs +2 -2
  22. package/components/GridNoColumnsOverlay.mjs +1 -1
  23. package/components/GridNoResultsOverlay.mjs +1 -1
  24. package/components/GridNoRowsOverlay.mjs +1 -1
  25. package/components/GridPagination.js +9 -1
  26. package/components/GridPagination.mjs +10 -2
  27. package/components/GridRow.mjs +2 -2
  28. package/components/GridRowCount.mjs +2 -2
  29. package/components/GridRowDragAndDropOverlay.mjs +1 -1
  30. package/components/GridScrollArea.js +20 -7
  31. package/components/GridScrollArea.mjs +22 -9
  32. package/components/GridSelectedRowCount.mjs +2 -2
  33. package/components/GridShadowScrollArea.mjs +2 -2
  34. package/components/GridSkeletonLoadingOverlay.mjs +2 -2
  35. package/components/base/GridFooterPlaceholder.mjs +1 -1
  36. package/components/base/GridOverlays.js +6 -5
  37. package/components/base/GridOverlays.mjs +7 -6
  38. package/components/cell/GridActionsCell.js +55 -52
  39. package/components/cell/GridActionsCell.mjs +58 -55
  40. package/components/cell/GridActionsCellItem.d.mts +20 -6
  41. package/components/cell/GridActionsCellItem.d.ts +20 -6
  42. package/components/cell/GridActionsCellItem.js +30 -8
  43. package/components/cell/GridActionsCellItem.mjs +32 -10
  44. package/components/cell/GridBooleanCell.mjs +2 -2
  45. package/components/cell/GridCell.js +9 -1
  46. package/components/cell/GridCell.mjs +11 -3
  47. package/components/cell/GridEditBooleanCell.mjs +2 -2
  48. package/components/cell/GridEditDateCell.mjs +2 -2
  49. package/components/cell/GridEditInputCell.mjs +2 -2
  50. package/components/cell/GridEditLongTextCell.mjs +1 -1
  51. package/components/cell/GridEditSingleSelectCell.mjs +2 -2
  52. package/components/cell/GridFooterCell.mjs +2 -2
  53. package/components/cell/GridLongTextCell.mjs +1 -1
  54. package/components/cell/GridSkeletonCell.mjs +2 -2
  55. package/components/columnHeaders/ColumnHeaderMenuIcon.mjs +1 -1
  56. package/components/columnHeaders/GridBaseColumnHeaders.mjs +2 -2
  57. package/components/columnHeaders/GridColumnGroupHeader.mjs +1 -1
  58. package/components/columnHeaders/GridColumnHeaderFilterIconButton.mjs +1 -1
  59. package/components/columnHeaders/GridColumnHeaderItem.mjs +1 -1
  60. package/components/columnHeaders/GridColumnHeaderSeparator.d.mts +1 -1
  61. package/components/columnHeaders/GridColumnHeaderSeparator.d.ts +1 -1
  62. package/components/columnHeaders/GridColumnHeaderSeparator.mjs +2 -2
  63. package/components/columnHeaders/GridColumnHeaderSortIcon.js +17 -0
  64. package/components/columnHeaders/GridColumnHeaderSortIcon.mjs +18 -1
  65. package/components/columnHeaders/GridColumnHeaderTitle.mjs +2 -2
  66. package/components/columnHeaders/GridGenericColumnHeaderItem.mjs +2 -2
  67. package/components/columnHeaders/GridIconButtonContainer.mjs +2 -2
  68. package/components/columnSelection/GridCellCheckboxRenderer.mjs +2 -2
  69. package/components/columnSelection/GridHeaderCheckbox.mjs +2 -2
  70. package/components/columnSelection/GridRowCheckbox.js +1 -3
  71. package/components/columnSelection/GridRowCheckbox.mjs +3 -5
  72. package/components/columnsManagement/GridColumnsManagement.mjs +1 -1
  73. package/components/columnsPanel/ColumnsPanelTrigger.mjs +2 -2
  74. package/components/containers/GridFooterContainer.mjs +2 -2
  75. package/components/containers/GridOverlay.mjs +2 -2
  76. package/components/containers/GridRoot.mjs +2 -2
  77. package/components/containers/GridRootStyles.js +22 -10
  78. package/components/containers/GridRootStyles.mjs +22 -10
  79. package/components/containers/GridToolbarContainer.mjs +2 -2
  80. package/components/export/ExportCsv.mjs +2 -2
  81. package/components/export/ExportPrint.js +4 -1
  82. package/components/export/ExportPrint.mjs +6 -3
  83. package/components/filterPanel/FilterPanelTrigger.mjs +2 -2
  84. package/components/menu/GridMenu.mjs +2 -2
  85. package/components/menu/columnMenu/GridColumnHeaderMenu.mjs +1 -1
  86. package/components/menu/columnMenu/GridColumnMenu.mjs +2 -2
  87. package/components/menu/columnMenu/GridColumnMenuContainer.mjs +2 -2
  88. package/components/menu/columnMenu/menuItems/GridColumnMenuColumnsItem.mjs +1 -1
  89. package/components/panel/GridColumnsPanel.mjs +1 -1
  90. package/components/panel/GridPanel.mjs +2 -2
  91. package/components/panel/GridPanelContent.mjs +2 -2
  92. package/components/panel/GridPanelContext.mjs +1 -1
  93. package/components/panel/GridPanelFooter.mjs +2 -2
  94. package/components/panel/GridPanelHeader.mjs +2 -2
  95. package/components/panel/GridPanelWrapper.mjs +2 -2
  96. package/components/panel/GridPreferencesPanel.mjs +1 -1
  97. package/components/panel/filterPanel/GridFilterForm.mjs +1 -1
  98. package/components/panel/filterPanel/GridFilterFormBase.mjs +2 -2
  99. package/components/panel/filterPanel/GridFilterInputBoolean.js +1 -12
  100. package/components/panel/filterPanel/GridFilterInputBoolean.mjs +3 -14
  101. package/components/panel/filterPanel/GridFilterInputDate.mjs +2 -2
  102. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.mjs +2 -2
  103. package/components/panel/filterPanel/GridFilterInputMultipleValue.mjs +2 -2
  104. package/components/panel/filterPanel/GridFilterInputSingleSelect.js +1 -12
  105. package/components/panel/filterPanel/GridFilterInputSingleSelect.mjs +3 -14
  106. package/components/panel/filterPanel/GridFilterInputValue.mjs +2 -2
  107. package/components/panel/filterPanel/GridFilterPanel.mjs +1 -1
  108. package/components/panel/filterPanel/GridFilterPanelBase.mjs +2 -2
  109. package/components/panel/filterPanel/filterPanelUtils.mjs +1 -1
  110. package/components/quickFilter/QuickFilter.js +7 -2
  111. package/components/quickFilter/QuickFilter.mjs +9 -4
  112. package/components/quickFilter/QuickFilterClear.js +17 -0
  113. package/components/quickFilter/QuickFilterClear.mjs +19 -2
  114. package/components/quickFilter/QuickFilterControl.mjs +2 -2
  115. package/components/quickFilter/QuickFilterTrigger.mjs +2 -2
  116. package/components/toolbar/GridToolbar.mjs +2 -2
  117. package/components/toolbar/GridToolbarColumnsButton.mjs +1 -1
  118. package/components/toolbar/GridToolbarDensitySelector.mjs +1 -1
  119. package/components/toolbar/GridToolbarExport.js +4 -1
  120. package/components/toolbar/GridToolbarExport.mjs +6 -3
  121. package/components/toolbar/GridToolbarExportContainer.mjs +1 -1
  122. package/components/toolbar/GridToolbarFilterButton.mjs +1 -1
  123. package/components/toolbar/GridToolbarQuickFilter.mjs +2 -2
  124. package/components/toolbarV8/GridToolbar.mjs +2 -2
  125. package/components/toolbarV8/Toolbar.mjs +2 -2
  126. package/components/toolbarV8/ToolbarButton.js +17 -0
  127. package/components/toolbarV8/ToolbarButton.mjs +19 -2
  128. package/components/virtualization/GridBottomContainer.mjs +1 -1
  129. package/components/virtualization/GridMainContainer.mjs +1 -1
  130. package/components/virtualization/GridTopContainer.mjs +1 -1
  131. package/components/virtualization/GridVirtualScrollbar.js +2 -2
  132. package/components/virtualization/GridVirtualScrollbar.mjs +2 -2
  133. package/components/virtualization/GridVirtualScroller.js +5 -2
  134. package/components/virtualization/GridVirtualScroller.mjs +6 -3
  135. package/components/virtualization/GridVirtualScrollerContent.mjs +1 -1
  136. package/components/virtualization/GridVirtualScrollerRenderZone.mjs +1 -1
  137. package/constants/cssVariables.mjs +1 -1
  138. package/constants/defaultGridSlotsComponents.mjs +1 -1
  139. package/constants/signature.d.mts +1 -1
  140. package/constants/signature.d.ts +1 -1
  141. package/hooks/core/pipeProcessing/useGridPipeProcessing.mjs +2 -2
  142. package/hooks/core/pipeProcessing/useGridRegisterPipeApplier.js +2 -2
  143. package/hooks/core/pipeProcessing/useGridRegisterPipeApplier.mjs +2 -2
  144. package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +2 -2
  145. package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.mjs +2 -2
  146. package/hooks/core/strategyProcessing/gridStrategyProcessingApi.d.mts +1 -1
  147. package/hooks/core/strategyProcessing/gridStrategyProcessingApi.d.ts +1 -1
  148. package/hooks/core/strategyProcessing/useGridRegisterStrategyProcessor.js +2 -2
  149. package/hooks/core/strategyProcessing/useGridRegisterStrategyProcessor.mjs +2 -2
  150. package/hooks/core/strategyProcessing/useGridStrategyProcessing.mjs +2 -2
  151. package/hooks/core/useGridApiInitialization.js +1 -1
  152. package/hooks/core/useGridApiInitialization.mjs +1 -1
  153. package/hooks/core/useGridIsRtl.mjs +1 -1
  154. package/hooks/core/useGridProps.mjs +1 -1
  155. package/hooks/core/useGridStateInitialization.mjs +1 -1
  156. package/hooks/core/useGridVirtualizer.d.mts +2 -2
  157. package/hooks/core/useGridVirtualizer.d.ts +2 -2
  158. package/hooks/core/useGridVirtualizer.js +6 -6
  159. package/hooks/core/useGridVirtualizer.mjs +4 -4
  160. package/hooks/features/columnGrouping/gridColumnGroupsUtils.mjs +2 -2
  161. package/hooks/features/columnGrouping/useGridColumnGrouping.mjs +1 -1
  162. package/hooks/features/columnHeaders/useGridColumnHeaders.mjs +1 -1
  163. package/hooks/features/columnMenu/getColumnMenuItemKeys.mjs +1 -1
  164. package/hooks/features/columnMenu/useGridColumnMenu.mjs +1 -1
  165. package/hooks/features/columnMenu/useGridColumnMenuSlots.mjs +2 -2
  166. package/hooks/features/columnResize/useGridColumnResize.js +4 -1
  167. package/hooks/features/columnResize/useGridColumnResize.mjs +5 -2
  168. package/hooks/features/columns/gridColumnsInterfaces.d.mts +1 -1
  169. package/hooks/features/columns/gridColumnsInterfaces.d.ts +1 -1
  170. package/hooks/features/columns/gridColumnsUtils.d.mts +1 -1
  171. package/hooks/features/columns/gridColumnsUtils.d.ts +1 -1
  172. package/hooks/features/columns/gridColumnsUtils.mjs +1 -1
  173. package/hooks/features/columns/useGridColumns.js +1 -1
  174. package/hooks/features/columns/useGridColumns.mjs +2 -2
  175. package/hooks/features/dataSource/cache.js +1 -1
  176. package/hooks/features/dataSource/cache.mjs +1 -1
  177. package/hooks/features/dataSource/useGridDataSourceBase.js +14 -29
  178. package/hooks/features/dataSource/useGridDataSourceBase.mjs +17 -32
  179. package/hooks/features/dataSource/useGridDataSourcePolling.d.mts +29 -0
  180. package/hooks/features/dataSource/useGridDataSourcePolling.d.ts +29 -0
  181. package/hooks/features/dataSource/useGridDataSourcePolling.js +62 -0
  182. package/hooks/features/dataSource/useGridDataSourcePolling.mjs +54 -0
  183. package/hooks/features/dataSource/utils.d.mts +1 -1
  184. package/hooks/features/dataSource/utils.d.ts +1 -1
  185. package/hooks/features/dataSource/utils.mjs +1 -1
  186. package/hooks/features/density/useGridDensity.mjs +1 -1
  187. package/hooks/features/dimensions/useGridDimensions.d.mts +1 -1
  188. package/hooks/features/dimensions/useGridDimensions.d.ts +1 -1
  189. package/hooks/features/dimensions/useGridDimensions.js +3 -3
  190. package/hooks/features/dimensions/useGridDimensions.mjs +3 -3
  191. package/hooks/features/editing/useGridCellEditing.js +1 -1
  192. package/hooks/features/editing/useGridCellEditing.mjs +5 -5
  193. package/hooks/features/editing/useGridEditing.mjs +1 -1
  194. package/hooks/features/editing/useGridRowEditing.js +1 -1
  195. package/hooks/features/editing/useGridRowEditing.mjs +5 -5
  196. package/hooks/features/export/serializers/csvSerializer.js +5 -5
  197. package/hooks/features/export/serializers/csvSerializer.mjs +5 -5
  198. package/hooks/features/export/useGridPrintExport.js +44 -20
  199. package/hooks/features/export/useGridPrintExport.mjs +45 -21
  200. package/hooks/features/filter/gridFilterUtils.js +3 -3
  201. package/hooks/features/filter/gridFilterUtils.mjs +5 -5
  202. package/hooks/features/filter/useGridFilter.js +2 -2
  203. package/hooks/features/filter/useGridFilter.mjs +3 -3
  204. package/hooks/features/focus/useGridFocus.mjs +1 -1
  205. package/hooks/features/headerFiltering/useGridHeaderFiltering.mjs +1 -1
  206. package/hooks/features/listView/useGridListView.d.mts +2 -2
  207. package/hooks/features/listView/useGridListView.d.ts +2 -2
  208. package/hooks/features/listView/useGridListView.js +1 -1
  209. package/hooks/features/listView/useGridListView.mjs +2 -2
  210. package/hooks/features/pagination/useGridPagination.mjs +1 -1
  211. package/hooks/features/pagination/useGridPaginationMeta.mjs +1 -1
  212. package/hooks/features/pagination/useGridPaginationModel.mjs +1 -1
  213. package/hooks/features/pagination/useGridRowCount.js +2 -2
  214. package/hooks/features/pagination/useGridRowCount.mjs +2 -2
  215. package/hooks/features/preferencesPanel/gridPreferencePanelsValue.d.mts +1 -1
  216. package/hooks/features/preferencesPanel/gridPreferencePanelsValue.d.ts +1 -1
  217. package/hooks/features/preferencesPanel/useGridPreferencesPanel.mjs +1 -1
  218. package/hooks/features/rowSelection/useGridRowSelection.d.mts +1 -1
  219. package/hooks/features/rowSelection/useGridRowSelection.d.ts +1 -1
  220. package/hooks/features/rowSelection/useGridRowSelection.js +50 -9
  221. package/hooks/features/rowSelection/useGridRowSelection.mjs +52 -11
  222. package/hooks/features/rowSelection/useGridRowSelectionPreProcessors.mjs +1 -1
  223. package/hooks/features/rowSelection/utils.js +5 -0
  224. package/hooks/features/rowSelection/utils.mjs +5 -0
  225. package/hooks/features/rows/gridRowsUtils.js +2 -2
  226. package/hooks/features/rows/gridRowsUtils.mjs +3 -3
  227. package/hooks/features/rows/useGridRowSpanning.mjs +1 -1
  228. package/hooks/features/rows/useGridRows.mjs +1 -1
  229. package/hooks/features/rows/useGridRowsMeta.mjs +1 -1
  230. package/hooks/features/rows/useGridRowsOverridableMethods.mjs +1 -1
  231. package/hooks/features/rows/useGridRowsPreProcessors.mjs +1 -1
  232. package/hooks/features/sorting/gridSortingUtils.js +1 -1
  233. package/hooks/features/sorting/gridSortingUtils.mjs +3 -3
  234. package/hooks/features/sorting/useGridSorting.js +2 -2
  235. package/hooks/features/sorting/useGridSorting.mjs +3 -3
  236. package/hooks/features/virtualization/gridFocusedVirtualCellSelector.mjs +1 -1
  237. package/hooks/features/virtualization/useGridVirtualization.mjs +1 -1
  238. package/hooks/utils/index.d.mts +1 -1
  239. package/hooks/utils/index.d.ts +1 -1
  240. package/hooks/utils/index.js +8 -12
  241. package/hooks/utils/index.mjs +2 -1
  242. package/hooks/utils/useGridSelector.js +2 -2
  243. package/hooks/utils/useGridSelector.mjs +2 -2
  244. package/index.js +1 -1
  245. package/index.mjs +1 -1
  246. package/internals/constants.d.mts +1 -1
  247. package/internals/constants.d.ts +1 -1
  248. package/internals/index.d.mts +1 -0
  249. package/internals/index.d.ts +1 -0
  250. package/internals/index.js +8 -0
  251. package/internals/index.mjs +1 -0
  252. package/internals/utils/cache.d.mts +0 -1
  253. package/internals/utils/cache.d.ts +0 -1
  254. package/internals/utils/cache.js +1 -3
  255. package/internals/utils/cache.mjs +1 -3
  256. package/internals/utils/computeSlots.mjs +1 -1
  257. package/internals/utils/propValidation.js +2 -2
  258. package/internals/utils/propValidation.mjs +3 -3
  259. package/material/index.mjs +2 -2
  260. package/models/api/gridCoreApi.d.mts +1 -1
  261. package/models/api/gridCoreApi.d.ts +1 -1
  262. package/models/api/gridEditingApi.d.mts +6 -6
  263. package/models/api/gridEditingApi.d.ts +6 -6
  264. package/models/api/gridPrintExportApi.d.mts +2 -1
  265. package/models/api/gridPrintExportApi.d.ts +2 -1
  266. package/models/events/gridEventLookup.d.mts +5 -5
  267. package/models/events/gridEventLookup.d.ts +5 -5
  268. package/models/gridBaseSlots.d.mts +18 -1
  269. package/models/gridBaseSlots.d.ts +18 -1
  270. package/models/gridEditRowModel.d.mts +3 -3
  271. package/models/gridEditRowModel.d.ts +3 -3
  272. package/models/gridExport.d.mts +13 -0
  273. package/models/gridExport.d.ts +13 -0
  274. package/models/gridFilterItem.d.mts +2 -2
  275. package/models/gridFilterItem.d.ts +2 -2
  276. package/models/index.d.mts +2 -1
  277. package/models/index.d.ts +2 -1
  278. package/models/params/gridEditCellParams.d.mts +2 -2
  279. package/models/params/gridEditCellParams.d.ts +2 -2
  280. package/models/params/gridRowParams.d.mts +2 -2
  281. package/models/params/gridRowParams.d.ts +2 -2
  282. package/models/props/DataGridProps.d.mts +8 -0
  283. package/models/props/DataGridProps.d.ts +8 -0
  284. package/package.json +6 -6
  285. package/utils/createSelector.d.mts +1 -1
  286. package/utils/createSelector.d.ts +1 -1
  287. package/utils/createSelector.js +1 -1
  288. package/utils/createSelector.mjs +1 -1
  289. package/hooks/utils/useFirstRender.d.mts +0 -1
  290. package/hooks/utils/useFirstRender.d.ts +0 -1
  291. package/hooks/utils/useFirstRender.js +0 -16
  292. package/hooks/utils/useFirstRender.mjs +0 -1
@@ -0,0 +1,29 @@
1
+ interface UseGridDataSourcePollingOptions {
2
+ /**
3
+ * The polling interval in milliseconds. The polling is off when it is `0` or less.
4
+ */
5
+ revalidateMs: number;
6
+ /**
7
+ * The polling is off when it is `false`.
8
+ */
9
+ isActive: boolean;
10
+ /**
11
+ * Runs when `<Activity>` shows the grid again, if the polling started before.
12
+ * @returns {boolean} `true` to resume the polling.
13
+ * @default () => true
14
+ */
15
+ shouldResume?: () => boolean;
16
+ }
17
+ /**
18
+ * Calls a revalidation callback at the `revalidateMs` interval.
19
+ * The polling pauses while `<Activity>` hides the grid and stops after the grid unmounts.
20
+ */
21
+ export declare const useGridDataSourcePolling: ({
22
+ revalidateMs,
23
+ isActive,
24
+ shouldResume
25
+ }: UseGridDataSourcePollingOptions) => {
26
+ startPolling: (callback: () => void) => void;
27
+ stopPolling: () => void;
28
+ };
29
+ export {};
@@ -0,0 +1,29 @@
1
+ interface UseGridDataSourcePollingOptions {
2
+ /**
3
+ * The polling interval in milliseconds. The polling is off when it is `0` or less.
4
+ */
5
+ revalidateMs: number;
6
+ /**
7
+ * The polling is off when it is `false`.
8
+ */
9
+ isActive: boolean;
10
+ /**
11
+ * Runs when `<Activity>` shows the grid again, if the polling started before.
12
+ * @returns {boolean} `true` to resume the polling.
13
+ * @default () => true
14
+ */
15
+ shouldResume?: () => boolean;
16
+ }
17
+ /**
18
+ * Calls a revalidation callback at the `revalidateMs` interval.
19
+ * The polling pauses while `<Activity>` hides the grid and stops after the grid unmounts.
20
+ */
21
+ export declare const useGridDataSourcePolling: ({
22
+ revalidateMs,
23
+ isActive,
24
+ shouldResume
25
+ }: UseGridDataSourcePollingOptions) => {
26
+ startPolling: (callback: () => void) => void;
27
+ stopPolling: () => void;
28
+ };
29
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.useGridDataSourcePolling = void 0;
10
+ var React = _interopRequireWildcard(require("react"));
11
+ var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
12
+ /**
13
+ * Calls a revalidation callback at the `revalidateMs` interval.
14
+ * The polling pauses while `<Activity>` hides the grid and stops after the grid unmounts.
15
+ */
16
+ const useGridDataSourcePolling = ({
17
+ revalidateMs,
18
+ isActive,
19
+ shouldResume = () => true
20
+ }) => {
21
+ const pollingIntervalRef = React.useRef(null);
22
+ const pollingCallbackRef = React.useRef(null);
23
+ // `false` while Activity is hidden or after unmount, so a late response cannot restart polling.
24
+ const isPollingAllowed = React.useRef(true);
25
+ const stopPolling = React.useCallback(() => {
26
+ if (pollingIntervalRef.current !== null) {
27
+ clearInterval(pollingIntervalRef.current);
28
+ pollingIntervalRef.current = null;
29
+ }
30
+ }, []);
31
+ const startPolling = (0, _useEventCallback.default)(callback => {
32
+ stopPolling();
33
+ // Keep the callback while Activity is hidden to resume the polling on show.
34
+ pollingCallbackRef.current = callback;
35
+ if (!isPollingAllowed.current || !isActive || revalidateMs <= 0) {
36
+ return;
37
+ }
38
+ pollingIntervalRef.current = setInterval(callback, revalidateMs);
39
+ });
40
+ React.useEffect(() => {
41
+ if (!isActive || revalidateMs <= 0) {
42
+ stopPolling();
43
+ }
44
+ }, [isActive, revalidateMs, stopPolling]);
45
+ const canResume = (0, _useEventCallback.default)(shouldResume);
46
+ React.useEffect(() => {
47
+ isPollingAllowed.current = true;
48
+ // Activity runs the effects again when it shows the grid, so resume the paused polling.
49
+ if (pollingCallbackRef.current && canResume()) {
50
+ startPolling(pollingCallbackRef.current);
51
+ }
52
+ return () => {
53
+ isPollingAllowed.current = false;
54
+ stopPolling();
55
+ };
56
+ }, [startPolling, stopPolling, canResume]);
57
+ return {
58
+ startPolling,
59
+ stopPolling
60
+ };
61
+ };
62
+ exports.useGridDataSourcePolling = useGridDataSourcePolling;
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import useEventCallback from '@mui/utils/useEventCallback';
5
+ /**
6
+ * Calls a revalidation callback at the `revalidateMs` interval.
7
+ * The polling pauses while `<Activity>` hides the grid and stops after the grid unmounts.
8
+ */
9
+ export const useGridDataSourcePolling = ({
10
+ revalidateMs,
11
+ isActive,
12
+ shouldResume = () => true
13
+ }) => {
14
+ const pollingIntervalRef = React.useRef(null);
15
+ const pollingCallbackRef = React.useRef(null);
16
+ // `false` while Activity is hidden or after unmount, so a late response cannot restart polling.
17
+ const isPollingAllowed = React.useRef(true);
18
+ const stopPolling = React.useCallback(() => {
19
+ if (pollingIntervalRef.current !== null) {
20
+ clearInterval(pollingIntervalRef.current);
21
+ pollingIntervalRef.current = null;
22
+ }
23
+ }, []);
24
+ const startPolling = useEventCallback(callback => {
25
+ stopPolling();
26
+ // Keep the callback while Activity is hidden to resume the polling on show.
27
+ pollingCallbackRef.current = callback;
28
+ if (!isPollingAllowed.current || !isActive || revalidateMs <= 0) {
29
+ return;
30
+ }
31
+ pollingIntervalRef.current = setInterval(callback, revalidateMs);
32
+ });
33
+ React.useEffect(() => {
34
+ if (!isActive || revalidateMs <= 0) {
35
+ stopPolling();
36
+ }
37
+ }, [isActive, revalidateMs, stopPolling]);
38
+ const canResume = useEventCallback(shouldResume);
39
+ React.useEffect(() => {
40
+ isPollingAllowed.current = true;
41
+ // Activity runs the effects again when it shows the grid, so resume the paused polling.
42
+ if (pollingCallbackRef.current && canResume()) {
43
+ startPolling(pollingCallbackRef.current);
44
+ }
45
+ return () => {
46
+ isPollingAllowed.current = false;
47
+ stopPolling();
48
+ };
49
+ }, [startPolling, stopPolling, canResume]);
50
+ return {
51
+ startPolling,
52
+ stopPolling
53
+ };
54
+ };
@@ -3,7 +3,7 @@ export declare enum DataSourceRowsUpdateStrategy {
3
3
  Default = "set-flat-rows",
4
4
  LazyLoading = "replace-row-range",
5
5
  GroupedData = "set-grouped-rows",
6
- LazyLoadedGroupedData = "replace-grouped-row-range",
6
+ LazyLoadedGroupedData = "replace-grouped-row-range"
7
7
  }
8
8
  /**
9
9
  * Provides better cache hit rate by:
@@ -3,7 +3,7 @@ export declare enum DataSourceRowsUpdateStrategy {
3
3
  Default = "set-flat-rows",
4
4
  LazyLoading = "replace-row-range",
5
5
  GroupedData = "set-grouped-rows",
6
- LazyLoadedGroupedData = "replace-grouped-row-range",
6
+ LazyLoadedGroupedData = "replace-grouped-row-range"
7
7
  }
8
8
  /**
9
9
  * Provides better cache hit rate by:
@@ -1,4 +1,4 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
1
+ import _extends from "@babel/runtime/helpers/extends";
2
2
  export let DataSourceRowsUpdateStrategy = /*#__PURE__*/function (DataSourceRowsUpdateStrategy) {
3
3
  DataSourceRowsUpdateStrategy["Default"] = "set-flat-rows";
4
4
  DataSourceRowsUpdateStrategy["LazyLoading"] = "replace-row-range";
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import _extends from "@babel/runtime/helpers/extends";
4
4
  import * as React from 'react';
5
5
  import useEventCallback from '@mui/utils/useEventCallback';
6
6
  import { useGridLogger } from "../../utils/useGridLogger.mjs";
@@ -3,7 +3,7 @@ import type { GridPrivateApiCommunity } from "../../../models/api/gridApiCommuni
3
3
  import type { DataGridProcessedProps } from "../../../models/props/DataGridProps.mjs";
4
4
  import type { GridDimensions } from "./gridDimensionsApi.mjs";
5
5
  import type { GridStateInitializer } from "../../utils/useGridInitializeState.mjs";
6
- type RootProps = Pick<DataGridProcessedProps, 'onResize' | 'scrollbarSize' | 'pagination' | 'paginationMode' | 'autoHeight' | 'getRowHeight' | 'rowHeight' | 'resizeThrottleMs' | 'columnHeaderHeight' | 'columnGroupHeaderHeight' | 'headerFilterHeight'>;
6
+ type RootProps = Pick<DataGridProcessedProps, 'onResize' | 'scrollbarSize' | 'pagination' | 'paginationMode' | 'autoHeight' | 'height' | 'getRowHeight' | 'rowHeight' | 'resizeThrottleMs' | 'columnHeaderHeight' | 'columnGroupHeaderHeight' | 'headerFilterHeight'>;
7
7
  export type GridDimensionsState = GridDimensions;
8
8
  export declare const dimensionsStateInitializer: GridStateInitializer<RootProps>;
9
9
  export declare function useGridDimensions(apiRef: RefObject<GridPrivateApiCommunity>, props: RootProps): void;
@@ -3,7 +3,7 @@ import type { GridPrivateApiCommunity } from "../../../models/api/gridApiCommuni
3
3
  import type { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
4
4
  import type { GridDimensions } from "./gridDimensionsApi.js";
5
5
  import type { GridStateInitializer } from "../../utils/useGridInitializeState.js";
6
- type RootProps = Pick<DataGridProcessedProps, 'onResize' | 'scrollbarSize' | 'pagination' | 'paginationMode' | 'autoHeight' | 'getRowHeight' | 'rowHeight' | 'resizeThrottleMs' | 'columnHeaderHeight' | 'columnGroupHeaderHeight' | 'headerFilterHeight'>;
6
+ type RootProps = Pick<DataGridProcessedProps, 'onResize' | 'scrollbarSize' | 'pagination' | 'paginationMode' | 'autoHeight' | 'height' | 'getRowHeight' | 'rowHeight' | 'resizeThrottleMs' | 'columnHeaderHeight' | 'columnGroupHeaderHeight' | 'headerFilterHeight'>;
7
7
  export type GridDimensionsState = GridDimensions;
8
8
  export declare const dimensionsStateInitializer: GridStateInitializer<RootProps>;
9
9
  export declare function useGridDimensions(apiRef: RefObject<GridPrivateApiCommunity>, props: RootProps): void;
@@ -11,7 +11,7 @@ exports.useGridDimensions = useGridDimensions;
11
11
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
12
  var React = _interopRequireWildcard(require("react"));
13
13
  var _platform = require("@base-ui/utils/platform");
14
- var _store = require("@mui/x-internals/store");
14
+ var _useStoreEffect = require("@mui/x-internals/useStoreEffect");
15
15
  var _useGridEvent = require("../../utils/useGridEvent");
16
16
  var _useGridApiMethod = require("../../utils/useGridApiMethod");
17
17
  var _createSelector = require("../../../utils/createSelector");
@@ -96,7 +96,7 @@ function useGridDimensions(apiRef, props) {
96
96
  if (!getRootDimensions().isReady) {
97
97
  return;
98
98
  }
99
- if (size.height === 0 && !errorShown.current && !props.autoHeight && !_platform.platform.env.jsdom) {
99
+ if (size.height === 0 && props.height == null && !errorShown.current && !props.autoHeight && !_platform.platform.env.jsdom) {
100
100
  logger.error(['The parent DOM element of the Data Grid has an empty height.', 'Please make sure that this element has an intrinsic height.', 'The grid displays with a height of 0px.', '', 'More details: https://mui.com/r/x-data-grid-no-dimensions.'].join('\n'));
101
101
  errorShown.current = true;
102
102
  }
@@ -107,7 +107,7 @@ function useGridDimensions(apiRef, props) {
107
107
  });
108
108
  /* eslint-enable react-hooks/rules-of-hooks */
109
109
  }
110
- (0, _store.useStoreEffect)(apiRef.current.store, s => s.dimensions, (previous, next) => {
110
+ (0, _useStoreEffect.useStoreEffect)(apiRef.current.store, s => s.dimensions, (previous, next) => {
111
111
  if (!next.isReady) {
112
112
  return;
113
113
  }
@@ -1,9 +1,9 @@
1
1
  'use client';
2
2
 
3
- import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import _extends from "@babel/runtime/helpers/extends";
4
4
  import * as React from 'react';
5
5
  import { platform } from '@base-ui/utils/platform';
6
- import { useStoreEffect } from '@mui/x-internals/store';
6
+ import { useStoreEffect } from '@mui/x-internals/useStoreEffect';
7
7
  import { useGridEventPriority } from "../../utils/useGridEvent.mjs";
8
8
  import { useGridApiMethod } from "../../utils/useGridApiMethod.mjs";
9
9
  import { createSelector } from "../../../utils/createSelector.mjs";
@@ -87,7 +87,7 @@ export function useGridDimensions(apiRef, props) {
87
87
  if (!getRootDimensions().isReady) {
88
88
  return;
89
89
  }
90
- if (size.height === 0 && !errorShown.current && !props.autoHeight && !platform.env.jsdom) {
90
+ if (size.height === 0 && props.height == null && !errorShown.current && !props.autoHeight && !platform.env.jsdom) {
91
91
  logger.error(['The parent DOM element of the Data Grid has an empty height.', 'Please make sure that this element has an intrinsic height.', 'The grid displays with a height of 0px.', '', 'More details: https://mui.com/r/x-data-grid-no-dimensions.'].join('\n'));
92
92
  errorShown.current = true;
93
93
  }
@@ -382,7 +382,7 @@ const useGridCellEditing = (apiRef, props) => {
382
382
  if (onProcessRowUpdateError) {
383
383
  onProcessRowUpdateError(errorThrown);
384
384
  } else if (process.env.NODE_ENV !== 'production') {
385
- (0, _warning.warnOnce)(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
385
+ (0, _warning.errorOnce)(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'].join('\n'));
386
386
  }
387
387
  };
388
388
  try {
@@ -1,13 +1,13 @@
1
1
  'use client';
2
2
 
3
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
- import _toPropertyKey from "@babel/runtime/helpers/esm/toPropertyKey";
5
- import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
4
+ import _toPropertyKey from "@babel/runtime/helpers/toPropertyKey";
5
+ import _extends from "@babel/runtime/helpers/extends";
6
6
  import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
7
7
  const _excluded = ["id", "field"],
8
8
  _excluded2 = ["id", "field"];
9
9
  import * as React from 'react';
10
- import { warnOnce } from '@mui/x-internals/warning';
10
+ import { errorOnce } from '@mui/x-internals/warning';
11
11
  import useEventCallback from '@mui/utils/useEventCallback';
12
12
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
13
13
  import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
@@ -375,7 +375,7 @@ export const useGridCellEditing = (apiRef, props) => {
375
375
  if (onProcessRowUpdateError) {
376
376
  onProcessRowUpdateError(errorThrown);
377
377
  } else if (process.env.NODE_ENV !== 'production') {
378
- warnOnce(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
378
+ errorOnce(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'].join('\n'));
379
379
  }
380
380
  };
381
381
  try {
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import _extends from "@babel/runtime/helpers/extends";
4
4
  import * as React from 'react';
5
5
  import { useGridApiMethod } from "../../utils/useGridApiMethod.mjs";
6
6
  import { useGridCellEditing } from "./useGridCellEditing.mjs";
@@ -472,7 +472,7 @@ const useGridRowEditing = (apiRef, props) => {
472
472
  if (onProcessRowUpdateError) {
473
473
  onProcessRowUpdateError(errorThrown);
474
474
  } else if (process.env.NODE_ENV !== 'production') {
475
- (0, _warning.warnOnce)(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
475
+ (0, _warning.errorOnce)(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'].join('\n'));
476
476
  }
477
477
  };
478
478
  try {
@@ -1,15 +1,15 @@
1
1
  'use client';
2
2
 
3
- import _toPropertyKey from "@babel/runtime/helpers/esm/toPropertyKey";
4
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import _toPropertyKey from "@babel/runtime/helpers/toPropertyKey";
4
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
5
+ import _extends from "@babel/runtime/helpers/extends";
6
6
  import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
7
7
  const _excluded = ["id"],
8
8
  _excluded2 = ["id"];
9
9
  import * as React from 'react';
10
10
  import useEventCallback from '@mui/utils/useEventCallback';
11
11
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
12
- import { warnOnce } from '@mui/x-internals/warning';
12
+ import { errorOnce } from '@mui/x-internals/warning';
13
13
  import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
14
14
  import { useGridEvent, useGridEventPriority } from "../../utils/useGridEvent.mjs";
15
15
  import { GridEditModes, GridRowModes } from "../../../models/gridEditRowModel.mjs";
@@ -465,7 +465,7 @@ export const useGridRowEditing = (apiRef, props) => {
465
465
  if (onProcessRowUpdateError) {
466
466
  onProcessRowUpdateError(errorThrown);
467
467
  } else if (process.env.NODE_ENV !== 'production') {
468
- warnOnce(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
468
+ errorOnce(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'].join('\n'));
469
469
  }
470
470
  };
471
471
  try {
@@ -86,7 +86,7 @@ const serializeRow = ({
86
86
  const cellParams = getCellParams(id, column.field);
87
87
  if (String(cellParams.formattedValue) === '[object Object]') {
88
88
  if (process.env.NODE_ENV !== 'production') {
89
- (0, _warning.warnOnce)(['MUI X: When the value of a field is an object or a `renderCell` is provided, the CSV export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.']);
89
+ (0, _warning.warnOnce)(['MUI X: When the value of a field is an object or a `renderCell` is provided, the CSV export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.'].join('\n'));
90
90
  }
91
91
  }
92
92
  row.addValue(serializeCellValue(cellParams, {
@@ -104,13 +104,13 @@ function buildCSV(options) {
104
104
  ignoreValueFormatter,
105
105
  apiRef
106
106
  } = options;
107
- const CSVBody = rowIds.reduce((acc, id) => `${acc}${serializeRow({
107
+ const CSVBody = rowIds.map(id => serializeRow({
108
108
  id,
109
109
  columns,
110
110
  getCellParams: apiRef.current.getCellParams,
111
111
  ignoreValueFormatter,
112
112
  csvOptions
113
- })}\r\n`, '').trim();
113
+ })).join('\r\n');
114
114
  if (!csvOptions.includeHeaders) {
115
115
  return CSVBody;
116
116
  }
@@ -146,6 +146,6 @@ function buildCSV(options) {
146
146
  mainHeaderRow.addValue(column.headerName || column.field);
147
147
  });
148
148
  headerRows.push(mainHeaderRow);
149
- const CSVHead = `${headerRows.map(row => row.getRowString()).join('\r\n')}\r\n`;
150
- return `${CSVHead}${CSVBody}`.trim();
149
+ const CSVHead = headerRows.map(row => row.getRowString()).join('\r\n');
150
+ return rowIds.length > 0 ? `${CSVHead}\r\n${CSVBody}` : CSVHead;
151
151
  }
@@ -78,7 +78,7 @@ const serializeRow = ({
78
78
  const cellParams = getCellParams(id, column.field);
79
79
  if (String(cellParams.formattedValue) === '[object Object]') {
80
80
  if (process.env.NODE_ENV !== 'production') {
81
- warnOnce(['MUI X: When the value of a field is an object or a `renderCell` is provided, the CSV export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.']);
81
+ warnOnce(['MUI X: When the value of a field is an object or a `renderCell` is provided, the CSV export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.'].join('\n'));
82
82
  }
83
83
  }
84
84
  row.addValue(serializeCellValue(cellParams, {
@@ -96,13 +96,13 @@ export function buildCSV(options) {
96
96
  ignoreValueFormatter,
97
97
  apiRef
98
98
  } = options;
99
- const CSVBody = rowIds.reduce((acc, id) => `${acc}${serializeRow({
99
+ const CSVBody = rowIds.map(id => serializeRow({
100
100
  id,
101
101
  columns,
102
102
  getCellParams: apiRef.current.getCellParams,
103
103
  ignoreValueFormatter,
104
104
  csvOptions
105
- })}\r\n`, '').trim();
105
+ })).join('\r\n');
106
106
  if (!csvOptions.includeHeaders) {
107
107
  return CSVBody;
108
108
  }
@@ -138,6 +138,6 @@ export function buildCSV(options) {
138
138
  mainHeaderRow.addValue(column.headerName || column.field);
139
139
  });
140
140
  headerRows.push(mainHeaderRow);
141
- const CSVHead = `${headerRows.map(row => row.getRowString()).join('\r\n')}\r\n`;
142
- return `${CSVHead}${CSVBody}`.trim();
141
+ const CSVHead = headerRows.map(row => row.getRowString()).join('\r\n');
142
+ return rowIds.length > 0 ? `${CSVHead}\r\n${CSVBody}` : CSVHead;
143
143
  }
@@ -98,7 +98,7 @@ const useGridPrintExport = (apiRef, props) => {
98
98
  }, []);
99
99
  apiRef.current.setRows(newRows);
100
100
  }, [apiRef]);
101
- const handlePrintWindowLoad = React.useCallback((printWindow, options) => {
101
+ const handlePrintWindowLoad = React.useCallback(async (printWindow, options) => {
102
102
  const normalizeOptions = (0, _extends2.default)({
103
103
  copyStyles: true,
104
104
  hideToolbar: false,
@@ -107,7 +107,7 @@ const useGridPrintExport = (apiRef, props) => {
107
107
  }, options);
108
108
  const printDoc = printWindow.contentDocument;
109
109
  if (!printDoc) {
110
- return;
110
+ return false;
111
111
  }
112
112
  const gridRootElement = apiRef.current.rootElementRef.current;
113
113
  const gridClone = gridRootElement.cloneNode(true);
@@ -136,6 +136,8 @@ const useGridPrintExport = (apiRef, props) => {
136
136
  gridFooterElement.remove();
137
137
  }
138
138
  gridClone.style.height = 'auto';
139
+ gridClone.style.minHeight = '0';
140
+ gridClone.style.maxHeight = 'none';
139
141
  // The height above does not include grid border width, so we need to exclude it
140
142
  gridClone.style.boxSizing = 'content-box';
141
143
  if (!normalizeOptions.hideFooter && gridFooterElement) {
@@ -166,16 +168,23 @@ const useGridPrintExport = (apiRef, props) => {
166
168
  if (normalizeOptions.copyStyles) {
167
169
  const rootCandidate = gridRootElement.getRootNode();
168
170
  const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc.current;
169
- stylesheetLoadPromises = (0, _export.loadStyleSheets)(printDoc, root);
171
+ stylesheetLoadPromises = (0, _export.loadStyleSheets)(printDoc, root, {
172
+ onStylesheetError: normalizeOptions.onStylesheetError
173
+ });
174
+ }
175
+
176
+ // wait for remote stylesheets to load
177
+ const loaded = await Promise.all(stylesheetLoadPromises);
178
+ if (loaded.includes(false)) {
179
+ // `onStylesheetError` cancelled the print
180
+ return false;
170
181
  }
171
182
 
172
183
  // Trigger print
173
184
  if (process.env.NODE_ENV !== 'test' && !DEBUG_MODE) {
174
- // wait for remote stylesheets to load
175
- Promise.all(stylesheetLoadPromises).then(() => {
176
- printWindow.contentWindow.print();
177
- });
185
+ printWindow.contentWindow.print();
178
186
  }
187
+ return true;
179
188
  }, [apiRef, doc]);
180
189
  const handlePrintWindowAfterPrint = React.useCallback(printWindow => {
181
190
  // Remove the print iframe
@@ -228,21 +237,36 @@ const useGridPrintExport = (apiRef, props) => {
228
237
  const printWindow = buildPrintWindow(options?.fileName);
229
238
  if (process.env.NODE_ENV === 'test') {
230
239
  doc.current.body.appendChild(printWindow);
231
- // In test env, run the all pipeline without waiting for loading
232
- handlePrintWindowLoad(printWindow, options);
233
- handlePrintWindowAfterPrint(printWindow);
240
+ // In test env, run the all pipeline without waiting for the iframe to load or the print dialog
241
+ try {
242
+ await handlePrintWindowLoad(printWindow, options);
243
+ } finally {
244
+ handlePrintWindowAfterPrint(printWindow);
245
+ }
234
246
  } else {
235
- printWindow.onload = () => {
236
- handlePrintWindowLoad(printWindow, options);
237
- const mediaQueryList = printWindow.contentWindow.matchMedia('print');
238
- mediaQueryList.addEventListener('change', mql => {
239
- const isAfterPrint = mql.matches === false;
240
- if (isAfterPrint) {
247
+ await new Promise((resolve, reject) => {
248
+ printWindow.onload = () => {
249
+ const mediaQueryList = printWindow.contentWindow.matchMedia('print');
250
+ mediaQueryList.addEventListener('change', mql => {
251
+ const isAfterPrint = mql.matches === false;
252
+ if (isAfterPrint) {
253
+ handlePrintWindowAfterPrint(printWindow);
254
+ }
255
+ });
256
+ handlePrintWindowLoad(printWindow, options).then(printed => {
257
+ if (!printed) {
258
+ // The print dialog never opens, so restore the grid here
259
+ handlePrintWindowAfterPrint(printWindow);
260
+ }
261
+ resolve();
262
+ }, error => {
263
+ // The print dialog never opens, so restore the grid here
241
264
  handlePrintWindowAfterPrint(printWindow);
242
- }
243
- });
244
- };
245
- doc.current.body.appendChild(printWindow);
265
+ reject(error);
266
+ });
267
+ };
268
+ doc.current.body.appendChild(printWindow);
269
+ });
246
270
  }
247
271
  }, [props, logger, apiRef, handlePrintWindowLoad, handlePrintWindowAfterPrint, updateGridColumnsForPrint, updateGridRowsForPrint]);
248
272
  const printExportApi = {