@mui/x-data-grid-generator 8.0.0-alpha.1 → 8.0.0-alpha.10

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.
@@ -1,6 +1,7 @@
1
- import { GridRowModel, GridFilterModel, GridSortModel, GridColDef, GridRowId, GridPaginationModel, GridValidRowModel } from '@mui/x-data-grid-pro';
1
+ import { GridRowModel, GridFilterModel, GridSortModel, GridColDef, GridRowId, GridPaginationModel, GridValidRowModel, GridAggregationModel } from '@mui/x-data-grid-premium';
2
2
  export interface FakeServerResponse {
3
3
  returnedRows: GridRowModel[];
4
+ aggregateRow?: GridValidRowModel;
4
5
  nextCursor?: string;
5
6
  hasNextPage?: boolean;
6
7
  totalRowCount: number;
@@ -22,9 +23,10 @@ export interface QueryOptions {
22
23
  page?: number;
23
24
  pageSize?: number;
24
25
  filterModel?: GridFilterModel;
26
+ aggregationModel?: GridAggregationModel;
25
27
  sortModel?: GridSortModel;
26
- firstRowToRender?: number;
27
- lastRowToRender?: number;
28
+ start?: number;
29
+ end?: number;
28
30
  }
29
31
  export interface ServerSideQueryOptions {
30
32
  cursor?: GridRowId;
@@ -32,8 +34,9 @@ export interface ServerSideQueryOptions {
32
34
  groupKeys?: string[];
33
35
  filterModel?: GridFilterModel;
34
36
  sortModel?: GridSortModel;
35
- firstRowToRender?: number;
36
- lastRowToRender?: number;
37
+ aggregationModel?: GridAggregationModel;
38
+ start?: number;
39
+ end?: number;
37
40
  groupFields?: string[];
38
41
  }
39
42
  export declare const disableDelay: any;
@@ -45,6 +48,7 @@ export declare const loadServerRows: (rows: GridRowModel[], queryOptions: QueryO
45
48
  interface NestedDataRowsResponse {
46
49
  rows: GridRowModel[];
47
50
  rootRowCount: number;
51
+ aggregateRow?: GridRowModel;
48
52
  }
49
53
  /**
50
54
  * Simulates server data for tree-data feature
@@ -1,6 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { GridLogicOperator } from '@mui/x-data-grid-pro';
2
+ import { GridLogicOperator, GRID_AGGREGATION_FUNCTIONS } from '@mui/x-data-grid-premium';
3
3
  import { randomInt } from "../services/random-generator.js";
4
+ const getAvailableAggregationFunctions = columnType => {
5
+ const availableAggregationFunctions = new Map();
6
+ Object.keys(GRID_AGGREGATION_FUNCTIONS).forEach(functionName => {
7
+ const columnTypes = GRID_AGGREGATION_FUNCTIONS[functionName].columnTypes;
8
+ if (!columnTypes || columnTypes.includes(columnType ?? 'string')) {
9
+ availableAggregationFunctions.set(functionName, GRID_AGGREGATION_FUNCTIONS[functionName]);
10
+ }
11
+ });
12
+ return availableAggregationFunctions;
13
+ };
4
14
  export const disableDelay = typeof DISABLE_CHANCE_RANDOM !== 'undefined' && DISABLE_CHANCE_RANDOM;
5
15
  export const DEFAULT_SERVER_OPTIONS = {
6
16
  minDelay: disableDelay ? 0 : 100,
@@ -155,6 +165,36 @@ const getFilteredRows = (rows, filterModel, columnsWithDefaultColDef) => {
155
165
  return filterFunctions[index] === null ? true : filterFunctions[index](value);
156
166
  }));
157
167
  };
168
+ const applyAggregation = (aggregationModel, colDefs, rows, groupId = 'root') => {
169
+ const columnsToAggregate = Object.keys(aggregationModel);
170
+ if (columnsToAggregate.length === 0) {
171
+ return {};
172
+ }
173
+ const aggregateValues = {};
174
+ columnsToAggregate.forEach(field => {
175
+ const type = colDefs.find(({
176
+ field: f
177
+ }) => f === field)?.type;
178
+ if (!type) {
179
+ return;
180
+ }
181
+ const availableAggregationFunctions = getAvailableAggregationFunctions(type);
182
+ if (!availableAggregationFunctions.has(aggregationModel[field])) {
183
+ return;
184
+ }
185
+ const aggregationFunction = availableAggregationFunctions.get(aggregationModel[field]);
186
+ if (!aggregationFunction) {
187
+ return;
188
+ }
189
+ const values = rows.map(row => row[field]);
190
+ aggregateValues[`${field}Aggregate`] = aggregationFunction.apply({
191
+ values,
192
+ field,
193
+ groupId
194
+ });
195
+ });
196
+ return aggregateValues;
197
+ };
158
198
 
159
199
  /**
160
200
  * Simulates server data loading
@@ -172,7 +212,9 @@ export const loadServerRows = (rows, queryOptions, serverOptions, columnsWithDef
172
212
  const {
173
213
  cursor,
174
214
  page = 0,
175
- pageSize
215
+ pageSize,
216
+ start,
217
+ end
176
218
  } = queryOptions;
177
219
  let nextCursor;
178
220
  let firstRowIndex;
@@ -180,28 +222,37 @@ export const loadServerRows = (rows, queryOptions, serverOptions, columnsWithDef
180
222
  let filteredRows = getFilteredRows(rows, queryOptions.filterModel, columnsWithDefaultColDef);
181
223
  const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
182
224
  filteredRows = [...filteredRows].sort(rowComparator);
225
+ let aggregateRow = {};
226
+ if (queryOptions.aggregationModel) {
227
+ aggregateRow = applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, filteredRows);
228
+ }
183
229
  const totalRowCount = filteredRows.length;
184
- if (!pageSize) {
230
+ if (start !== undefined && end !== undefined) {
231
+ firstRowIndex = start;
232
+ lastRowIndex = end;
233
+ } else if (!pageSize) {
185
234
  firstRowIndex = 0;
186
- lastRowIndex = filteredRows.length;
235
+ lastRowIndex = filteredRows.length - 1;
187
236
  } else if (useCursorPagination) {
188
237
  firstRowIndex = cursor ? filteredRows.findIndex(({
189
238
  id
190
239
  }) => id === cursor) : 0;
191
240
  firstRowIndex = Math.max(firstRowIndex, 0); // if cursor not found return 0
192
- lastRowIndex = firstRowIndex + pageSize;
193
- nextCursor = lastRowIndex >= filteredRows.length ? undefined : filteredRows[lastRowIndex].id;
241
+ lastRowIndex = firstRowIndex + pageSize - 1;
242
+ nextCursor = filteredRows[lastRowIndex + 1]?.id;
194
243
  } else {
195
244
  firstRowIndex = page * pageSize;
196
- lastRowIndex = (page + 1) * pageSize;
245
+ lastRowIndex = (page + 1) * pageSize - 1;
197
246
  }
198
247
  const hasNextPage = lastRowIndex < filteredRows.length - 1;
199
- const response = {
200
- returnedRows: filteredRows.slice(firstRowIndex, lastRowIndex),
248
+ const response = _extends({
249
+ returnedRows: filteredRows.slice(firstRowIndex, lastRowIndex + 1),
201
250
  hasNextPage,
202
251
  nextCursor,
203
252
  totalRowCount
204
- };
253
+ }, queryOptions.aggregationModel ? {
254
+ aggregateRow
255
+ } : {});
205
256
  return new Promise(resolve => {
206
257
  setTimeout(() => {
207
258
  resolve(response);
@@ -311,6 +362,12 @@ export const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWi
311
362
  let childRowsWithDescendantCounts = childRows.map(row => {
312
363
  const descendants = findTreeDataRowChildren(filteredRows, row[pathKey], pathKey, -1);
313
364
  const descendantCount = descendants.length;
365
+ if (descendantCount > 0 && queryOptions.aggregationModel) {
366
+ // Parent row, compute aggregation
367
+ return _extends({}, row, {
368
+ descendantCount
369
+ }, applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, descendants, row.id));
370
+ }
314
371
  return _extends({}, row, {
315
372
  descendantCount
316
373
  });
@@ -320,6 +377,10 @@ export const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWi
320
377
  const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
321
378
  childRowsWithDescendantCounts = [...childRowsWithDescendantCounts].sort(rowComparator);
322
379
  }
380
+ let aggregateRow;
381
+ if (queryOptions.aggregationModel) {
382
+ aggregateRow = applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, filteredRows);
383
+ }
323
384
  if (queryOptions.paginationModel && queryOptions.groupKeys.length === 0) {
324
385
  // Only paginate root rows, grid should refetch root rows when `paginationModel` updates
325
386
  const {
@@ -334,7 +395,8 @@ export const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWi
334
395
  setTimeout(() => {
335
396
  resolve({
336
397
  rows: childRowsWithDescendantCounts,
337
- rootRowCount
398
+ rootRowCount,
399
+ aggregateRow
338
400
  });
339
401
  }, delay); // simulate network latency
340
402
  });
@@ -423,6 +485,12 @@ export const processRowGroupingRows = (rows, queryOptions, serverOptions, column
423
485
  id
424
486
  }) => typeof id !== 'string' || !id.startsWith('auto-generated-parent-'));
425
487
  const descendantCount = descendants.length;
488
+ if (descendantCount > 0 && queryOptions.aggregationModel) {
489
+ // Parent row, compute aggregation
490
+ return _extends({}, row, {
491
+ descendantCount
492
+ }, applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, descendants, row.id));
493
+ }
426
494
  return _extends({}, row, {
427
495
  descendantCount
428
496
  });
@@ -433,6 +501,10 @@ export const processRowGroupingRows = (rows, queryOptions, serverOptions, column
433
501
  const sortedChildRows = [...childRowsWithDescendantCounts].sort(rowComparator);
434
502
  childRowsWithDescendantCounts = [...sortedMissingGroups, ...sortedChildRows];
435
503
  }
504
+ let aggregateRow;
505
+ if (queryOptions.aggregationModel) {
506
+ aggregateRow = applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, filteredRows);
507
+ }
436
508
  if (queryOptions.paginationModel && queryOptions.groupKeys.length === 0) {
437
509
  // Only paginate root rows, grid should refetch root rows when `paginationModel` updates
438
510
  const {
@@ -447,7 +519,8 @@ export const processRowGroupingRows = (rows, queryOptions, serverOptions, column
447
519
  setTimeout(() => {
448
520
  resolve({
449
521
  rows: childRowsWithDescendantCounts,
450
- rootRowCount
522
+ rootRowCount,
523
+ aggregateRow
451
524
  });
452
525
  }, delay); // simulate network latency
453
526
  });
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import _extends from "@babel/runtime/helpers/esm/extends";
2
4
  import * as React from 'react';
3
5
  import { LRUCache } from 'lru-cache';
@@ -1,4 +1,4 @@
1
- import { GridRowModel, GridGetRowsResponse, GridColDef, GridInitialState } from '@mui/x-data-grid-pro';
1
+ import { GridRowModel, GridGetRowsResponse, GridColDef, GridInitialState } from '@mui/x-data-grid-premium';
2
2
  import { AddPathToDemoDataOptions } from '../services/tree-data-generator';
3
3
  import type { ServerOptions } from './serverUtils';
4
4
  export declare const BASE_URL = "https://mui.com/x/api/data-grid";
@@ -9,6 +9,7 @@ type UseMockServerResponse = {
9
9
  getChildrenCount?: (row: GridRowModel) => number;
10
10
  fetchRows: (url: string) => Promise<GridGetRowsResponse>;
11
11
  loadNewData: () => void;
12
+ isReady: boolean;
12
13
  };
13
14
  type DataSet = 'Commodity' | 'Employee' | 'Movies';
14
15
  interface UseMockServerOptions {
@@ -1,7 +1,9 @@
1
+ 'use client';
2
+
1
3
  import _extends from "@babel/runtime/helpers/esm/extends";
2
4
  import * as React from 'react';
3
5
  import { LRUCache } from 'lru-cache';
4
- import { getGridDefaultColumnTypes } from '@mui/x-data-grid-pro';
6
+ import { getGridDefaultColumnTypes } from '@mui/x-data-grid-premium';
5
7
  import { extrapolateSeed, deepFreeze } from "./useDemoData.js";
6
8
  import { getCommodityColumns } from "../columns/commodities.columns.js";
7
9
  import { getEmployeeColumns } from "../columns/employees.columns.js";
@@ -200,38 +202,47 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
200
202
  if (isTreeData) {
201
203
  const {
202
204
  rows,
203
- rootRowCount
205
+ rootRowCount,
206
+ aggregateRow
204
207
  } = await processTreeDataRows(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
205
- getRowsResponse = {
208
+ getRowsResponse = _extends({
206
209
  rows: rows.slice().map(row => _extends({}, row, {
207
210
  path: undefined
208
211
  })),
209
212
  rowCount: rootRowCount
210
- };
213
+ }, aggregateRow ? {
214
+ aggregateRow
215
+ } : {});
211
216
  } else if (isRowGrouping) {
212
217
  const {
213
218
  rows,
214
- rootRowCount
219
+ rootRowCount,
220
+ aggregateRow
215
221
  } = await processRowGroupingRows(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
216
- getRowsResponse = {
222
+ getRowsResponse = _extends({
217
223
  rows: rows.slice().map(row => _extends({}, row, {
218
224
  path: undefined
219
225
  })),
220
226
  rowCount: rootRowCount
221
- };
227
+ }, aggregateRow ? {
228
+ aggregateRow
229
+ } : {});
222
230
  } else {
223
231
  const {
224
232
  returnedRows,
225
233
  nextCursor,
226
- totalRowCount
234
+ totalRowCount,
235
+ aggregateRow
227
236
  } = await loadServerRows(data?.rows ?? [], _extends({}, params, params.paginationModel), serverOptionsWithDefault, columnsWithDefaultColDef);
228
- getRowsResponse = {
237
+ getRowsResponse = _extends({
229
238
  rows: returnedRows,
230
239
  rowCount: totalRowCount,
231
240
  pageInfo: {
232
241
  nextCursor
233
242
  }
234
- };
243
+ }, aggregateRow ? {
244
+ aggregateRow
245
+ } : {});
235
246
  }
236
247
  return new Promise(resolve => {
237
248
  if (verbose) {
@@ -248,6 +259,7 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
248
259
  fetchRows,
249
260
  loadNewData: () => {
250
261
  setIndex(oldIndex => oldIndex + 1);
251
- }
262
+ },
263
+ isReady: Boolean(data?.rows?.length)
252
264
  };
253
265
  };
@@ -39,7 +39,7 @@ export declare const createFakeServer: (dataSetOptions?: Partial<UseDemoDataOpti
39
39
  hideSortIcons?: boolean;
40
40
  disableColumnMenu?: boolean;
41
41
  filterable?: boolean;
42
- filterOperators?: readonly import("@mui/x-data-grid").GridFilterOperator<any, any, any>[] | undefined;
42
+ filterOperators?: readonly import("@mui/x-data-grid").GridFilterOperator<any, any, any, any>[] | undefined;
43
43
  getApplyQuickFilterFn?: import("@mui/x-data-grid").GetApplyQuickFilterFn<any, any> | undefined;
44
44
  disableReorder?: boolean;
45
45
  disableExport?: boolean;
@@ -89,7 +89,7 @@ export declare const createFakeServer: (dataSetOptions?: Partial<UseDemoDataOpti
89
89
  hideSortIcons?: boolean;
90
90
  disableColumnMenu?: boolean;
91
91
  filterable?: boolean;
92
- filterOperators?: readonly import("@mui/x-data-grid").GridFilterOperator<any, any, any>[] | undefined;
92
+ filterOperators?: readonly import("@mui/x-data-grid").GridFilterOperator<any, any, any, any>[] | undefined;
93
93
  getApplyQuickFilterFn?: import("@mui/x-data-grid").GetApplyQuickFilterFn<any, any> | undefined;
94
94
  disableReorder?: boolean;
95
95
  disableExport?: boolean;
@@ -141,7 +141,7 @@ export declare const createFakeServer: (dataSetOptions?: Partial<UseDemoDataOpti
141
141
  hideSortIcons?: boolean;
142
142
  disableColumnMenu?: boolean;
143
143
  filterable?: boolean;
144
- filterOperators?: readonly import("@mui/x-data-grid").GridFilterOperator<any, any, any>[] | undefined;
144
+ filterOperators?: readonly import("@mui/x-data-grid").GridFilterOperator<any, any, any, any>[] | undefined;
145
145
  getApplyQuickFilterFn?: import("@mui/x-data-grid").GetApplyQuickFilterFn<any, any> | undefined;
146
146
  disableReorder?: boolean;
147
147
  disableExport?: boolean;
package/hooks/useQuery.js CHANGED
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import _extends from "@babel/runtime/helpers/esm/extends";
2
4
  import * as React from 'react';
3
5
  import { getGridDefaultColumnTypes } from '@mui/x-data-grid-pro';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid-generator v8.0.0-alpha.1
2
+ * @mui/x-data-grid-generator v8.0.0-alpha.10
3
3
  *
4
4
  * @license MUI X Commercial
5
5
  * This source code is licensed under the commercial license found in the
@@ -1,6 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { GridLogicOperator } from '@mui/x-data-grid-pro';
2
+ import { GridLogicOperator, GRID_AGGREGATION_FUNCTIONS } from '@mui/x-data-grid-premium';
3
3
  import { randomInt } from "../services/random-generator.js";
4
+ const getAvailableAggregationFunctions = columnType => {
5
+ const availableAggregationFunctions = new Map();
6
+ Object.keys(GRID_AGGREGATION_FUNCTIONS).forEach(functionName => {
7
+ const columnTypes = GRID_AGGREGATION_FUNCTIONS[functionName].columnTypes;
8
+ if (!columnTypes || columnTypes.includes(columnType ?? 'string')) {
9
+ availableAggregationFunctions.set(functionName, GRID_AGGREGATION_FUNCTIONS[functionName]);
10
+ }
11
+ });
12
+ return availableAggregationFunctions;
13
+ };
4
14
  export const disableDelay = typeof DISABLE_CHANCE_RANDOM !== 'undefined' && DISABLE_CHANCE_RANDOM;
5
15
  export const DEFAULT_SERVER_OPTIONS = {
6
16
  minDelay: disableDelay ? 0 : 100,
@@ -155,6 +165,36 @@ const getFilteredRows = (rows, filterModel, columnsWithDefaultColDef) => {
155
165
  return filterFunctions[index] === null ? true : filterFunctions[index](value);
156
166
  }));
157
167
  };
168
+ const applyAggregation = (aggregationModel, colDefs, rows, groupId = 'root') => {
169
+ const columnsToAggregate = Object.keys(aggregationModel);
170
+ if (columnsToAggregate.length === 0) {
171
+ return {};
172
+ }
173
+ const aggregateValues = {};
174
+ columnsToAggregate.forEach(field => {
175
+ const type = colDefs.find(({
176
+ field: f
177
+ }) => f === field)?.type;
178
+ if (!type) {
179
+ return;
180
+ }
181
+ const availableAggregationFunctions = getAvailableAggregationFunctions(type);
182
+ if (!availableAggregationFunctions.has(aggregationModel[field])) {
183
+ return;
184
+ }
185
+ const aggregationFunction = availableAggregationFunctions.get(aggregationModel[field]);
186
+ if (!aggregationFunction) {
187
+ return;
188
+ }
189
+ const values = rows.map(row => row[field]);
190
+ aggregateValues[`${field}Aggregate`] = aggregationFunction.apply({
191
+ values,
192
+ field,
193
+ groupId
194
+ });
195
+ });
196
+ return aggregateValues;
197
+ };
158
198
 
159
199
  /**
160
200
  * Simulates server data loading
@@ -172,7 +212,9 @@ export const loadServerRows = (rows, queryOptions, serverOptions, columnsWithDef
172
212
  const {
173
213
  cursor,
174
214
  page = 0,
175
- pageSize
215
+ pageSize,
216
+ start,
217
+ end
176
218
  } = queryOptions;
177
219
  let nextCursor;
178
220
  let firstRowIndex;
@@ -180,28 +222,37 @@ export const loadServerRows = (rows, queryOptions, serverOptions, columnsWithDef
180
222
  let filteredRows = getFilteredRows(rows, queryOptions.filterModel, columnsWithDefaultColDef);
181
223
  const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
182
224
  filteredRows = [...filteredRows].sort(rowComparator);
225
+ let aggregateRow = {};
226
+ if (queryOptions.aggregationModel) {
227
+ aggregateRow = applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, filteredRows);
228
+ }
183
229
  const totalRowCount = filteredRows.length;
184
- if (!pageSize) {
230
+ if (start !== undefined && end !== undefined) {
231
+ firstRowIndex = start;
232
+ lastRowIndex = end;
233
+ } else if (!pageSize) {
185
234
  firstRowIndex = 0;
186
- lastRowIndex = filteredRows.length;
235
+ lastRowIndex = filteredRows.length - 1;
187
236
  } else if (useCursorPagination) {
188
237
  firstRowIndex = cursor ? filteredRows.findIndex(({
189
238
  id
190
239
  }) => id === cursor) : 0;
191
240
  firstRowIndex = Math.max(firstRowIndex, 0); // if cursor not found return 0
192
- lastRowIndex = firstRowIndex + pageSize;
193
- nextCursor = lastRowIndex >= filteredRows.length ? undefined : filteredRows[lastRowIndex].id;
241
+ lastRowIndex = firstRowIndex + pageSize - 1;
242
+ nextCursor = filteredRows[lastRowIndex + 1]?.id;
194
243
  } else {
195
244
  firstRowIndex = page * pageSize;
196
- lastRowIndex = (page + 1) * pageSize;
245
+ lastRowIndex = (page + 1) * pageSize - 1;
197
246
  }
198
247
  const hasNextPage = lastRowIndex < filteredRows.length - 1;
199
- const response = {
200
- returnedRows: filteredRows.slice(firstRowIndex, lastRowIndex),
248
+ const response = _extends({
249
+ returnedRows: filteredRows.slice(firstRowIndex, lastRowIndex + 1),
201
250
  hasNextPage,
202
251
  nextCursor,
203
252
  totalRowCount
204
- };
253
+ }, queryOptions.aggregationModel ? {
254
+ aggregateRow
255
+ } : {});
205
256
  return new Promise(resolve => {
206
257
  setTimeout(() => {
207
258
  resolve(response);
@@ -311,6 +362,12 @@ export const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWi
311
362
  let childRowsWithDescendantCounts = childRows.map(row => {
312
363
  const descendants = findTreeDataRowChildren(filteredRows, row[pathKey], pathKey, -1);
313
364
  const descendantCount = descendants.length;
365
+ if (descendantCount > 0 && queryOptions.aggregationModel) {
366
+ // Parent row, compute aggregation
367
+ return _extends({}, row, {
368
+ descendantCount
369
+ }, applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, descendants, row.id));
370
+ }
314
371
  return _extends({}, row, {
315
372
  descendantCount
316
373
  });
@@ -320,6 +377,10 @@ export const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWi
320
377
  const rowComparator = getRowComparator(queryOptions.sortModel, columnsWithDefaultColDef);
321
378
  childRowsWithDescendantCounts = [...childRowsWithDescendantCounts].sort(rowComparator);
322
379
  }
380
+ let aggregateRow;
381
+ if (queryOptions.aggregationModel) {
382
+ aggregateRow = applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, filteredRows);
383
+ }
323
384
  if (queryOptions.paginationModel && queryOptions.groupKeys.length === 0) {
324
385
  // Only paginate root rows, grid should refetch root rows when `paginationModel` updates
325
386
  const {
@@ -334,7 +395,8 @@ export const processTreeDataRows = (rows, queryOptions, serverOptions, columnsWi
334
395
  setTimeout(() => {
335
396
  resolve({
336
397
  rows: childRowsWithDescendantCounts,
337
- rootRowCount
398
+ rootRowCount,
399
+ aggregateRow
338
400
  });
339
401
  }, delay); // simulate network latency
340
402
  });
@@ -423,6 +485,12 @@ export const processRowGroupingRows = (rows, queryOptions, serverOptions, column
423
485
  id
424
486
  }) => typeof id !== 'string' || !id.startsWith('auto-generated-parent-'));
425
487
  const descendantCount = descendants.length;
488
+ if (descendantCount > 0 && queryOptions.aggregationModel) {
489
+ // Parent row, compute aggregation
490
+ return _extends({}, row, {
491
+ descendantCount
492
+ }, applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, descendants, row.id));
493
+ }
426
494
  return _extends({}, row, {
427
495
  descendantCount
428
496
  });
@@ -433,6 +501,10 @@ export const processRowGroupingRows = (rows, queryOptions, serverOptions, column
433
501
  const sortedChildRows = [...childRowsWithDescendantCounts].sort(rowComparator);
434
502
  childRowsWithDescendantCounts = [...sortedMissingGroups, ...sortedChildRows];
435
503
  }
504
+ let aggregateRow;
505
+ if (queryOptions.aggregationModel) {
506
+ aggregateRow = applyAggregation(queryOptions.aggregationModel, columnsWithDefaultColDef, filteredRows);
507
+ }
436
508
  if (queryOptions.paginationModel && queryOptions.groupKeys.length === 0) {
437
509
  // Only paginate root rows, grid should refetch root rows when `paginationModel` updates
438
510
  const {
@@ -447,7 +519,8 @@ export const processRowGroupingRows = (rows, queryOptions, serverOptions, column
447
519
  setTimeout(() => {
448
520
  resolve({
449
521
  rows: childRowsWithDescendantCounts,
450
- rootRowCount
522
+ rootRowCount,
523
+ aggregateRow
451
524
  });
452
525
  }, delay); // simulate network latency
453
526
  });
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import _extends from "@babel/runtime/helpers/esm/extends";
2
4
  import * as React from 'react';
3
5
  import { LRUCache } from 'lru-cache';
@@ -1,7 +1,9 @@
1
+ 'use client';
2
+
1
3
  import _extends from "@babel/runtime/helpers/esm/extends";
2
4
  import * as React from 'react';
3
5
  import { LRUCache } from 'lru-cache';
4
- import { getGridDefaultColumnTypes } from '@mui/x-data-grid-pro';
6
+ import { getGridDefaultColumnTypes } from '@mui/x-data-grid-premium';
5
7
  import { extrapolateSeed, deepFreeze } from "./useDemoData.js";
6
8
  import { getCommodityColumns } from "../columns/commodities.columns.js";
7
9
  import { getEmployeeColumns } from "../columns/employees.columns.js";
@@ -200,38 +202,47 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
200
202
  if (isTreeData) {
201
203
  const {
202
204
  rows,
203
- rootRowCount
205
+ rootRowCount,
206
+ aggregateRow
204
207
  } = await processTreeDataRows(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
205
- getRowsResponse = {
208
+ getRowsResponse = _extends({
206
209
  rows: rows.slice().map(row => _extends({}, row, {
207
210
  path: undefined
208
211
  })),
209
212
  rowCount: rootRowCount
210
- };
213
+ }, aggregateRow ? {
214
+ aggregateRow
215
+ } : {});
211
216
  } else if (isRowGrouping) {
212
217
  const {
213
218
  rows,
214
- rootRowCount
219
+ rootRowCount,
220
+ aggregateRow
215
221
  } = await processRowGroupingRows(data?.rows ?? [], params, serverOptionsWithDefault, columnsWithDefaultColDef);
216
- getRowsResponse = {
222
+ getRowsResponse = _extends({
217
223
  rows: rows.slice().map(row => _extends({}, row, {
218
224
  path: undefined
219
225
  })),
220
226
  rowCount: rootRowCount
221
- };
227
+ }, aggregateRow ? {
228
+ aggregateRow
229
+ } : {});
222
230
  } else {
223
231
  const {
224
232
  returnedRows,
225
233
  nextCursor,
226
- totalRowCount
234
+ totalRowCount,
235
+ aggregateRow
227
236
  } = await loadServerRows(data?.rows ?? [], _extends({}, params, params.paginationModel), serverOptionsWithDefault, columnsWithDefaultColDef);
228
- getRowsResponse = {
237
+ getRowsResponse = _extends({
229
238
  rows: returnedRows,
230
239
  rowCount: totalRowCount,
231
240
  pageInfo: {
232
241
  nextCursor
233
242
  }
234
- };
243
+ }, aggregateRow ? {
244
+ aggregateRow
245
+ } : {});
235
246
  }
236
247
  return new Promise(resolve => {
237
248
  if (verbose) {
@@ -248,6 +259,7 @@ export const useMockServer = (dataSetOptions, serverOptions, shouldRequestsFail)
248
259
  fetchRows,
249
260
  loadNewData: () => {
250
261
  setIndex(oldIndex => oldIndex + 1);
251
- }
262
+ },
263
+ isReady: Boolean(data?.rows?.length)
252
264
  };
253
265
  };
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import _extends from "@babel/runtime/helpers/esm/extends";
2
4
  import * as React from 'react';
3
5
  import { getGridDefaultColumnTypes } from '@mui/x-data-grid-pro';
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid-generator v8.0.0-alpha.1
2
+ * @mui/x-data-grid-generator v8.0.0-alpha.10
3
3
  *
4
4
  * @license MUI X Commercial
5
5
  * This source code is licensed under the commercial license found in the
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import _extends from "@babel/runtime/helpers/esm/extends";
2
4
  import * as React from 'react';
3
5
  import clsx from 'clsx';