mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[data grid] Display aggregation label at the aggregation row

Open deerawan opened this issue 1 month ago • 2 comments

Summary

Able to move aggregation labels e.g sum, avg from the column header to the aggregation footer

Examples

Before

Image

After

Move it to the aggregation row

Image

Motivation

Putting them in the header is so far away from the data it's referring to

Search keywords: data grid, aggregation

Order ID: 119122

deerawan avatar Dec 02 '25 22:12 deerawan

Hi @deerawan and thanks for opening an issue for this. What you describe makes perfect sense ... I guess this can be achieved with custom renderers, so let me take a look at a possible solution!

michelengelen avatar Dec 04 '25 13:12 michelengelen

I did play around with this for a while and it indeed can be achieved with some customization.

The aggregation label in the header can be hidden through theming or the sx prop:

sx={{
  // Hide aggregation method label from column headers
  '& .MuiDataGrid-aggregationColumnHeaderLabel': {
    display: 'none',
  },
}}

And to display it in the aggregation row instead you can use the renderCell from the column definition:

const renderAggFooterCell: NonNullable<GridColDef['renderCell']> = (params) => {
  if ((params as any).aggregation) {
    const method = (params as any).aggregation.aggregationFunctionName;
    return (
      <div style={{ display: 'flex', flexDirection: 'column', lineHeight: 1.1 }}>
        <span>{params.formattedValue}</span>
        <span style={{ fontSize: 11, opacity: 0.7 }}>{method}</span>
      </div>
    );
  }
  return params.formattedValue as any;
};

This will make it look similar to this Image

michelengelen avatar Dec 04 '25 15:12 michelengelen

This issue has been inactive for 7 days. Please remove the stale label or leave a comment to keep it open. Otherwise, it will be closed in 5 days.

github-actions[bot] avatar Dec 12 '25 03:12 github-actions[bot]