Skip to content

[data grid] Aggregation does not respond to sorting (+getCellValue not usable with pivoting) #18342

@lauri865

Description

@lauri865

Steps to reproduce

Steps:

  1. Open this link to live example: https://stackblitz.com/edit/zvyat1a6?file=src%2FDemo.tsx
  2. Sort by transaction date
  3. See how the aggregated value for "Price (first)" doesn't change

Current behavior

Aggregation doesn't honor sorting, which prevents some aggregations such as "First/Last". This is especially an issue in pivoting and row grouping of data where values don't stack (e.g. share price), but you would want to show e.g. the latest share price for the quarter instead.

We work a lot with financial data, and thus find pivoting borderline useless until we get first/last (or better yet latest) aggregations to work. Summing share prices, multiples, etc. makes little sense, but we do want to show the most recent value per quarter for example.

I have also tried to hack this by overriding getCellValue and returning the whole row for it + comparing dates. But within pivoting, it returns values for all the rows, and new columns get autogenerated that hold the actual values for that specific column, but it's not possible to understand which dynamic column we're aggregating at a given point. Hence, overriding getCellValue breaks aggregation completely.

Reproduction: https://stackblitz.com/edit/zvyat1a6-eigrrkht?file=src%2FDemo.tsx
Check console, for every column that we're aggregating, all price values are available, hence Google's first share price becomes completely wrong ($1000, which it not even a valid value).

Expected behavior

  1. Aggregation values should be provided in a sorted order
  2. getCellValue should only fetch values for the pivoted column, not all columns

Context

Ag-grid offers this out of the box (click on values -> first(Gold)): https://www.ag-grid.com/javascript-data-grid/pivoting/

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: aggregation sorting pivot first last latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature: AggregationRelated to the data grid Aggregation featurefeature: PivotingRelated to the data grid pivoting featurefeature: SortingRelated to the data grid Sorting featurescope: data gridChanges related to the data grid.type: bugIt doesn't behave as expected.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions