Skip to content
Source
Sign inSign up
TanStack/table

fix(table-core): point sorted row model rowsById at sorted branch clones #6635

Openkoreahghg(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/6635/headopened

Showing 3 changed files with 64 additions and 2 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/sorted-rows-by-id.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/table-core': patch
+---
+​
+Point the sorted row model's `rowsById` at the cloned branch rows whose `subRows` were re-ordered by sorting. Previously `rowsById` was reused from the pre-sorted row model, so `table.getRow(id)` returned the original parent with unsorted `subRows` instead of the row rendered in `getRowModel().rows`.
11 additions and 2 deletionspackages/table-core/src/features/row-sorting/createSortedRowModel.tsModified
View file
@@ -1,5 +1,6 @@
import {
copyInstancePropertiesWithoutMemos,
+ makeObjectMap,
skipFirstRun,
tableMemo,
} from '../../utils'
@@ -57,6 +58,8 @@
​
const sortedFlatRows: Array<Row<TFeatures, TData>> = []
+ // Copied on the first branch clone so lookups resolve to the sorted rows
+ let rowsById = preSortedRowModel.rowsById
​
// Filter out sortings that correspond to non existing columns
const availableSorting = sorting.filter((sort) => {
@@ -178,6 +181,10 @@
cloned.subRows = sortedSubRows.rows
sortedData[i] = cloned
sortedFlatRows[flatIndex] = cloned
+ if (rowsById === preSortedRowModel.rowsById) {