Skip to content

Commit a71ce10

Browse files
PiR1KevinVandy
andauthoredJul 14, 2024··
fix(table-core): assign unassign parentId in grouped row model (#5657)
* fix(getGroupedRowModel): assign parentId & unassign on ungroup (including depth = 0 on ungroup) * assign parent id before flattening rows * simplify ungrouping * remove nx token again * don't remove nx token again --------- Co-authored-by: Kevin Van Cott <kevinvandy656@gmail.com>
1 parent bb0a536 commit a71ce10

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed
 

‎packages/table-core/src/utils/getGroupedRowModel.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createRow } from '../core/row'
2-
import { Table, Row, RowModel, RowData } from '../types'
2+
import { Row, RowData, RowModel, Table } from '../types'
33
import { flattenBy, getMemoOptions, memo } from '../utils'
4+
import { GroupingState } from '../features/ColumnGrouping'
45

56
export function getGroupedRowModel<TData extends RowData>(): (
67
table: Table<TData>
@@ -10,6 +11,10 @@ export function getGroupedRowModel<TData extends RowData>(): (
1011
() => [table.getState().grouping, table.getPreGroupedRowModel()],
1112
(grouping, rowModel) => {
1213
if (!rowModel.rows.length || !grouping.length) {
14+
rowModel.rows.forEach(row => {
15+
row.depth = 0
16+
row.parentId = undefined
17+
})
1318
return rowModel
1419
}
1520

@@ -53,7 +58,7 @@ export function getGroupedRowModel<TData extends RowData>(): (
5358
// Group the rows together for this level
5459
const rowGroupsMap = groupBy(rows, columnId)
5560

56-
// Peform aggregations for each group
61+
// Perform aggregations for each group
5762
const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(
5863
([groupingValue, groupedRows], index) => {
5964
let id = `${columnId}:${groupingValue}`
@@ -62,6 +67,10 @@ export function getGroupedRowModel<TData extends RowData>(): (
6267
// First, Recurse to group sub rows before aggregation
6368
const subRows = groupUpRecursively(groupedRows, depth + 1, id)
6469

70+
subRows.forEach(subRow => {
71+
subRow.parentId = id
72+
})
73+
6574
// Flatten the leaf rows of the rows in this group
6675
const leafRows = depth
6776
? flattenBy(groupedRows, row => row.subRows)

0 commit comments

Comments
 (0)
Please sign in to comment.