Repository navigation
Conversation
`TreeDataGrid` no longer asks for a function that groups a set of rows into a `Record<string, readonly R[]>`. Instead, `getRowGroupKey(row, columnKey)` returns the group key of a single row, and the grid builds the group tree itself in a single pass over the rows. Grouping and flattening are now done in one recursion which also returns the fully-expanded row count, so `startRowIndex` and `aria-rowcount` keep their previous meaning. Note: groups are now ordered by the first row that belongs to them, whereas `Object.entries()` used to sort integer-like group keys numerically. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RQUA3cWdaFLZSQwKAGCC3x
It defaults to `String(row[columnKey])`, which is what most grids need, so grouping now only requires `groupBy`, `expandedGroupIds` and `onExpandedGroupIdsChange`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RQUA3cWdaFLZSQwKAGCC3x
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4159 +/- ##
=======================================
Coverage 98.56% 98.57%
=======================================
Files 45 45
Lines 1957 1962 +5
Branches 728 731 +3
=======================================
+ Hits 1929 1934 +5
Misses 28 28
🚀 New features to boost your workflow:
|
Grouping the rows only depends on `rows`, `groupBy` and `getRowGroupKey`, while flattening them depends on the expanded state. Keeping both in a single `useMemo` meant that expanding or collapsing a group re-grouped every row. `startRowIndex` and the total row count do not depend on the expanded state either, so they are computed while grouping, and collapsed groups no longer have to be traversed when the rows are flattened. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RQUA3cWdaFLZSQwKAGCC3x
Group rows are only ever created by `TreeDataGrid`, so a single set can be shared by every instance instead of being rebuilt on every flatten. That makes `isGroupRow` a stable module-level function, which drops it from four dependency arrays and lets the `rows` memo return the rows alone. `rowHeight` is no longer recomputed when a group is expanded or collapsed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RQUA3cWdaFLZSQwKAGCC3x
…th-getRowGroupKey # Conflicts: # README.md # src/TreeDataGrid.tsx
Add a test that integer-like group keys keep the order of their first row, instead of being sorted numerically like `Object.entries()` used to. The row grouping demo only sorted its rows by country, so its year groups would have come out in random order. Sort the rows by year too. Add a performance note to `getRowGroupKey`, as a new function identity groups all the rows again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…th-getRowGroupKey
The groups are only mutated while the rows are being grouped, so build them with a mutable type and return them from the `useMemo` as a `ReadonlyMap` of readonly groups, like `useCalculatedColumns` does with its columns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The `useMemo` already depends on the rows, so it can return the row count when there is nothing to group too, instead of falling back to `rawRows.length` on every render. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Function props are moving to `getX` names, which `getRowGroupKey` already follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rowGrouper with getRowGroupKeyrowGrouper with getRowGroupKey, rename groupIdGetter to getGroupId
nstepien
marked this pull request as ready for review
October 23, 2026 01:15
Collaborator
Author
|
@amanmahajan7 any issues with replacing I also want to rename |
This branch has not been deployed
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.
TreeDataGridno longer asks for a function that groups a set of rows into aRecord<string, readonly R[]>. Instead,getRowGroupKey(row, columnKey)returns the group key of a single row, and the grid builds the group tree itself.The new prop is optional. It defaults to
String(row[columnKey]), so grouping now only requiresgroupBy,expandedGroupIds, andonExpandedGroupIdsChange:<TreeDataGrid groupBy={['country', 'year']} - rowGrouper={rowGrouper} expandedGroupIds={expandedGroupIds} onExpandedGroupIdsChange={setExpandedGroupIds} /> - -function rowGrouper(rows: readonly Row[], columnKey: string) { - return Object.groupBy(rows, (row) => row[columnKey]); -}Pass it to group on something other than the raw cell value, e.g., bucketing dates by year.
Implementation
groupBykeys and is added to every group along its path, so a group'schildRowsholds all of its descendant rows, same as whatrowGrouperused to receive at each level.GroupBy,GroupByMap, andReadonlyGroupByMaptypes, andisReadonlyArray.Memoization
rows,groupBy, andgetRowGroupKeyonly, so expanding or collapsing a group no longer re-groups every row.startRowIndexand the total row count don't depend on the expanded state either, so they're computed while grouping. Flattening now only walks expanded groups: collapsed subtrees are never traversed, andgetGroupIdis only called for visible groups.isGroupRowis a module-level function backed by a module-levelWeakSet, since group rows are only ever created byTreeDataGrid. It's stable across renders, so it's out of four dependency arrays androwHeightsurvives a toggle.Breaking changes
groupIdGetteris renamed togetGroupId, as function props are moving togetXnames.Groups are now ordered by the first row that belongs to them.
Object.entries()previously sorted integer-like group keys numerically, so a numeric group key over unsorted rows will now come out in row order instead of ascending. A new test covers this, and the row grouping demo now sorts its rows by year within each country so its year groups stay in ascending order.Notes
vp run cipasses. The existingTreeDataGridtests now run against the defaultgetRowGroupKey, with dedicated tests covering a custom one and the group order. Visual tests were not run locally;test/visual/treeGrid.test.tsxgroups rows that are already in order, so the screenshot is expected to be unchanged.🤖 Generated with Claude Code