Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ function table_getPinnedRows<
if (keepPinnedRows) {
// get all rows that are pinned even if they would not be otherwise
// visible; account for expanded parent rows, but not pagination/filtering
const fullRow = table.getRow(rowId, true)
if (row_getIsAllParentsExpanded(fullRow)) row = fullRow
const fullRow =
table.getPrePaginatedRowModel().rowsById[rowId] ??
table.getCoreRowModel().rowsById[rowId]
if (fullRow && row_getIsAllParentsExpanded(fullRow)) row = fullRow
} else {
// else get only visible rows that are pinned
row = visibleRows.find((r) => r.id === rowId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, expect, it, vi } from 'vitest'
import {
columnGroupingFeature,
constructTable,
createGroupedRowModel,
createPaginatedRowModel,
rowPaginationFeature,
rowPinningFeature,
Expand All @@ -21,6 +23,12 @@ const featuresWithPagination = testFeatures({
paginatedRowModel: createPaginatedRowModel(),
})

const featuresWithGrouping = testFeatures({
columnGroupingFeature,
rowPinningFeature,
groupedRowModel: createGroupedRowModel(),
})

function makeTable(
options?: Partial<
Omit<TableOptions<typeof features, Person>, 'data' | 'columns' | 'features'>
Expand Down Expand Up @@ -137,6 +145,31 @@ describe('table methods', () => {
})

describe('getTopRows/getBottomRows/getCenterRows', () => {
it('does not throw when a pinned grouped row disappears after ungrouping', () => {
const data = generateTestData(3)
const table = constructTable({
features: featuresWithGrouping,
data,
columns: generateTestColumnDefs<typeof featuresWithGrouping>(data),
initialState: {
grouping: ['status'],
},
})
const groupedRow = table.getRowModel().rows[0]!

groupedRow.pin('top')
expect(table.getTopRows()).toEqual([groupedRow])

table.setGrouping([])

expect(table.getTopRows()).toEqual([])
expect(table.atoms.rowPinning.get().top).toEqual([groupedRow.id])

table.setGrouping(['status'])

expect(table.getTopRows().map((row) => row.id)).toEqual([groupedRow.id])
})

it('should return correct rows for each section', () => {
const table = makeTable({
initialState: {
Expand Down
Loading