Skip to content
Source
Sign inSign up
TanStack/table

fix(table-core): flatten sorted parent rows ahead of their sub-rows #6529

MergedJaybhade(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/6529/headmerged by KevinVandy

Showing 7 changed files with 12 additions and 6 deletions (loading 4).

x
0 of 7 viewed, 7 left
5 additions and 0 deletions.changeset/great-pugs-sniff.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/table-core': patch
+---
+​
+Fix `getSortedRowModel().flatRows` listing sub-rows before their parent. This restores the parent-first order used by the v8 sorted model and aligns the flattened result with the sorted `rows` tree, core row model, and paginated row model.
6 additions and 5 deletionspackages/table-core/src/features/row-sorting/createSortedRowModel.tsModified
View file
@@ -163,6 +163,11 @@
changed = true
​
+ // Take this row's slot before descending, so a parent stays ahead of
+ // its own sub-rows in flatRows.
+ const flatIndex = sortedFlatRows.length
+ sortedFlatRows.push(row)
+​
if (row.subRows.length) {
const sortedSubRows = sortData(row.subRows)
​
@@ -172,13 +177,9 @@
copyInstancePropertiesWithoutMemos(cloned, row)
cloned.subRows = sortedSubRows.rows