@tanstack/table-core 9.0.0-beta.46 → 9.0.0-beta.47
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/features/column-filtering/columnFilteringFeature.types.d.cts +43 -3
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +43 -3
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +18 -9
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +6 -2
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +6 -2
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +18 -9
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs +7 -2
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.cts +6 -2
- package/dist/features/column-filtering/createFilteredRowModel.d.ts +6 -2
- package/dist/features/column-filtering/createFilteredRowModel.js +7 -2
- package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +41 -3
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +41 -3
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +17 -3
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +5 -0
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +5 -0
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +17 -3
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +6 -3
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +6 -3
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +6 -3
- package/dist/features/column-grouping/createGroupedRowModel.js +6 -3
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +3 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +2 -6
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +2 -6
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +3 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs +6 -2
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.d.cts +6 -2
- package/dist/features/row-sorting/createSortedRowModel.d.ts +6 -2
- package/dist/features/row-sorting/createSortedRowModel.js +6 -2
- package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +31 -2
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +31 -2
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +19 -4
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +19 -4
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/fns/aggregationFns.cjs +128 -57
- package/dist/fns/aggregationFns.cjs.map +1 -1
- package/dist/fns/aggregationFns.d.cts +72 -18
- package/dist/fns/aggregationFns.d.ts +72 -18
- package/dist/fns/aggregationFns.js +126 -58
- package/dist/fns/aggregationFns.js.map +1 -1
- package/dist/fns/filterFns.cjs +253 -96
- package/dist/fns/filterFns.cjs.map +1 -1
- package/dist/fns/filterFns.d.cts +126 -94
- package/dist/fns/filterFns.d.ts +126 -94
- package/dist/fns/filterFns.js +246 -97
- package/dist/fns/filterFns.js.map +1 -1
- package/dist/fns/sortFns.cjs +68 -21
- package/dist/fns/sortFns.cjs.map +1 -1
- package/dist/fns/sortFns.d.cts +48 -15
- package/dist/fns/sortFns.d.ts +48 -15
- package/dist/fns/sortFns.js +68 -22
- package/dist/fns/sortFns.js.map +1 -1
- package/dist/helpers/tableFeatures.cjs +5 -4
- package/dist/helpers/tableFeatures.cjs.map +1 -1
- package/dist/helpers/tableFeatures.d.cts +5 -4
- package/dist/helpers/tableFeatures.d.ts +5 -4
- package/dist/helpers/tableFeatures.js +5 -4
- package/dist/helpers/tableFeatures.js.map +1 -1
- package/dist/index.cjs +12 -0
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +4 -4
- package/dist/types/TableFeatures.d.cts +15 -7
- package/dist/types/TableFeatures.d.ts +15 -7
- package/dist/types/type-utils.d.cts +8 -1
- package/dist/types/type-utils.d.ts +8 -1
- package/package.json +1 -1
- package/skills/api-not-found/SKILL.md +1 -1
- package/skills/client-vs-server/SKILL.md +1 -1
- package/skills/column-faceting/SKILL.md +11 -5
- package/skills/column-filtering/SKILL.md +8 -3
- 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 +3 -3
- package/skills/grouping/SKILL.md +8 -3
- package/skills/migrate-v8-to-v9/SKILL.md +7 -7
- 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 +9 -3
- package/skills/table-features/SKILL.md +16 -13
- package/skills/typescript/SKILL.md +1 -1
- package/src/features/column-filtering/columnFilteringFeature.types.ts +60 -0
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +33 -19
- package/src/features/column-filtering/createFilteredRowModel.ts +13 -3
- package/src/features/column-grouping/columnGroupingFeature.types.ts +63 -8
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +43 -9
- package/src/features/column-grouping/createGroupedRowModel.ts +6 -3
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +8 -0
- package/src/features/row-sorting/createSortedRowModel.ts +6 -2
- package/src/features/row-sorting/rowSortingFeature.types.ts +53 -1
- package/src/features/row-sorting/rowSortingFeature.utils.ts +45 -13
- package/src/fns/aggregationFns.ts +204 -146
- package/src/fns/filterFns.ts +361 -283
- package/src/fns/sortFns.ts +95 -78
- package/src/helpers/tableFeatures.ts +5 -4
- package/src/types/TableFeatures.ts +15 -7
- package/src/types/type-utils.ts +8 -0
|
@@ -1,30 +1,81 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AggregationFnDef,
|
|
3
|
+
CreatedAggregationFn,
|
|
4
|
+
} from '../features/column-grouping/columnGroupingFeature.types'
|
|
1
5
|
import type { RowData } from '../types/type-utils'
|
|
2
6
|
import type { TableFeatures } from '../types/TableFeatures'
|
|
3
7
|
import type { Row } from '../types/Row'
|
|
4
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Builds an `AggregationFn` from a value-level reducer plus optional
|
|
11
|
+
* `resolveDataValue` and `fromRows` settings.
|
|
12
|
+
*
|
|
13
|
+
* The `aggregate` reducer receives an array of the group rows' values, each
|
|
14
|
+
* already passed through `resolveDataValue` when one is defined. Keeping
|
|
15
|
+
* normalization in the resolver means a variant of an existing aggregation
|
|
16
|
+
* function only has to swap the resolver, not re-implement the computation.
|
|
17
|
+
*
|
|
18
|
+
* The definition is attached to the returned function, so a variant can be
|
|
19
|
+
* created by spreading a built-in aggregation function and overriding what
|
|
20
|
+
* differs. For example, a `min` that works on date columns:
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* const earliest = constructAggregationFn({
|
|
24
|
+
* ...aggregationFn_min,
|
|
25
|
+
* resolveDataValue: (value) =>
|
|
26
|
+
* value instanceof Date ? value.getTime() : value,
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* The built-in `count`, `first`, and `last` aggregation functions are plain
|
|
31
|
+
* row-level functions instead: they read group position or size and never
|
|
32
|
+
* look at every value, so materializing a values array would be wasted work.
|
|
33
|
+
*/
|
|
34
|
+
export function constructAggregationFn<
|
|
35
|
+
TFeatures extends TableFeatures = any,
|
|
36
|
+
TData extends RowData = any,
|
|
37
|
+
>(
|
|
38
|
+
def: AggregationFnDef<TFeatures, TData>,
|
|
39
|
+
): CreatedAggregationFn<TFeatures, TData> {
|
|
40
|
+
const aggregationFn: CreatedAggregationFn<TFeatures, TData> = Object.assign(
|
|
41
|
+
<TRowFeatures extends TableFeatures, TRowData extends RowData>(
|
|
42
|
+
columnId: string,
|
|
43
|
+
leafRows: Array<Row<TRowFeatures, TRowData>>,
|
|
44
|
+
childRows: Array<Row<TRowFeatures, TRowData>>,
|
|
45
|
+
): any => {
|
|
46
|
+
const rows = aggregationFn.fromRows === 'childRows' ? childRows : leafRows
|
|
47
|
+
const resolveDataValue = aggregationFn.resolveDataValue
|
|
48
|
+
const values: Array<any> = new Array(rows.length)
|
|
49
|
+
for (let i = 0; i < rows.length; i++) {
|
|
50
|
+
const value = rows[i]!.getValue(columnId)
|
|
51
|
+
values[i] = resolveDataValue ? resolveDataValue(value) : value
|
|
52
|
+
}
|
|
53
|
+
// The def's reducer is typed against the factory's TFeatures/TData;
|
|
54
|
+
// the caller's row generics are erased at this boundary.
|
|
55
|
+
return aggregationFn.aggregate(values, rows as any, columnId)
|
|
56
|
+
},
|
|
57
|
+
def,
|
|
58
|
+
)
|
|
59
|
+
return aggregationFn
|
|
60
|
+
}
|
|
61
|
+
|
|
5
62
|
/**
|
|
6
63
|
* Sums numeric child-row values for a grouped column.
|
|
7
64
|
*
|
|
8
65
|
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
9
66
|
* can reuse already aggregated values.
|
|
10
67
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
for (let i = 0; i < childRows.length; i++) {
|
|
23
|
-
const nextValue = childRows[i]!.getValue(columnId)
|
|
24
|
-
sumValue += typeof nextValue === 'number' ? nextValue : 0
|
|
25
|
-
}
|
|
26
|
-
return sumValue
|
|
27
|
-
}
|
|
68
|
+
export const aggregationFn_sum = constructAggregationFn({
|
|
69
|
+
fromRows: 'childRows',
|
|
70
|
+
aggregate: (values) => {
|
|
71
|
+
let sumValue = 0
|
|
72
|
+
for (let i = 0; i < values.length; i++) {
|
|
73
|
+
const nextValue = values[i]
|
|
74
|
+
sumValue += typeof nextValue === 'number' ? nextValue : 0
|
|
75
|
+
}
|
|
76
|
+
return sumValue
|
|
77
|
+
},
|
|
78
|
+
})
|
|
28
79
|
|
|
29
80
|
/**
|
|
30
81
|
* Finds the minimum numeric child-row value for a grouped column.
|
|
@@ -32,29 +83,24 @@ export function aggregationFn_sum<
|
|
|
32
83
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
33
84
|
* numeric value is found.
|
|
34
85
|
*/
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
typeof value === 'number' &&
|
|
50
|
-
(minValue === undefined || value < minValue)
|
|
51
|
-
) {
|
|
52
|
-
minValue = value
|
|
86
|
+
export const aggregationFn_min = constructAggregationFn({
|
|
87
|
+
fromRows: 'childRows',
|
|
88
|
+
aggregate: (values) => {
|
|
89
|
+
let minValue: number | undefined
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < values.length; i++) {
|
|
92
|
+
const value = values[i]
|
|
93
|
+
if (
|
|
94
|
+
typeof value === 'number' &&
|
|
95
|
+
(minValue === undefined || value < minValue)
|
|
96
|
+
) {
|
|
97
|
+
minValue = value
|
|
98
|
+
}
|
|
53
99
|
}
|
|
54
|
-
}
|
|
55
100
|
|
|
56
|
-
|
|
57
|
-
}
|
|
101
|
+
return minValue
|
|
102
|
+
},
|
|
103
|
+
})
|
|
58
104
|
|
|
59
105
|
/**
|
|
60
106
|
* Finds the maximum numeric child-row value for a grouped column.
|
|
@@ -62,28 +108,24 @@ export function aggregationFn_min<
|
|
|
62
108
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
63
109
|
* numeric value is found.
|
|
64
110
|
*/
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
typeof value === 'number' &&
|
|
79
|
-
(maxValue === undefined || value > maxValue)
|
|
80
|
-
) {
|
|
81
|
-
maxValue = value
|
|
111
|
+
export const aggregationFn_max = constructAggregationFn({
|
|
112
|
+
fromRows: 'childRows',
|
|
113
|
+
aggregate: (values) => {
|
|
114
|
+
let maxValue: number | undefined
|
|
115
|
+
|
|
116
|
+
for (let i = 0; i < values.length; i++) {
|
|
117
|
+
const value = values[i]
|
|
118
|
+
if (
|
|
119
|
+
typeof value === 'number' &&
|
|
120
|
+
(maxValue === undefined || value > maxValue)
|
|
121
|
+
) {
|
|
122
|
+
maxValue = value
|
|
123
|
+
}
|
|
82
124
|
}
|
|
83
|
-
}
|
|
84
125
|
|
|
85
|
-
|
|
86
|
-
}
|
|
126
|
+
return maxValue
|
|
127
|
+
},
|
|
128
|
+
})
|
|
87
129
|
|
|
88
130
|
/**
|
|
89
131
|
* Finds the numeric extent for a grouped column.
|
|
@@ -91,31 +133,27 @@ export function aggregationFn_max<
|
|
|
91
133
|
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
92
134
|
* present.
|
|
93
135
|
*/
|
|
94
|
-
export
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
minValue = maxValue = value
|
|
110
|
-
} else {
|
|
111
|
-
if (minValue > value) minValue = value
|
|
112
|
-
if (maxValue! < value) maxValue = value
|
|
136
|
+
export const aggregationFn_extent = constructAggregationFn({
|
|
137
|
+
fromRows: 'childRows',
|
|
138
|
+
aggregate: (values) => {
|
|
139
|
+
let minValue: number | undefined
|
|
140
|
+
let maxValue: number | undefined
|
|
141
|
+
|
|
142
|
+
for (let i = 0; i < values.length; i++) {
|
|
143
|
+
const value = values[i]
|
|
144
|
+
if (typeof value === 'number') {
|
|
145
|
+
if (minValue === undefined) {
|
|
146
|
+
minValue = maxValue = value
|
|
147
|
+
} else {
|
|
148
|
+
if (minValue > value) minValue = value
|
|
149
|
+
if (maxValue! < value) maxValue = value
|
|
150
|
+
}
|
|
113
151
|
}
|
|
114
152
|
}
|
|
115
|
-
}
|
|
116
153
|
|
|
117
|
-
|
|
118
|
-
}
|
|
154
|
+
return [minValue, maxValue]
|
|
155
|
+
},
|
|
156
|
+
})
|
|
119
157
|
|
|
120
158
|
/**
|
|
121
159
|
* Averages numeric leaf-row values for a grouped column.
|
|
@@ -123,31 +161,30 @@ export function aggregationFn_extent<
|
|
|
123
161
|
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
124
162
|
* are ignored.
|
|
125
163
|
*/
|
|
126
|
-
export
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const value = leafRows[i]!.getValue(columnId)
|
|
135
|
-
if (value != null && typeof value === 'number') {
|
|
136
|
-
++count
|
|
137
|
-
sumValue += value
|
|
138
|
-
} else if (value != null) {
|
|
139
|
-
const numValue = +value
|
|
140
|
-
if (!Number.isNaN(numValue)) {
|
|
164
|
+
export const aggregationFn_mean = constructAggregationFn({
|
|
165
|
+
aggregate: (values) => {
|
|
166
|
+
let count = 0
|
|
167
|
+
let sumValue = 0
|
|
168
|
+
|
|
169
|
+
for (let i = 0; i < values.length; i++) {
|
|
170
|
+
const value = values[i]
|
|
171
|
+
if (value != null && typeof value === 'number') {
|
|
141
172
|
++count
|
|
142
|
-
sumValue +=
|
|
173
|
+
sumValue += value
|
|
174
|
+
} else if (value != null) {
|
|
175
|
+
const numValue = +value
|
|
176
|
+
if (!Number.isNaN(numValue)) {
|
|
177
|
+
++count
|
|
178
|
+
sumValue += numValue
|
|
179
|
+
}
|
|
143
180
|
}
|
|
144
181
|
}
|
|
145
|
-
}
|
|
146
182
|
|
|
147
|
-
|
|
183
|
+
if (count) return sumValue / count
|
|
148
184
|
|
|
149
|
-
|
|
150
|
-
}
|
|
185
|
+
return
|
|
186
|
+
},
|
|
187
|
+
})
|
|
151
188
|
|
|
152
189
|
/**
|
|
153
190
|
* Computes the median of numeric leaf-row values for a grouped column.
|
|
@@ -155,68 +192,52 @@ export function aggregationFn_mean<
|
|
|
155
192
|
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
156
193
|
* present, the result is `undefined`.
|
|
157
194
|
*/
|
|
158
|
-
export
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return values
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return values.length % 2 !== 0
|
|
180
|
-
? values[mid]
|
|
181
|
-
: (values[mid - 1]! + values[mid]!) / 2
|
|
182
|
-
}
|
|
195
|
+
export const aggregationFn_median = constructAggregationFn({
|
|
196
|
+
aggregate: (values: Array<number>) => {
|
|
197
|
+
if (!values.length) {
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
for (let i = 0; i < values.length; i++) {
|
|
202
|
+
if (typeof values[i] !== 'number') return
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (values.length === 1) {
|
|
206
|
+
return values[0]
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const mid = Math.floor(values.length / 2)
|
|
210
|
+
values.sort((a, b) => a - b)
|
|
211
|
+
return values.length % 2 !== 0
|
|
212
|
+
? values[mid]
|
|
213
|
+
: (values[mid - 1]! + values[mid]!) / 2
|
|
214
|
+
},
|
|
215
|
+
})
|
|
183
216
|
|
|
184
217
|
/**
|
|
185
218
|
* Collects unique leaf-row values for a grouped column.
|
|
186
219
|
*
|
|
187
220
|
* Values are compared with JavaScript `Set` semantics.
|
|
188
221
|
*/
|
|
189
|
-
export
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {
|
|
193
|
-
const set = new Set<unknown>()
|
|
194
|
-
for (let i = 0; i < leafRows.length; i++) {
|
|
195
|
-
set.add(leafRows[i]!.getValue(columnId))
|
|
196
|
-
}
|
|
197
|
-
return Array.from(set.values())
|
|
198
|
-
}
|
|
222
|
+
export const aggregationFn_unique = constructAggregationFn({
|
|
223
|
+
aggregate: (values) => Array.from(new Set(values).values()),
|
|
224
|
+
})
|
|
199
225
|
|
|
200
226
|
/**
|
|
201
227
|
* Counts unique leaf-row values for a grouped column.
|
|
202
228
|
*
|
|
203
229
|
* Values are compared with JavaScript `Set` semantics.
|
|
204
230
|
*/
|
|
205
|
-
export
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {
|
|
209
|
-
const set = new Set<unknown>()
|
|
210
|
-
for (let i = 0; i < leafRows.length; i++) {
|
|
211
|
-
set.add(leafRows[i]!.getValue(columnId))
|
|
212
|
-
}
|
|
213
|
-
return set.size
|
|
214
|
-
}
|
|
231
|
+
export const aggregationFn_uniqueCount = constructAggregationFn({
|
|
232
|
+
aggregate: (values) => new Set(values).size,
|
|
233
|
+
})
|
|
215
234
|
|
|
216
235
|
/**
|
|
217
236
|
* Counts the number of leaf rows in the group.
|
|
218
237
|
*
|
|
219
238
|
* The column id is ignored because the result is based only on group size.
|
|
239
|
+
* This is a plain row-level function (not built with
|
|
240
|
+
* `constructAggregationFn`) because it never reads row values.
|
|
220
241
|
*/
|
|
221
242
|
export function aggregationFn_count<
|
|
222
243
|
TFeatures extends TableFeatures,
|
|
@@ -225,10 +246,45 @@ export function aggregationFn_count<
|
|
|
225
246
|
return leafRows.length
|
|
226
247
|
}
|
|
227
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Returns the first leaf-row value for a grouped column.
|
|
251
|
+
*
|
|
252
|
+
* This is a plain row-level function (not built with
|
|
253
|
+
* `constructAggregationFn`) because it only reads one positional value.
|
|
254
|
+
*/
|
|
255
|
+
export function aggregationFn_first<
|
|
256
|
+
TFeatures extends TableFeatures,
|
|
257
|
+
TData extends RowData,
|
|
258
|
+
>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {
|
|
259
|
+
return leafRows[0]?.getValue(columnId)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Returns the last leaf-row value for a grouped column.
|
|
264
|
+
*
|
|
265
|
+
* This is a plain row-level function (not built with
|
|
266
|
+
* `constructAggregationFn`) because it only reads one positional value.
|
|
267
|
+
*/
|
|
268
|
+
export function aggregationFn_last<
|
|
269
|
+
TFeatures extends TableFeatures,
|
|
270
|
+
TData extends RowData,
|
|
271
|
+
>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {
|
|
272
|
+
return leafRows[leafRows.length - 1]?.getValue(columnId)
|
|
273
|
+
}
|
|
274
|
+
|
|
228
275
|
/**
|
|
229
276
|
* The built-in aggregation function registry.
|
|
230
277
|
*
|
|
231
|
-
*
|
|
278
|
+
* Registering this full object opts out of tree-shaking: every built-in
|
|
279
|
+
* aggregation function ends up in your bundle. Prefer importing the
|
|
280
|
+
* `aggregationFn_*` functions you actually use and registering just those in
|
|
281
|
+
* the `aggregationFns` slot, or passing them directly to the `aggregationFn`
|
|
282
|
+
* column option.
|
|
283
|
+
*
|
|
284
|
+
* @deprecated Import individual `aggregationFn_*` functions instead for a
|
|
285
|
+
* smaller bundle. This export still works and is not going away in v9, but
|
|
286
|
+
* built-in name resolution (including `aggregationFn: 'auto'`) only finds
|
|
287
|
+
* functions you register yourself.
|
|
232
288
|
*/
|
|
233
289
|
export const aggregationFns = {
|
|
234
290
|
sum: aggregationFn_sum,
|
|
@@ -240,6 +296,8 @@ export const aggregationFns = {
|
|
|
240
296
|
unique: aggregationFn_unique,
|
|
241
297
|
uniqueCount: aggregationFn_uniqueCount,
|
|
242
298
|
count: aggregationFn_count,
|
|
299
|
+
first: aggregationFn_first,
|
|
300
|
+
last: aggregationFn_last,
|
|
243
301
|
}
|
|
244
302
|
|
|
245
303
|
export type BuiltInAggregationFn = keyof typeof aggregationFns
|