@tanstack/table-core 9.0.0-beta.49 → 9.0.0-beta.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/rows/coreRowsFeature.cjs +5 -1
- package/dist/core/rows/coreRowsFeature.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.js +6 -2
- package/dist/core/rows/coreRowsFeature.js.map +1 -1
- package/dist/core/rows/coreRowsFeature.types.d.cts +8 -0
- package/dist/core/rows/coreRowsFeature.types.d.ts +8 -0
- package/dist/core/rows/coreRowsFeature.utils.cjs +11 -0
- package/dist/core/rows/coreRowsFeature.utils.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.utils.d.cts +6 -1
- package/dist/core/rows/coreRowsFeature.utils.d.ts +6 -1
- package/dist/core/rows/coreRowsFeature.utils.js +11 -1
- package/dist/core/rows/coreRowsFeature.utils.js.map +1 -1
- package/dist/features/aggregation/aggregationFeature.cjs +3 -2
- package/dist/features/aggregation/aggregationFeature.cjs.map +1 -1
- package/dist/features/aggregation/aggregationFeature.js +3 -2
- package/dist/features/aggregation/aggregationFeature.js.map +1 -1
- package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -1
- package/dist/features/aggregation/aggregationFeature.types.d.cts +36 -13
- package/dist/features/aggregation/aggregationFeature.types.d.ts +36 -13
- package/dist/features/aggregation/aggregationFeature.types.js.map +1 -1
- package/dist/features/aggregation/aggregationFeature.utils.cjs +36 -22
- package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -1
- package/dist/features/aggregation/aggregationFeature.utils.d.cts +9 -8
- package/dist/features/aggregation/aggregationFeature.utils.d.ts +9 -8
- package/dist/features/aggregation/aggregationFeature.utils.js +36 -22
- package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -1
- package/dist/features/aggregation/aggregationFns.cjs +35 -29
- package/dist/features/aggregation/aggregationFns.cjs.map +1 -1
- package/dist/features/aggregation/aggregationFns.d.cts +8 -7
- package/dist/features/aggregation/aggregationFns.d.ts +8 -7
- package/dist/features/aggregation/aggregationFns.js +35 -29
- package/dist/features/aggregation/aggregationFns.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +3 -3
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.js +3 -3
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/static-functions.cjs +1 -0
- package/dist/static-functions.d.cts +2 -2
- package/dist/static-functions.d.ts +2 -2
- package/dist/static-functions.js +2 -2
- package/package.json +1 -1
- package/skills/aggregation/SKILL.md +25 -15
- package/skills/api-not-found/SKILL.md +1 -1
- package/skills/client-vs-server/SKILL.md +1 -1
- package/skills/column-faceting/SKILL.md +1 -1
- package/skills/column-filtering/SKILL.md +1 -1
- package/skills/column-ordering/SKILL.md +1 -1
- package/skills/column-pinning/SKILL.md +1 -1
- package/skills/column-resizing/SKILL.md +1 -1
- package/skills/column-sizing/SKILL.md +1 -1
- package/skills/column-visibility/SKILL.md +1 -1
- package/skills/core/SKILL.md +1 -1
- package/skills/custom-features/SKILL.md +1 -1
- package/skills/expanding/SKILL.md +1 -1
- package/skills/global-filtering/SKILL.md +1 -1
- package/skills/grouping/SKILL.md +1 -1
- package/skills/migrate-v8-to-v9/SKILL.md +11 -3
- package/skills/pagination/SKILL.md +1 -1
- package/skills/row-pinning/SKILL.md +1 -1
- package/skills/row-selection/SKILL.md +1 -1
- package/skills/sorting/SKILL.md +1 -1
- package/skills/table-features/SKILL.md +1 -1
- package/skills/typescript/SKILL.md +1 -1
- package/src/core/rows/coreRowsFeature.ts +5 -0
- package/src/core/rows/coreRowsFeature.types.ts +8 -0
- package/src/core/rows/coreRowsFeature.utils.ts +18 -0
- package/src/features/aggregation/aggregationFeature.ts +2 -1
- package/src/features/aggregation/aggregationFeature.types.ts +39 -12
- package/src/features/aggregation/aggregationFeature.utils.ts +56 -27
- package/src/features/aggregation/aggregationFns.ts +42 -33
- package/src/features/column-grouping/createGroupedRowModel.ts +3 -3
package/skills/grouping/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: >
|
|
|
5
5
|
metadata:
|
|
6
6
|
type: lifecycle
|
|
7
7
|
library: '@tanstack/table-core'
|
|
8
|
-
library_version: '9.0.0-beta.
|
|
8
|
+
library_version: '9.0.0-beta.50'
|
|
9
9
|
requires: ['core', 'table-features', 'typescript']
|
|
10
10
|
sources:
|
|
11
11
|
- 'TanStack/table:docs/framework/react/guide/migrating.md'
|
|
@@ -123,14 +123,22 @@ Move registries from table options or factory arguments into these feature slots
|
|
|
123
123
|
Register only the built-ins the table references by string name, importing each individually (`filterFn_includesString`, `sortFn_alphanumeric`, `aggregationFn_sum`, and so on) alongside any custom functions. The full registry objects (`filterFns`, `sortFns`, `aggregationFns` exports) still work but bundle every built-in. A slot's keys become the valid string names in column definitions, and `'auto'` resolves only registered functions.
|
|
124
124
|
|
|
125
125
|
Aggregation is independent from grouping. Add `aggregationFeature` for
|
|
126
|
-
`aggregationFn`, `aggregatedCell`, `column.getAggregationValue(
|
|
126
|
+
`aggregationFn`, `aggregatedCell`, `column.getAggregationValue(options?)`, and
|
|
127
127
|
`cell.getIsAggregated`. A root total does not require grouping. Convert legacy
|
|
128
128
|
custom callables `(columnId, leafRows, childRows) => result` to
|
|
129
129
|
`constructAggregationFn({ aggregate: (context) => result, merge? })`
|
|
130
130
|
definitions. Replace `column.getAggregationFn()` with
|
|
131
131
|
`column.getAggregationFns()`; arrays in `aggregationFn` return keyed objects.
|
|
132
132
|
Replace the old `AggregationFn` and `CreatedAggregationFn` types with
|
|
133
|
-
`AggregationFnDef`.
|
|
133
|
+
`AggregationFnDef`. Aggregation row selection is shared across every definition
|
|
134
|
+
on a column: `maxAggregationDepth` defaults to `0`, while `1` selects direct
|
|
135
|
+
sub-rows and `Infinity` selects terminal rows. Explicit totals can override it
|
|
136
|
+
with the single object signature
|
|
137
|
+
`column.getAggregationValue({ rows, maxDepth })`; positional row and depth
|
|
138
|
+
arguments are not supported. All built-ins consume the same selected `rows`.
|
|
139
|
+
Custom definitions can inspect grouped `subRows`, and `merge` receives matching
|
|
140
|
+
`subRowResults`. Use `table.getMaxSubRowDepth()` when a depth should derive from
|
|
141
|
+
the deepest structural row in the core model.
|
|
134
142
|
|
|
135
143
|
### 3. Migrate state reads and whole-state observation
|
|
136
144
|
|
package/skills/sorting/SKILL.md
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
row_getUniqueValues,
|
|
10
10
|
row_getValue,
|
|
11
11
|
row_renderValue,
|
|
12
|
+
table_getMaxSubRowDepth,
|
|
12
13
|
table_getRow,
|
|
13
14
|
table_getRowId,
|
|
14
15
|
table_getRowsInDisplayOrder,
|
|
@@ -73,6 +74,10 @@ export const coreRowsFeature: TableFeature = {
|
|
|
73
74
|
fn: (id: string, searchAll?: boolean) =>
|
|
74
75
|
table_getRow(table, id, searchAll),
|
|
75
76
|
},
|
|
77
|
+
table_getMaxSubRowDepth: {
|
|
78
|
+
fn: () => table_getMaxSubRowDepth(table),
|
|
79
|
+
memoDeps: () => [table.getCoreRowModel()],
|
|
80
|
+
},
|
|
76
81
|
})
|
|
77
82
|
},
|
|
78
83
|
}
|
|
@@ -131,6 +131,11 @@ export interface Table_Rows<
|
|
|
131
131
|
in out TFeatures extends TableFeatures,
|
|
132
132
|
in out TData extends RowData,
|
|
133
133
|
> {
|
|
134
|
+
/**
|
|
135
|
+
* Returns the deepest structural row depth in the core row model.
|
|
136
|
+
* Root rows are depth `0`, direct sub-rows are depth `1`, and so on.
|
|
137
|
+
*/
|
|
138
|
+
getMaxSubRowDepth: () => number
|
|
134
139
|
/**
|
|
135
140
|
* Returns the rows in the current display order and assigns their display
|
|
136
141
|
* indexes. When expanded rows bypass pagination, expanded descendants are
|
|
@@ -138,6 +143,9 @@ export interface Table_Rows<
|
|
|
138
143
|
* `row.getDisplayIndex()`.
|
|
139
144
|
*/
|
|
140
145
|
getRowsInDisplayOrder: () => Array<Row<TFeatures, TData>>
|
|
146
|
+
/**
|
|
147
|
+
* Returns the row id for a given row.
|
|
148
|
+
*/
|
|
141
149
|
getRowId: (_: TData, index: number, parent?: Row<TFeatures, TData>) => string
|
|
142
150
|
/**
|
|
143
151
|
* Returns the row with the given ID.
|
|
@@ -167,6 +167,24 @@ export function row_getLeafRows<
|
|
|
167
167
|
return flattenBy(row.subRows, (d) => d.subRows)
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Returns the deepest structural row depth in the core row model.
|
|
172
|
+
* Root rows are depth `0`, their direct sub-rows are depth `1`, and so on.
|
|
173
|
+
*/
|
|
174
|
+
export function table_getMaxSubRowDepth<
|
|
175
|
+
TFeatures extends TableFeatures,
|
|
176
|
+
TData extends RowData,
|
|
177
|
+
>(table: Table_Internal<TFeatures, TData>): number {
|
|
178
|
+
const rows = table.getCoreRowModel().flatRows
|
|
179
|
+
let maxDepth = 0
|
|
180
|
+
|
|
181
|
+
for (let i = 0; i < rows.length; i++) {
|
|
182
|
+
maxDepth = Math.max(maxDepth, rows[i]!.depth)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return maxDepth
|
|
186
|
+
}
|
|
187
|
+
|
|
170
188
|
/**
|
|
171
189
|
* Looks up this row's direct parent, if it has one.
|
|
172
190
|
*
|
|
@@ -16,6 +16,7 @@ export const aggregationFeature: TableFeature = {
|
|
|
16
16
|
aggregatedCell: ({ column, getValue }: any) =>
|
|
17
17
|
formatAggregatedCellValue(getValue(), column.columnDef.aggregationFn),
|
|
18
18
|
aggregationFn: 'auto',
|
|
19
|
+
maxAggregationDepth: 0,
|
|
19
20
|
}),
|
|
20
21
|
|
|
21
22
|
getDefaultTableOptions: () => ({
|
|
@@ -36,7 +37,7 @@ export const aggregationFeature: TableFeature = {
|
|
|
36
37
|
fn: (column) => column_getAggregationFns(column),
|
|
37
38
|
},
|
|
38
39
|
column_getAggregationValue: {
|
|
39
|
-
fn: (column,
|
|
40
|
+
fn: (column, options) => column_getAggregationValue(column, options),
|
|
40
41
|
},
|
|
41
42
|
column_getAutoAggregationFn: {
|
|
42
43
|
fn: (column) => column_getAutoAggregationFn(column),
|
|
@@ -20,6 +20,14 @@ export interface AggregationContext<
|
|
|
20
20
|
column: Column<TFeatures, TData, TValue>
|
|
21
21
|
/** Convenience alias for `column.id`. */
|
|
22
22
|
columnId: string
|
|
23
|
+
/** Maximum relative sub-row depth used to select `rows`. */
|
|
24
|
+
maxDepth: number
|
|
25
|
+
/**
|
|
26
|
+
* Immediate sub-rows for grouped aggregation. This property is omitted
|
|
27
|
+
* for root or caller-supplied-row aggregation. At a terminal grouping level
|
|
28
|
+
* these are the direct data rows; at a nested level they are sub-row groups.
|
|
29
|
+
*/
|
|
30
|
+
subRows?: ReadonlyArray<Row<TFeatures, TData>>
|
|
23
31
|
/** Reads this column's value from one of `rows`. */
|
|
24
32
|
getValue: (row: Row<TFeatures, TData>) => TValue
|
|
25
33
|
/**
|
|
@@ -29,8 +37,8 @@ export interface AggregationContext<
|
|
|
29
37
|
*/
|
|
30
38
|
groupingRow?: Row<TFeatures, TData>
|
|
31
39
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
40
|
+
* Unique rows selected at `maxDepth`. Branches that end before `maxDepth`
|
|
41
|
+
* contribute their deepest available row.
|
|
34
42
|
*/
|
|
35
43
|
rows: ReadonlyArray<Row<TFeatures, TData>>
|
|
36
44
|
/** The table that owns the column and rows. */
|
|
@@ -44,10 +52,10 @@ export interface AggregationMergeContext<
|
|
|
44
52
|
TValue,
|
|
45
53
|
TResult,
|
|
46
54
|
> extends AggregationContext<TFeatures, TData, TValue> {
|
|
47
|
-
/** Results produced for each immediate
|
|
48
|
-
|
|
49
|
-
/** Immediate
|
|
50
|
-
|
|
55
|
+
/** Results produced for each immediate sub-row group, in sub-row order. */
|
|
56
|
+
subRowResults: ReadonlyArray<TResult>
|
|
57
|
+
/** Immediate sub-row groups corresponding to `subRowResults`. */
|
|
58
|
+
subRows: ReadonlyArray<Row<TFeatures, TData>>
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
/** A context-based aggregation definition and optional grouped-result merge. */
|
|
@@ -57,11 +65,11 @@ export interface AggregationFnDef<
|
|
|
57
65
|
TValue = unknown,
|
|
58
66
|
TResult = unknown,
|
|
59
67
|
> {
|
|
60
|
-
/** Computes a result directly from
|
|
68
|
+
/** Computes a result directly from the selected `rows`. */
|
|
61
69
|
aggregate: (context: AggregationContext<TFeatures, TData, TValue>) => TResult
|
|
62
70
|
/**
|
|
63
|
-
* Combines already-computed immediate
|
|
64
|
-
* nested grouping falls back to `aggregate` over the group's
|
|
71
|
+
* Combines already-computed immediate sub-row results. When omitted,
|
|
72
|
+
* nested grouping falls back to `aggregate` over the group's selected rows.
|
|
65
73
|
*/
|
|
66
74
|
merge?: (
|
|
67
75
|
context: AggregationMergeContext<TFeatures, TData, TValue, TResult>,
|
|
@@ -236,6 +244,12 @@ export interface ColumnDef_Aggregation<
|
|
|
236
244
|
* result object. Inline definitions in an array require an explicit `id`.
|
|
237
245
|
*/
|
|
238
246
|
aggregationFn?: AggregationFnOption<TFeatures, TData, TValue>
|
|
247
|
+
/**
|
|
248
|
+
* Maximum relative sub-row depth used for grouped aggregation and cached
|
|
249
|
+
* default totals. `0` selects the supplied root rows, `1` their direct
|
|
250
|
+
* sub-rows, and so on. Defaults to `0`.
|
|
251
|
+
*/
|
|
252
|
+
maxAggregationDepth?: number
|
|
239
253
|
/**
|
|
240
254
|
* Optionally supplies a precomputed aggregation value for this column.
|
|
241
255
|
* Return `{ value }` to handle the request, including `{ value: undefined }`;
|
|
@@ -257,11 +271,11 @@ export interface Column_Aggregation<
|
|
|
257
271
|
>
|
|
258
272
|
/**
|
|
259
273
|
* Aggregates this column over the default pre-grouped row model, or over a
|
|
260
|
-
* caller-provided array of rows.
|
|
261
|
-
*
|
|
274
|
+
* caller-provided array of rows. `options.maxDepth` overrides the column's
|
|
275
|
+
* `maxAggregationDepth`. Explicit-row calls are intentionally not cached.
|
|
262
276
|
*/
|
|
263
277
|
getAggregationValue: <TResult = ColumnAggregationValue<TFeatures>>(
|
|
264
|
-
|
|
278
|
+
options?: AggregationValueOptions<TFeatures, TData>,
|
|
265
279
|
) => TResult
|
|
266
280
|
/** Infers `sum` for a numeric first row and `extent` for a Date first row. */
|
|
267
281
|
getAutoAggregationFn: () =>
|
|
@@ -269,6 +283,17 @@ export interface Column_Aggregation<
|
|
|
269
283
|
| undefined
|
|
270
284
|
}
|
|
271
285
|
|
|
286
|
+
/** Options for a caller-requested column aggregation value. */
|
|
287
|
+
export interface AggregationValueOptions<
|
|
288
|
+
in out TFeatures extends TableFeatures,
|
|
289
|
+
in out TData extends RowData,
|
|
290
|
+
> {
|
|
291
|
+
/** Overrides the column's `maxAggregationDepth` for this request. */
|
|
292
|
+
maxDepth?: number
|
|
293
|
+
/** Rows to aggregate instead of the default pre-grouped row model. */
|
|
294
|
+
rows?: ReadonlyArray<Row<TFeatures, TData>>
|
|
295
|
+
}
|
|
296
|
+
|
|
272
297
|
/** Cell instance APIs installed by `aggregationFeature`. */
|
|
273
298
|
export interface Cell_Aggregation {
|
|
274
299
|
/** Whether this cell displays an aggregate on a synthetic grouped row. */
|
|
@@ -289,6 +314,8 @@ export interface AggregationValueContext<
|
|
|
289
314
|
> {
|
|
290
315
|
/** The column whose value was requested. */
|
|
291
316
|
column: Column<TFeatures, TData, TValue>
|
|
317
|
+
/** Maximum relative sub-row depth used for the request. */
|
|
318
|
+
maxDepth: number
|
|
292
319
|
/** Caller-provided rows, or `undefined` for the default row model. */
|
|
293
320
|
rows?: ReadonlyArray<Row<TFeatures, TData>>
|
|
294
321
|
/** The table that owns the column. */
|
|
@@ -5,9 +5,11 @@ import type { Row } from '../../types/Row'
|
|
|
5
5
|
import type { TableFeatures } from '../../types/TableFeatures'
|
|
6
6
|
import type { CellData, RowData } from '../../types/type-utils'
|
|
7
7
|
import type {
|
|
8
|
+
AggregationContext,
|
|
8
9
|
AggregationFnDef,
|
|
9
10
|
AggregationFnDescriptor,
|
|
10
11
|
AggregationFnRef,
|
|
12
|
+
AggregationValueOptions,
|
|
11
13
|
ColumnAggregationValue,
|
|
12
14
|
ResolvedAggregationFn,
|
|
13
15
|
} from './aggregationFeature.types'
|
|
@@ -15,6 +17,7 @@ import type {
|
|
|
15
17
|
interface AggregationCacheEntry {
|
|
16
18
|
aggregationFnOption: unknown
|
|
17
19
|
dependency: unknown
|
|
20
|
+
maxDepth: number
|
|
18
21
|
registry: unknown
|
|
19
22
|
value: unknown
|
|
20
23
|
}
|
|
@@ -50,21 +53,31 @@ function warn(message: string) {
|
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
|
|
56
|
+
function resolveMaxAggregationDepth(maxDepth: number | undefined) {
|
|
57
|
+
return maxDepth === undefined || Number.isNaN(maxDepth)
|
|
58
|
+
? 0
|
|
59
|
+
: Math.max(0, Math.floor(maxDepth))
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
63
|
+
* Selects unique rows at a maximum relative depth in encounter order.
|
|
64
|
+
* Branches that end before the requested depth contribute their deepest row.
|
|
56
65
|
*/
|
|
57
66
|
export function normalizeAggregationRows<
|
|
58
67
|
TFeatures extends TableFeatures,
|
|
59
68
|
TData extends RowData,
|
|
60
|
-
>(
|
|
69
|
+
>(
|
|
70
|
+
rows: ReadonlyArray<Row<TFeatures, TData>>,
|
|
71
|
+
maxDepth = 0,
|
|
72
|
+
): Array<Row<TFeatures, TData>> {
|
|
61
73
|
const result: Array<Row<TFeatures, TData>> = []
|
|
62
74
|
const seen = new Set<string>()
|
|
75
|
+
const normalizedMaxDepth = resolveMaxAggregationDepth(maxDepth)
|
|
63
76
|
|
|
64
|
-
const visit = (row: Row<TFeatures, TData
|
|
65
|
-
if (row.subRows.length) {
|
|
77
|
+
const visit = (row: Row<TFeatures, TData>, depth: number) => {
|
|
78
|
+
if (row.subRows.length && depth < normalizedMaxDepth) {
|
|
66
79
|
for (let i = 0; i < row.subRows.length; i++) {
|
|
67
|
-
visit(row.subRows[i]
|
|
80
|
+
visit(row.subRows[i]!, depth + 1)
|
|
68
81
|
}
|
|
69
82
|
return
|
|
70
83
|
}
|
|
@@ -76,7 +89,7 @@ export function normalizeAggregationRows<
|
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
for (let i = 0; i < rows.length; i++) {
|
|
79
|
-
visit(rows[i]
|
|
92
|
+
visit(rows[i]!, 0)
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
return result
|
|
@@ -232,35 +245,40 @@ export function column_getAggregationFns<
|
|
|
232
245
|
return finish(resolved)
|
|
233
246
|
}
|
|
234
247
|
|
|
235
|
-
function
|
|
236
|
-
|
|
248
|
+
function getSubRowResult(
|
|
249
|
+
subRowValue: unknown,
|
|
237
250
|
isMultiple: boolean,
|
|
238
251
|
id: string | undefined,
|
|
239
252
|
) {
|
|
240
|
-
if (!isMultiple) return
|
|
241
|
-
if (!id || !
|
|
242
|
-
return hasOwn(
|
|
243
|
-
? (
|
|
253
|
+
if (!isMultiple) return subRowValue
|
|
254
|
+
if (!id || !subRowValue || typeof subRowValue !== 'object') return undefined
|
|
255
|
+
return hasOwn(subRowValue, id)
|
|
256
|
+
? (subRowValue as Record<string, unknown>)[id]
|
|
244
257
|
: undefined
|
|
245
258
|
}
|
|
246
259
|
|
|
247
|
-
/** Executes every configured aggregation
|
|
260
|
+
/** Executes every configured aggregation over a depth-selected row frontier. */
|
|
248
261
|
export function aggregateColumnValue<
|
|
249
262
|
TFeatures extends TableFeatures,
|
|
250
263
|
TData extends RowData,
|
|
251
264
|
>(args: {
|
|
252
|
-
|
|
265
|
+
maxDepth?: number
|
|
266
|
+
subRows?: ReadonlyArray<Row<TFeatures, TData>>
|
|
253
267
|
column: Column<TFeatures, TData, unknown>
|
|
254
268
|
groupingRow?: Row<TFeatures, TData>
|
|
255
269
|
rows: ReadonlyArray<Row<TFeatures, TData>>
|
|
256
270
|
}): unknown {
|
|
257
|
-
const {
|
|
271
|
+
const { subRows, column, groupingRow, rows } = args
|
|
258
272
|
const internalColumn = column as Column_Internal<TFeatures, TData, unknown>
|
|
273
|
+
const maxDepth = resolveMaxAggregationDepth(
|
|
274
|
+
args.maxDepth ?? internalColumn.columnDef.maxAggregationDepth,
|
|
275
|
+
)
|
|
276
|
+
const aggregationRows = normalizeAggregationRows(rows, maxDepth)
|
|
259
277
|
const entries = column_getAggregationFns(internalColumn)
|
|
260
278
|
const isMultiple = Array.isArray(internalColumn.columnDef.aggregationFn)
|
|
261
279
|
const canMerge =
|
|
262
|
-
!!
|
|
263
|
-
|
|
280
|
+
!!subRows?.length &&
|
|
281
|
+
subRows.every(
|
|
264
282
|
(row) =>
|
|
265
283
|
!!(row as any).groupingColumnId &&
|
|
266
284
|
(row as any).groupingColumnId !== column.id,
|
|
@@ -270,22 +288,24 @@ export function aggregateColumnValue<
|
|
|
270
288
|
const definition = entry.aggregationFn
|
|
271
289
|
if (!definition) return undefined
|
|
272
290
|
|
|
273
|
-
const context = {
|
|
291
|
+
const context: AggregationContext<TFeatures, TData, unknown> = {
|
|
292
|
+
...(subRows ? { subRows } : {}),
|
|
274
293
|
column,
|
|
275
294
|
columnId: column.id,
|
|
276
295
|
getValue: (row: Row<TFeatures, TData>) => row.getValue(column.id),
|
|
277
296
|
...(groupingRow ? { groupingRow } : {}),
|
|
278
|
-
|
|
297
|
+
maxDepth,
|
|
298
|
+
rows: aggregationRows,
|
|
279
299
|
table: column.table as any,
|
|
280
300
|
}
|
|
281
301
|
|
|
282
302
|
if (canMerge && definition.merge) {
|
|
283
303
|
return definition.merge({
|
|
284
304
|
...context,
|
|
285
|
-
|
|
286
|
-
|
|
305
|
+
subRowResults: subRows.map((row) =>
|
|
306
|
+
getSubRowResult(row.getValue(column.id), isMultiple, entry.id),
|
|
287
307
|
),
|
|
288
|
-
|
|
308
|
+
subRows,
|
|
289
309
|
})
|
|
290
310
|
}
|
|
291
311
|
|
|
@@ -306,17 +326,22 @@ export function aggregateColumnValue<
|
|
|
306
326
|
return result
|
|
307
327
|
}
|
|
308
328
|
|
|
309
|
-
/** Implements `column.getAggregationValue(
|
|
329
|
+
/** Implements `column.getAggregationValue(options?)` and its default cache. */
|
|
310
330
|
export function column_getAggregationValue<
|
|
311
331
|
TFeatures extends TableFeatures,
|
|
312
332
|
TData extends RowData,
|
|
313
333
|
TValue extends CellData = CellData,
|
|
314
334
|
>(
|
|
315
335
|
column: Column_Internal<TFeatures, TData, TValue>,
|
|
316
|
-
|
|
336
|
+
options?: AggregationValueOptions<TFeatures, TData>,
|
|
317
337
|
): ColumnAggregationValue<TFeatures> {
|
|
338
|
+
const rows = options?.rows
|
|
339
|
+
const resolvedMaxDepth = resolveMaxAggregationDepth(
|
|
340
|
+
options?.maxDepth ?? column.columnDef.maxAggregationDepth,
|
|
341
|
+
)
|
|
318
342
|
const providedResult = column.columnDef.getAggregationValue?.({
|
|
319
343
|
column: column as any,
|
|
344
|
+
maxDepth: resolvedMaxDepth,
|
|
320
345
|
rows,
|
|
321
346
|
table: column.table as any,
|
|
322
347
|
})
|
|
@@ -327,7 +352,8 @@ export function column_getAggregationValue<
|
|
|
327
352
|
if (rows !== undefined) {
|
|
328
353
|
return aggregateColumnValue({
|
|
329
354
|
column: column as any,
|
|
330
|
-
|
|
355
|
+
maxDepth: resolvedMaxDepth,
|
|
356
|
+
rows,
|
|
331
357
|
}) as any
|
|
332
358
|
}
|
|
333
359
|
|
|
@@ -341,6 +367,7 @@ export function column_getAggregationValue<
|
|
|
341
367
|
if (
|
|
342
368
|
previous &&
|
|
343
369
|
previous.dependency === model &&
|
|
370
|
+
previous.maxDepth === resolvedMaxDepth &&
|
|
344
371
|
previous.registry === registry &&
|
|
345
372
|
previous.aggregationFnOption === aggregationFnOption
|
|
346
373
|
) {
|
|
@@ -349,11 +376,13 @@ export function column_getAggregationValue<
|
|
|
349
376
|
|
|
350
377
|
const value = aggregateColumnValue({
|
|
351
378
|
column: column as any,
|
|
352
|
-
|
|
379
|
+
maxDepth: resolvedMaxDepth,
|
|
380
|
+
rows: model.rows,
|
|
353
381
|
})
|
|
354
382
|
;(column as any)._aggregationValueCache = {
|
|
355
383
|
aggregationFnOption,
|
|
356
384
|
dependency: model,
|
|
385
|
+
maxDepth: resolvedMaxDepth,
|
|
357
386
|
registry,
|
|
358
387
|
value,
|
|
359
388
|
} satisfies AggregationCacheEntry
|