Skip to content

Commit

Permalink
Remove aggregationRowsScope support
Browse files Browse the repository at this point in the history
  • Loading branch information
MBilalShafi committed Dec 18, 2024
1 parent d3bda4d commit ee6b3c8
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 273 deletions.

This file was deleted.

This file was deleted.

36 changes: 0 additions & 36 deletions docs/data/data-grid/server-side-data/aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,6 @@ The following example demonstrates a basic server-side aggregation.
The data source mock server (`useMockServer()`) mocks the built-in aggregation functions listed in the [built-in functions](/x/react-data-grid/aggregation/#built-in-functions) section of the client-side aggregation. Provide the function names and minimal configuration to demonstrate the aggregation, as shown in the demo.
:::

## Customize the aggregation rows scope

Even though it depends on the business logic on the server, in general, the aggregation is computed for the filtered rows only, as obvious from the default value of the prop `aggregationRowsScope`.

```ts
/**
* Rows used to generate the aggregated value.
* If `filtered`, the aggregated values are generated using only the rows currently passing the filtering process.
* If `all`, the aggregated values are generated using all the rows.
* @default "filtered"
*/
aggregationRowsScope: 'filtered' | 'all';
```

To make it customizable on the server, the Data Grid passes the `aggregationRowsScope` prop to the `getRows` method of `GridDataSource`.
Use it to define the rows used to compute the aggregation.

```tsx
const dataSource = {
getRows: async ({ aggregationRowsScope, ...otherParams }) => {
const response = await fetchRows({
...otherParams,
aggregationRowsScope,
});
return {
rows: response.rows,
rowCount: rows.length,
// The values computed for the aggregation based on the rows scope
aggregateRow: rows.aggregateRow,
};
},
};
```

{{"demo": "ServerSideDataGridAggregationScope.js", "bg": "inline"}}

## Usage with row grouping

Server-side aggregation works with row grouping in a similar way as described in [Aggregation—usage with row grouping](/x/react-data-grid/aggregation/#usage-with-row-grouping). The aggregated values are acquired from the parent rows using the `getAggregatedValue` method.
Expand Down
5 changes: 1 addition & 4 deletions packages/x-data-grid-generator/src/hooks/serverUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export interface QueryOptions {
pageSize?: number;
filterModel?: GridFilterModel;
aggregationModel?: GridAggregationModel;
aggregationRowsScope?: 'all' | 'filtered';
sortModel?: GridSortModel;
start?: number;
end?: number;
Expand All @@ -73,7 +72,6 @@ export interface ServerSideQueryOptions {
filterModel?: GridFilterModel;
sortModel?: GridSortModel;
aggregationModel?: GridAggregationModel;
aggregationRowsScope?: 'all' | 'filtered';
start?: number;
end?: number;
groupFields?: string[];
Expand Down Expand Up @@ -349,11 +347,10 @@ export const loadServerRows = (

let aggregateRow = {};
if (queryOptions.aggregationModel) {
const rowsToAggregate = queryOptions.aggregationRowsScope === 'all' ? rows : filteredRows;
aggregateRow = applyAggregation(
queryOptions.aggregationModel,
columnsWithDefaultColDef,
rowsToAggregate,
filteredRows,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ export const useGridAggregation = (
return {
...params,
aggregationModel: gridAggregationModelSelector(apiRef),
aggregationRowsScope: props.aggregationRowsScope,
};
},
[apiRef, props.aggregationRowsScope],
[apiRef],
);

useGridRegisterPipeProcessor(apiRef, 'getRowsParams', addGetRowsParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface GridGetRowsResponsePremium extends GridGetRowsResponse {

export interface GridGetRowsParamsPremium extends GridGetRowsParams {
aggregationModel?: GridAggregationModel;
aggregationRowsScope?: 'filtered' | 'all';
}

export interface GridDataSourcePremium extends Omit<GridDataSource, 'getRows'> {
Expand Down

0 comments on commit ee6b3c8

Please sign in to comment.