Pivot: preserve expanded rows when adding a field, sorting, or refreshing - #9785
Open
mahdi13 wants to merge 3 commits into
Open
Pivot: preserve expanded rows when adding a field, sorting, or refreshing#9785mahdi13 wants to merge 3 commits into
mahdi13 wants to merge 3 commits into
Conversation
Foundation for keying pivot row expansion by dimension-value paths instead of positional TanStack row ids, so expansion survives sorting, adding a field, and data refreshes (rilldata#9781). Keys are the dimension values from root to a node, NUL-joined and hierarchical (depth is the segment count, parent is strip-last-segment). Pure helpers with unit tests.
Wire the value-based expand keys through the pivot so expansion survives sorting, adding a field, and data refreshes (rilldata#9781). - PivotTable sets a hierarchical value-based getRowId, with a reserved id for the grand-totals row. - getValuesForExpandedKey and addExpandedDataToPivot resolve a key by matching each row's value (stored under rowDimensions[0]) instead of positional indices. - queryExpandedRowMeasureValues derives depth from the key's segment count. - getFiltersForCell, getValuesForFlatTable, getRawRowValues, the show-more keys, and the ancestor-highlight walk use the value keys. - Drop the expanded={} resets on add/sort/columns/rows and stop reading the legacy positional pivotExpanded proto field. - Tests updated for value-based resolution. Fixes rilldata#9781
mahdi13
force-pushed
the
pivot-value-based-expansion
branch
from
August 4, 2026 13:29
63818ef to
0262ac9
Compare
Expand a nested row, then add a measure and sort, and assert the row stays expanded (rilldata#9781).
mahdi13
force-pushed
the
pivot-value-based-expansion
branch
from
August 4, 2026 15:09
0262ac9 to
c35cd9a
Compare
mahdi13
marked this pull request as ready for review
August 4, 2026 15:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The pivot table tracked expanded rows by TanStack's positional row ids (dot paths like
0.1.2that index intosubRows). Any config change re-partitions or re-orders the row tree, so those ids stop pointing at the same rows and the expanded state was discarded. Adding a measure or dimension, reordering row dimensions, or sorting all collapsed the tree back to the top level.This switches expansion to value-based hierarchical keys: the dimension values from the root to a node, so a node keeps the same key across add, sort, and data refreshes.
PivotTablesets a value-basedgetRowId(parent id plus this row's value), with a reserved id for the prepended grand-totals row.getValuesForExpandedKeyandaddExpandedDataToPivotresolve a key by matching each row's own value (stored underrowDimensions[0]at every depth) instead of positional indices, which also removes the totals-row offset.queryExpandedRowMeasureValuesderives nesting depth from the key's segment count.getFiltersForCell,getValuesForFlatTable,getRawRowValues, the show-more row limits, and the ancestor-highlight walk all use the value keys.expanded = {}resets on add/sort/columns/rows are dropped. A reorder just leaves keys that match nothing (inert), and the legacy positionalpivotExpandedproto field is no longer read.Reordering the row dimensions changes a node's value path, so those specific nodes are not restored (they were not before either). Adding a field, sorting, and refreshing now keep the tree expanded.
Closes #9781
Checklist: