From 28997e4fb8cad394677c1ad264de394428df16bd Mon Sep 17 00:00:00 2001 From: Kevin Van Cott Date: Sat, 13 Jul 2024 21:46:10 -0500 Subject: [PATCH] simplify ungrouping --- packages/table-core/src/utils/getGroupedRowModel.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/table-core/src/utils/getGroupedRowModel.ts b/packages/table-core/src/utils/getGroupedRowModel.ts index e5464f8514..da97631913 100644 --- a/packages/table-core/src/utils/getGroupedRowModel.ts +++ b/packages/table-core/src/utils/getGroupedRowModel.ts @@ -6,22 +6,15 @@ import { GroupingState } from '../features/ColumnGrouping' export function getGroupedRowModel(): ( table: Table ) => () => RowModel { - let lastGrouping: GroupingState - return table => memo( () => [table.getState().grouping, table.getPreGroupedRowModel()], (grouping, rowModel) => { - //ungrouping - if (lastGrouping?.length > 0 && grouping.length === 0) { + if (!rowModel.rows.length || !grouping.length) { rowModel.rows.forEach(row => { row.depth = 0 - delete row.parentId + row.parentId = undefined }) - } - lastGrouping = grouping - - if (!rowModel.rows.length || !grouping.length) { return rowModel }