mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
3.91k stars 1.19k forks source link

[data grid] When using Datagrid's aggregation is it possible to somehow use group row's value instead of the aggregated one? #13027

Open gulicJan opened 1 month ago

gulicJan commented 1 month ago

The problem in depth

image

Hey,

is there any way how to avoid the mentioned logic? I'm using aggregation and in some cases I want the group row to skip aggregation and use it's value instead (aggregation was done on the server for some specific cases).

MUI Example:

https://stackblitz.com/run?file=Demo.tsx

How to achieve that the Public grouped row's value 1Kb would be considered as the row's value instead of the aggregated value of 40 Kb.

image

Your environment

`npx @mui/envinfo` ``` Chrome Version 124.0.6367.119 System: OS: macOS 14.4.1 Binaries: Node: 18.14.2 - ~/.nvm/versions/node/v18.14.2/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.5.0 - ~/.nvm/versions/node/v18.14.2/bin/npm Browsers: Chrome: 124.0.6367.119 Edge: Not Found Firefox: Not Found Safari: 17.4.1 npmPackages: @emotion/react: ^11.11.4 => 11.11.4 @emotion/styled: ^11.11.0 => 11.11.0 @mui/base: 5.0.0-beta.37 @mui/core-downloads-tracker: 5.15.11 @mui/icons-material: ^5.15.11 => 5.15.11 @mui/lab: ^5.0.0-alpha.166 => 5.0.0-alpha.166 @mui/material: ^5.15.11 => 5.15.11 @mui/private-theming: 5.15.11 @mui/styled-engine: 5.15.11 @mui/system: 5.15.11 @mui/types: 7.2.13 @mui/utils: 5.15.11 @mui/x-data-grid: 6.19.5 @mui/x-data-grid-premium: ^6.19.5 => 6.19.5 @mui/x-data-grid-pro: 6.19.5 @mui/x-date-pickers: 6.19.5 @mui/x-date-pickers-pro: ^6.19.5 => 6.19.5 @mui/x-license-pro: 6.10.2 @mui/x-tree-view: ^6.17.0 => 6.17.0 @types/react: ^18.2.60 => 18.2.60 react: ^18.2.0 => 18.2.0 react-dom: ^18.2.0 => 18.2.0 typescript: ^5.3.3 => 5.3.3 ```

Search keywords: datagrid aggregation tree-data Order ID: 64163

michelengelen commented 1 month ago

Hey @gulicJan This is not possible atm. I can add this as a feature request to the board if you want. That way the team can have a look and see if an addition of this feature makes sense.

gulicJan commented 1 month ago

Hey @gulicJan This is not possible atm. I can add this as a feature request to the board if you want. That way the team can have a look and see if an addition of this feature makes sense.

Please, that would be very useful.

If that's not possible, we have another way of going around this by skipping some rows from the aggregation - is that possible?

michelengelen commented 1 month ago

Hey @gulicJan This is not possible atm. I can add this as a feature request to the board if you want. That way the team can have a look and see if an addition of this feature makes sense.

Please, that would be very useful.

Got it. 👍🏼

If that's not possible, we have another way of going around this by skipping some rows from the aggregation - is that possible?

Well, you can always build your custom aggregation functions where you could use some conditions to skip aggregation for rows.

gulicJan commented 1 month ago

Well, you can always build your custom aggregation functions where you could use some conditions to skip aggregation for rows.

How can I skip the row from the aggregation for example when row.shouldSkip === true?

I've found one way by using getCellValue like this:

export const sum: GridAggregationFunction = {
  label: 'Sum',
  getCellValue({ row }) {
    if (row.shouldSkip) {
      return null;
    }

    return row.cost;
  },
  apply: ...

but my problem with that is that im using this Sum aggregation function for multiple columns not only for cost so I can't find a way to make more general solution.

michelengelen commented 1 month ago

It is not easy to build a general solution. That's true. I would suggest to build a custom one only for the columns you need it for and leave the rest as is. I will try and build an example later today and check back here.

gulicJan commented 1 month ago

It is not easy to build a general solution. That's true. I would suggest to build a custom one only for the columns you need it for and leave the rest as is. I will try and build an example later today and check back here.

That's true, but the "issue" is that the logic of skipping particular rows should be applied to every column and we have more than 40 of them. And also for later if we would add new columns in this case we would need also to create new aggregation functions for them.

Any luck with the solution?

michelengelen commented 1 month ago

Any luck with the solution?

Just picked it up again ... I had some meetings yesterday and could not finish it. I will try now to find a good solution for that.

michelengelen commented 1 month ago

Hey @gulicJan ... I finished the exploration and it is possible to exclude grouping rows (parent rows) from aggregation and still generalize them.

Here is an example.

Would this be solution you can work with?

gulicJan commented 1 month ago

Would this be solution you can work with?

It helps in some way, but there's still a question - is there a way to somehow flag specific children rows to be excluded from the aggregation?

In your case is it possible to somehow exclude favicon.ico size from the general aggregation?

image