diff --git a/packages/table-core/src/utils/getPaginationRowModel.ts b/packages/table-core/src/utils/getPaginationRowModel.ts index 9119a5dc23..85a8bc8878 100644 --- a/packages/table-core/src/utils/getPaginationRowModel.ts +++ b/packages/table-core/src/utils/getPaginationRowModel.ts @@ -44,13 +44,22 @@ export function getPaginationRowModel(opts?: { paginatedRowModel.flatRows = [] + // keep track of the already added flatRows, to avoid duplication of already expanded sub-rows + const addedFlatRowsSet = new Set() + const handleRow = (row: Row) => { + if (addedFlatRowsSet.has(row.id)) { + return + } + paginatedRowModel.flatRows.push(row) + addedFlatRowsSet.add(row.id) + if (row.subRows.length) { row.subRows.forEach(handleRow) } } - + paginatedRowModel.rows.forEach(handleRow) return paginatedRowModel