Skip to content

Commit 03142ed

Browse files
authored
fix: row pinning after ungrouping (#6493)
1 parent 9700f9b commit 03142ed

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

packages/table-core/src/features/row-pinning/rowPinningFeature.utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ function table_getPinnedRows<
123123
if (keepPinnedRows) {
124124
// get all rows that are pinned even if they would not be otherwise
125125
// visible; account for expanded parent rows, but not pagination/filtering
126-
const fullRow = table.getRow(rowId, true)
127-
if (row_getIsAllParentsExpanded(fullRow)) row = fullRow
126+
const fullRow =
127+
table.getPrePaginatedRowModel().rowsById[rowId] ??
128+
table.getCoreRowModel().rowsById[rowId]
129+
if (fullRow && row_getIsAllParentsExpanded(fullRow)) row = fullRow
128130
} else {
129131
// else get only visible rows that are pinned
130132
row = visibleRows.find((r) => r.id === rowId)

packages/table-core/tests/implementation/features/row-pinning/rowPinningFeature.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { describe, expect, it, vi } from 'vitest'
22
import {
3+
columnGroupingFeature,
34
constructTable,
5+
createGroupedRowModel,
46
createPaginatedRowModel,
57
rowPaginationFeature,
68
rowPinningFeature,
@@ -21,6 +23,12 @@ const featuresWithPagination = testFeatures({
2123
paginatedRowModel: createPaginatedRowModel(),
2224
})
2325

26+
const featuresWithGrouping = testFeatures({
27+
columnGroupingFeature,
28+
rowPinningFeature,
29+
groupedRowModel: createGroupedRowModel(),
30+
})
31+
2432
function makeTable(
2533
options?: Partial<
2634
Omit<TableOptions<typeof features, Person>, 'data' | 'columns' | 'features'>
@@ -137,6 +145,31 @@ describe('table methods', () => {
137145
})
138146

139147
describe('getTopRows/getBottomRows/getCenterRows', () => {
148+
it('does not throw when a pinned grouped row disappears after ungrouping', () => {
149+
const data = generateTestData(3)
150+
const table = constructTable({
151+
features: featuresWithGrouping,
152+
data,
153+
columns: generateTestColumnDefs<typeof featuresWithGrouping>(data),
154+
initialState: {
155+
grouping: ['status'],
156+
},
157+
})
158+
const groupedRow = table.getRowModel().rows[0]!
159+
160+
groupedRow.pin('top')
161+
expect(table.getTopRows()).toEqual([groupedRow])
162+
163+
table.setGrouping([])
164+
165+
expect(table.getTopRows()).toEqual([])
166+
expect(table.atoms.rowPinning.get().top).toEqual([groupedRow.id])
167+
168+
table.setGrouping(['status'])
169+
170+
expect(table.getTopRows().map((row) => row.id)).toEqual([groupedRow.id])
171+
})
172+
140173
it('should return correct rows for each section', () => {
141174
const table = makeTable({
142175
initialState: {

0 commit comments

Comments
 (0)