MCPcopy Index your code
hub / github.com/TanStack/table / groupUpRecursively

Function groupUpRecursively

packages/table-core/src/utils/getGroupedRowModel.ts:34–146  ·  view source on GitHub ↗
(
          rows: Row<TData>[],
          depth = 0,
          parentId?: string
        )

Source from the content-addressed store, hash-verified

32
33 // Recursively group the data
34 const groupUpRecursively = (
35 rows: Row<TData>[],
36 depth = 0,
37 parentId?: string
38 ) => {
39 // Grouping depth has been been met
40 // Stop grouping and simply rewrite thd depth and row relationships
41 if (depth >= existingGrouping.length) {
42 return rows.map(row => {
43 row.depth = depth
44
45 groupedFlatRows.push(row)
46 groupedRowsById[row.id] = row
47
48 if (row.subRows) {
49 row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id)
50 }
51
52 return row
53 })
54 }
55
56 const columnId: string = existingGrouping[depth]!
57
58 // Group the rows together for this level
59 const rowGroupsMap = groupBy(rows, columnId)
60
61 // Perform aggregations for each group
62 const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(
63 ([groupingValue, groupedRows], index) => {
64 let id = `${columnId}:${groupingValue}`
65 id = parentId ? `${parentId}>${id}` : id
66
67 // First, Recurse to group sub rows before aggregation
68 const subRows = groupUpRecursively(groupedRows, depth + 1, id)
69
70 subRows.forEach(subRow => {
71 subRow.parentId = id
72 })
73
74 // Flatten the leaf rows of the rows in this group
75 const leafRows = depth
76 ? flattenBy(groupedRows, row => row.subRows)
77 : groupedRows
78
79 const row = createRow(
80 table,
81 id,
82 leafRows[0]!.original,
83 index,
84 depth,
85 undefined,
86 parentId
87 )
88
89 Object.assign(row, {
90 groupingColumnId: columnId,
91 groupingValue,

Callers 1

getGroupedRowModelFunction · 0.85

Calls 3

flattenByFunction · 0.90
createRowFunction · 0.90
groupByFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…