Skip to content

Pivot: expanded rows collapse on any config change (adding a measure/dimension, reordering, or sorting) #9781

Description

@mahdi13

Describe the bug

In an Explore dashboard's pivot table, drilled-in (expanded) rows are discarded whenever the pivot configuration changes. Adding a measure or dimension, reordering the row dimensions, or changing the sort all collapse the tree back to the top level, so the user has to manually re-expand everything. On a wide dashboard this makes iterative analysis painful, because every small change wipes your place.

To Reproduce

  1. Open an Explore dashboard and switch to the Pivot view.
  2. Put 2 or 3 dimensions on Rows (for example Application > Source > Month) and a few measures on Columns.
  3. Expand several rows to drill in.
  4. Do any of the following: add a measure to Columns, add or reorder a row dimension, or click a column header to sort.
  5. The entire tree collapses to the top level and all expanded rows are lost.

Expected behavior

Expansion should be preserved across config changes wherever the rows still exist. Adding a measure or column, or adding or removing a row dimension at the deepest level, should not collapse anything. Reordering or sorting should keep the same value nodes expanded.

Desktop

  • OS: macOS
  • Browser: Chrome
  • Version: v0.88.5 and main (verified on commit d43bb02)

Additional context

Root cause: the pivot tracks expanded rows by positional TanStack keys (dot paths like "0.1.2" that index into subRows) rather than by dimension values. Any config change re-partitions or re-orders the row tree, so those positional keys no longer point at the same rows and the expanded state is thrown away. The setPivotRows, setPivotColumns, and addPivotField reducers reset expanded = {} (web-common/src/features/dashboards/stores/dashboard-stores.ts), and pivot-expansion.ts traverses positionally via getValuesForExpandedKey and addExpandedDataToPivot (key.split(".").map((i) => parseInt(i, 10))).

Proposed fix: track expansion by dimension-value paths (a stable getRowId on the pivot table plus value-keyed expanded state), so expansion survives add, reorder, and sort. Related prior work: closed #6916 "Pivot: Expand and collapse" (design doc). We would like to contribute the implementation, and are opening this issue first to align on the approach before submitting the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions