From 3440b819c7498f4e2c6630fec36df8e53767626c Mon Sep 17 00:00:00 2001 From: melaniemeindldynatrace Date: Wed, 26 Mar 2025 08:13:41 +0100 Subject: [PATCH] fix: Duplicate sub-rows in pagination row model. --- .../table-core/src/utils/getPaginationRowModel.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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