Skip to content

Commit

Permalink
simplify ungrouping
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Jul 14, 2024
1 parent 47893fa commit 28997e4
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions packages/table-core/src/utils/getGroupedRowModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@ import { GroupingState } from '../features/ColumnGrouping'
export function getGroupedRowModel<TData extends RowData>(): (
table: Table<TData>
) => () => RowModel<TData> {
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
}

Expand Down

0 comments on commit 28997e4

Please sign in to comment.