@tanstack/table-core 9.0.0-beta.47 → 9.0.0-beta.48
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/row-models/coreRowModelsFeature.types.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
- package/dist/features/aggregation/aggregationFeature.cjs +38 -0
- package/dist/features/aggregation/aggregationFeature.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.d.cts +10 -0
- package/dist/features/aggregation/aggregationFeature.d.ts +10 -0
- package/dist/features/aggregation/aggregationFeature.js +38 -0
- package/dist/features/aggregation/aggregationFeature.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs +13 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.d.cts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.d.ts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.js +12 -0
- package/dist/features/aggregation/aggregationFeature.types.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs +198 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.cts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.ts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.js +192 -0
- package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -0
- package/dist/features/aggregation/aggregationFns.cjs +240 -0
- package/dist/features/aggregation/aggregationFns.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFns.d.cts +67 -0
- package/dist/features/aggregation/aggregationFns.d.ts +67 -0
- package/dist/features/aggregation/aggregationFns.js +229 -0
- package/dist/features/aggregation/aggregationFns.js.map +1 -0
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +1 -1
- package/dist/{fns → features/column-filtering}/filterFns.cjs +1 -1
- package/dist/features/column-filtering/filterFns.cjs.map +1 -0
- package/dist/{fns → features/column-filtering}/filterFns.d.cts +4 -4
- package/dist/{fns → features/column-filtering}/filterFns.d.ts +4 -4
- package/dist/{fns → features/column-filtering}/filterFns.js +1 -1
- package/dist/features/column-filtering/filterFns.js.map +1 -0
- package/dist/features/column-grouping/columnGroupingFeature.cjs +3 -12
- package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.cts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.ts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.js +4 -13
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +6 -87
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -87
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -64
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -44
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -44
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -63
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -16
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -6
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -6
- package/dist/features/column-grouping/createGroupedRowModel.js +25 -18
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/{fns → features/row-sorting}/sortFns.cjs +1 -1
- package/dist/{fns/sortFns.js.map → features/row-sorting/sortFns.cjs.map} +1 -1
- package/dist/{fns → features/row-sorting}/sortFns.d.cts +4 -4
- package/dist/{fns → features/row-sorting}/sortFns.d.ts +4 -4
- package/dist/{fns → features/row-sorting}/sortFns.js +1 -1
- package/dist/features/row-sorting/sortFns.js.map +1 -0
- package/dist/features/stockFeatures.cjs +2 -0
- package/dist/features/stockFeatures.cjs.map +1 -1
- package/dist/features/stockFeatures.d.cts +2 -0
- package/dist/features/stockFeatures.d.ts +2 -0
- package/dist/features/stockFeatures.js +2 -0
- package/dist/features/stockFeatures.js.map +1 -1
- package/dist/index.cjs +7 -4
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +6 -4
- package/dist/static-functions.cjs +8 -3
- package/dist/static-functions.d.cts +3 -2
- package/dist/static-functions.d.ts +3 -2
- package/dist/static-functions.js +3 -2
- package/dist/types/Cell.d.cts +3 -1
- package/dist/types/Cell.d.ts +3 -1
- package/dist/types/Column.d.cts +4 -2
- package/dist/types/Column.d.ts +4 -2
- package/dist/types/ColumnDef.d.cts +5 -3
- package/dist/types/ColumnDef.d.ts +5 -3
- package/dist/types/Row.d.cts +3 -1
- package/dist/types/Row.d.ts +3 -1
- package/dist/types/RowModel.d.cts +1 -1
- package/dist/types/RowModel.d.ts +1 -1
- package/dist/types/RowModelFns.d.cts +3 -3
- package/dist/types/RowModelFns.d.ts +3 -3
- package/dist/types/Table.d.cts +1 -1
- package/dist/types/Table.d.ts +1 -1
- package/dist/types/TableFeatures.d.cts +4 -4
- package/dist/types/TableFeatures.d.ts +4 -4
- package/dist/types/TableOptions.d.cts +5 -3
- package/dist/types/TableOptions.d.ts +5 -3
- package/dist/types/TableState.d.cts +1 -1
- package/dist/types/TableState.d.ts +1 -1
- package/dist/worker/initTableWorker.cjs.map +1 -1
- package/dist/worker/initTableWorker.js.map +1 -1
- package/package.json +1 -1
- package/skills/aggregation/SKILL.md +131 -0
- 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 +12 -18
- package/skills/migrate-v8-to-v9/SKILL.md +15 -2
- 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 +5 -2
- package/skills/typescript/SKILL.md +1 -1
- package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
- package/src/features/aggregation/aggregationFeature.ts +59 -0
- package/src/features/aggregation/aggregationFeature.types.ts +312 -0
- package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
- package/src/features/aggregation/aggregationFns.ts +336 -0
- package/src/features/column-filtering/columnFilteringFeature.types.ts +1 -1
- package/src/{fns → features/column-filtering}/filterFns.ts +4 -4
- package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
- package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -141
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -122
- package/src/features/column-grouping/createGroupedRowModel.ts +32 -41
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +1 -1
- package/src/features/row-sorting/rowSortingFeature.types.ts +1 -1
- package/src/features/row-sorting/rowSortingFeature.utils.ts +1 -1
- package/src/{fns → features/row-sorting}/sortFns.ts +4 -7
- package/src/features/stockFeatures.ts +3 -0
- package/src/index.ts +7 -8
- package/src/static-functions.ts +1 -0
- package/src/types/Cell.ts +2 -0
- package/src/types/Column.ts +3 -1
- package/src/types/ColumnDef.ts +6 -3
- package/src/types/Row.ts +2 -0
- package/src/types/RowModelFns.ts +3 -3
- package/src/types/TableFeatures.ts +4 -4
- package/src/types/TableOptions.ts +5 -1
- package/src/worker/initTableWorker.ts +1 -1
- package/dist/fns/aggregationFns.cjs +0 -234
- package/dist/fns/aggregationFns.cjs.map +0 -1
- package/dist/fns/aggregationFns.d.cts +0 -139
- package/dist/fns/aggregationFns.d.ts +0 -139
- package/dist/fns/aggregationFns.js +0 -221
- package/dist/fns/aggregationFns.js.map +0 -1
- package/dist/fns/filterFns.cjs.map +0 -1
- package/dist/fns/filterFns.js.map +0 -1
- package/dist/fns/sortFns.cjs.map +0 -1
- package/src/fns/aggregationFns.ts +0 -303
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cloneState, hasOwn
|
|
1
|
+
import { cloneState, hasOwn } from '../../utils'
|
|
2
2
|
import type { Column_Internal } from '../../types/Column'
|
|
3
3
|
import type { CellData, RowData, Updater } from '../../types/type-utils'
|
|
4
4
|
import type { TableFeatures } from '../../types/TableFeatures'
|
|
@@ -6,7 +6,6 @@ import type { Table_Internal } from '../../types/Table'
|
|
|
6
6
|
import type { Row } from '../../types/Row'
|
|
7
7
|
import type { Cell } from '../../types/Cell'
|
|
8
8
|
import type {
|
|
9
|
-
AggregationFn,
|
|
10
9
|
GroupingState,
|
|
11
10
|
Row_ColumnGrouping,
|
|
12
11
|
} from './columnGroupingFeature.types'
|
|
@@ -135,103 +134,6 @@ export function column_getToggleGroupingHandler<
|
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
/**
|
|
139
|
-
* Chooses a built-in aggregation function from the first core row value.
|
|
140
|
-
*
|
|
141
|
-
* Numeric columns default to `sum`, date-like values default to `extent`, and
|
|
142
|
-
* other value types leave aggregation unspecified.
|
|
143
|
-
*
|
|
144
|
-
* The chosen aggregation function is looked up in the table's
|
|
145
|
-
* `aggregationFns` registry. When it is not registered there, this returns
|
|
146
|
-
* `undefined` and warns in development instead of substituting a different
|
|
147
|
-
* aggregation function.
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* ```ts
|
|
151
|
-
* const aggregationFn = column_getAutoAggregationFn(column)
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
export function column_getAutoAggregationFn<
|
|
155
|
-
TFeatures extends TableFeatures,
|
|
156
|
-
TData extends RowData,
|
|
157
|
-
TValue extends CellData = CellData,
|
|
158
|
-
>(column: Column_Internal<TFeatures, TData, TValue>) {
|
|
159
|
-
const aggregationFns:
|
|
160
|
-
| Record<string, AggregationFn<TFeatures, TData>>
|
|
161
|
-
| undefined = column.table._rowModelFns.aggregationFns
|
|
162
|
-
|
|
163
|
-
const firstRow = column.table.getCoreRowModel().flatRows[0]
|
|
164
|
-
|
|
165
|
-
const value = firstRow?.getValue(column.id)
|
|
166
|
-
|
|
167
|
-
let aggregationFnName: string | undefined
|
|
168
|
-
|
|
169
|
-
if (typeof value === 'number') {
|
|
170
|
-
aggregationFnName = 'sum'
|
|
171
|
-
} else if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
172
|
-
aggregationFnName = 'extent'
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (!aggregationFnName) {
|
|
176
|
-
return undefined
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const aggregationFn = aggregationFns?.[aggregationFnName]
|
|
180
|
-
|
|
181
|
-
if (process.env.NODE_ENV === 'development' && !aggregationFn) {
|
|
182
|
-
console.warn(
|
|
183
|
-
`aggregationFn '${aggregationFnName}' (auto) for column '${column.id}' is not registered`,
|
|
184
|
-
)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return aggregationFn
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Resolves the aggregation function configured for a column.
|
|
192
|
-
*
|
|
193
|
-
* Function-valued `columnDef.aggregationFn` is returned directly, `'auto'`
|
|
194
|
-
* delegates to `column_getAutoAggregationFn`, and string values are looked up in
|
|
195
|
-
* the table's aggregation function registry.
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```ts
|
|
199
|
-
* const aggregationFn = column_getAggregationFn(column)
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
|
-
export function column_getAggregationFn<
|
|
203
|
-
TFeatures extends TableFeatures,
|
|
204
|
-
TData extends RowData,
|
|
205
|
-
TValue extends CellData = CellData,
|
|
206
|
-
>(column: Column_Internal<TFeatures, TData, TValue>) {
|
|
207
|
-
const aggregationFns:
|
|
208
|
-
| Record<string, AggregationFn<TFeatures, TData>>
|
|
209
|
-
| undefined = column.table._rowModelFns.aggregationFns
|
|
210
|
-
|
|
211
|
-
if (isFunction(column.columnDef.aggregationFn)) {
|
|
212
|
-
return column.columnDef.aggregationFn
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (column.columnDef.aggregationFn === 'auto') {
|
|
216
|
-
return column_getAutoAggregationFn(column)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const aggregationFn =
|
|
220
|
-
aggregationFns?.[column.columnDef.aggregationFn as string]
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
process.env.NODE_ENV === 'development' &&
|
|
224
|
-
!aggregationFn &&
|
|
225
|
-
column.columnDef.aggregationFn != null
|
|
226
|
-
) {
|
|
227
|
-
console.warn(
|
|
228
|
-
`aggregationFn '${String(column.columnDef.aggregationFn)}' for column '${column.id}' is not registered`,
|
|
229
|
-
)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return aggregationFn
|
|
233
|
-
}
|
|
234
|
-
|
|
235
137
|
/**
|
|
236
138
|
* Routes a grouping updater through the table's grouping change handler.
|
|
237
139
|
*
|
|
@@ -367,26 +269,3 @@ export function cell_getIsPlaceholder<
|
|
|
367
269
|
>(cell: Cell<TFeatures, TData, TValue>) {
|
|
368
270
|
return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column)
|
|
369
271
|
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Checks whether this cell should render an aggregated value.
|
|
373
|
-
*
|
|
374
|
-
* Aggregated cells are non-placeholder, non-grouped cells on rows that have
|
|
375
|
-
* subRows.
|
|
376
|
-
*
|
|
377
|
-
* @example
|
|
378
|
-
* ```ts
|
|
379
|
-
* const isAggregated = cell_getIsAggregated(cell)
|
|
380
|
-
* ```
|
|
381
|
-
*/
|
|
382
|
-
export function cell_getIsAggregated<
|
|
383
|
-
TFeatures extends TableFeatures,
|
|
384
|
-
TData extends RowData,
|
|
385
|
-
TValue extends CellData = CellData,
|
|
386
|
-
>(cell: Cell<TFeatures, TData, TValue>) {
|
|
387
|
-
return (
|
|
388
|
-
!cell_getIsGrouped(cell) &&
|
|
389
|
-
!cell_getIsPlaceholder(cell) &&
|
|
390
|
-
!!cell.row.subRows.length
|
|
391
|
-
)
|
|
392
|
-
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasOwn, makeObjectMap, tableMemo } from '../../utils'
|
|
2
2
|
import { constructRow } from '../../core/rows/constructRow'
|
|
3
3
|
import { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'
|
|
4
4
|
import { table_autoResetExpanded } from '../row-expanding/rowExpandingFeature.utils'
|
|
5
5
|
import { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from '
|
|
10
|
-
import
|
|
7
|
+
aggregateColumnValue,
|
|
8
|
+
normalizeAggregationRows,
|
|
9
|
+
} from '../aggregation/aggregationFeature.utils'
|
|
10
|
+
import { row_getGroupingValue } from './columnGroupingFeature.utils'
|
|
11
11
|
import type { Row_ColumnGrouping } from './columnGroupingFeature.types'
|
|
12
12
|
import type { TableFeatures } from '../../types/TableFeatures'
|
|
13
13
|
import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'
|
|
@@ -20,12 +20,8 @@ import type { RowData } from '../../types/type-utils'
|
|
|
20
20
|
*
|
|
21
21
|
* The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns: { sum: aggregationFn_sum } })`.
|
|
26
|
-
* Importing individual `aggregationFn_*` functions keeps unused built-ins out
|
|
27
|
-
* of your bundle; aggregation functions passed directly to the
|
|
28
|
-
* `aggregationFn` column option need no registration at all.
|
|
23
|
+
* When aggregationFeature is also registered, grouped rows use its shared
|
|
24
|
+
* executor for non-group values. Grouping remains useful without aggregation.
|
|
29
25
|
*/
|
|
30
26
|
export function createGroupedRowModel<
|
|
31
27
|
TFeatures extends TableFeatures,
|
|
@@ -40,6 +36,7 @@ export function createGroupedRowModel<
|
|
|
40
36
|
memoDeps: () => [
|
|
41
37
|
table.atoms.grouping?.get(),
|
|
42
38
|
table.getPreGroupedRowModel(),
|
|
39
|
+
table.options.columns,
|
|
43
40
|
],
|
|
44
41
|
fn: () => _createGroupedRowModel(table),
|
|
45
42
|
onAfterUpdate: () => {
|
|
@@ -121,10 +118,7 @@ function _createGroupedRowModel<
|
|
|
121
118
|
subRow.parentId = id
|
|
122
119
|
})
|
|
123
120
|
|
|
124
|
-
|
|
125
|
-
const leafRows = depth
|
|
126
|
-
? flattenBy(groupedRows, (row) => row.subRows)
|
|
127
|
-
: groupedRows
|
|
121
|
+
const leafRows = normalizeAggregationRows(groupedRows)
|
|
128
122
|
|
|
129
123
|
const row = constructRow(
|
|
130
124
|
table,
|
|
@@ -142,8 +136,12 @@ function _createGroupedRowModel<
|
|
|
142
136
|
subRows,
|
|
143
137
|
leafRows,
|
|
144
138
|
getValue: (colId: string) => {
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
const groupingIndex = existingGrouping.indexOf(colId)
|
|
140
|
+
|
|
141
|
+
// The active grouping column and ancestor grouping columns expose
|
|
142
|
+
// their inherited grouping values. Columns grouped at deeper
|
|
143
|
+
// levels are still eligible for aggregation here.
|
|
144
|
+
if (groupingIndex !== -1 && groupingIndex <= depth) {
|
|
147
145
|
if (hasOwn(row._valuesCache, colId)) {
|
|
148
146
|
return row._valuesCache[colId]
|
|
149
147
|
}
|
|
@@ -156,32 +154,25 @@ function _createGroupedRowModel<
|
|
|
156
154
|
return row._valuesCache[colId]
|
|
157
155
|
}
|
|
158
156
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
) {
|
|
163
|
-
return
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Aggregate the values
|
|
167
|
-
const column = table.getColumn(colId)
|
|
168
|
-
const aggregateFn = column_getAggregationFn(
|
|
169
|
-
column as Column<TFeatures, TData, unknown>,
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
if (!row._groupingValuesCache) {
|
|
173
|
-
row._groupingValuesCache = makeObjectMap()
|
|
157
|
+
const aggregationCache = (row as any)._aggregationValuesCache as
|
|
158
|
+
| Record<string, unknown>
|
|
159
|
+
| undefined
|
|
160
|
+
if (aggregationCache && hasOwn(aggregationCache, colId)) {
|
|
161
|
+
return aggregationCache[colId]
|
|
174
162
|
}
|
|
175
163
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
164
|
+
const column = table.getColumn(colId) as any
|
|
165
|
+
if (typeof column.getAggregationFns !== 'function') return undefined
|
|
166
|
+
|
|
167
|
+
const cache = ((row as any)._aggregationValuesCache ??=
|
|
168
|
+
makeObjectMap())
|
|
169
|
+
cache[colId] = aggregateColumnValue({
|
|
170
|
+
childRows: subRows,
|
|
171
|
+
column,
|
|
172
|
+
groupingRow: row,
|
|
173
|
+
rows: leafRows,
|
|
174
|
+
})
|
|
175
|
+
return cache[colId]
|
|
185
176
|
},
|
|
186
177
|
})
|
|
187
178
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { filterFn_includesString } from '
|
|
1
|
+
import { filterFn_includesString } from '../column-filtering/filterFns'
|
|
2
2
|
import { cloneState, isFunction } from '../../utils'
|
|
3
3
|
import type { Column_Internal } from '../../types/Column'
|
|
4
4
|
import type { FilterFn } from '../column-filtering/columnFilteringFeature.types'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { reSplitAlphaNumeric, sortFn_basic } from '../../fns/sortFns'
|
|
2
1
|
import { cloneState, isFunction } from '../../utils'
|
|
2
|
+
import { reSplitAlphaNumeric, sortFn_basic } from './sortFns'
|
|
3
3
|
import type { CellData, RowData, Updater } from '../../types/type-utils'
|
|
4
4
|
import type { TableFeatures } from '../../types/TableFeatures'
|
|
5
5
|
import type { Table_Internal } from '../../types/Table'
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '
|
|
5
|
-
import type { RowData } from '../types/type-utils'
|
|
6
|
-
import type { TableFeatures } from '../types/TableFeatures'
|
|
7
|
-
import type { Row } from '../types/Row'
|
|
1
|
+
import type { CreatedSortFn, SortFnDef } from './rowSortingFeature.types'
|
|
2
|
+
import type { RowData } from '../../types/type-utils'
|
|
3
|
+
import type { TableFeatures } from '../../types/TableFeatures'
|
|
4
|
+
import type { Row } from '../../types/Row'
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Regular expression used to split mixed text and numeric chunks.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { columnFacetingFeature } from './column-faceting/columnFacetingFeature'
|
|
2
|
+
import { aggregationFeature } from './aggregation/aggregationFeature'
|
|
2
3
|
import { columnFilteringFeature } from './column-filtering/columnFilteringFeature'
|
|
3
4
|
import { columnGroupingFeature } from './column-grouping/columnGroupingFeature'
|
|
4
5
|
import { columnOrderingFeature } from './column-ordering/columnOrderingFeature'
|
|
@@ -14,6 +15,7 @@ import { rowSelectionFeature } from './row-selection/rowSelectionFeature'
|
|
|
14
15
|
import { rowSortingFeature } from './row-sorting/rowSortingFeature'
|
|
15
16
|
|
|
16
17
|
export interface StockFeatures {
|
|
18
|
+
aggregationFeature: typeof aggregationFeature
|
|
17
19
|
columnFacetingFeature: typeof columnFacetingFeature
|
|
18
20
|
columnFilteringFeature: typeof columnFilteringFeature
|
|
19
21
|
columnGroupingFeature: typeof columnGroupingFeature
|
|
@@ -36,6 +38,7 @@ export interface StockFeatures {
|
|
|
36
38
|
* Use individual feature exports for tree-shaking, or this aggregate when a table should include every built-in feature.
|
|
37
39
|
*/
|
|
38
40
|
export const stockFeatures: StockFeatures = {
|
|
41
|
+
aggregationFeature,
|
|
39
42
|
columnFacetingFeature,
|
|
40
43
|
columnFilteringFeature,
|
|
41
44
|
columnGroupingFeature,
|
package/src/index.ts
CHANGED
|
@@ -58,20 +58,17 @@ export * from './core/table/constructTable'
|
|
|
58
58
|
export * from './core/table/coreTablesFeature'
|
|
59
59
|
export * from './core/table/coreTablesFeature.types'
|
|
60
60
|
|
|
61
|
-
/**
|
|
62
|
-
* RowModelFns
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
export * from './fns/aggregationFns'
|
|
66
|
-
export * from './fns/filterFns'
|
|
67
|
-
export * from './fns/sortFns'
|
|
68
|
-
|
|
69
61
|
/**
|
|
70
62
|
* Features
|
|
71
63
|
*/
|
|
72
64
|
|
|
73
65
|
export * from './features/stockFeatures'
|
|
74
66
|
|
|
67
|
+
// aggregationFeature
|
|
68
|
+
export * from './features/aggregation/aggregationFeature'
|
|
69
|
+
export * from './features/aggregation/aggregationFeature.types'
|
|
70
|
+
export * from './features/aggregation/aggregationFns'
|
|
71
|
+
|
|
75
72
|
// columnFacetingFeature
|
|
76
73
|
export * from './features/column-faceting/columnFacetingFeature'
|
|
77
74
|
export * from './features/column-faceting/columnFacetingFeature.types'
|
|
@@ -83,6 +80,7 @@ export * from './features/column-faceting/createFacetedUniqueValues'
|
|
|
83
80
|
export * from './features/column-filtering/columnFilteringFeature'
|
|
84
81
|
export * from './features/column-filtering/columnFilteringFeature.types'
|
|
85
82
|
export * from './features/column-filtering/createFilteredRowModel'
|
|
83
|
+
export * from './features/column-filtering/filterFns'
|
|
86
84
|
|
|
87
85
|
// columnGroupingFeature
|
|
88
86
|
export * from './features/column-grouping/columnGroupingFeature'
|
|
@@ -135,5 +133,6 @@ export * from './features/row-selection/rowSelectionFeature.types'
|
|
|
135
133
|
export * from './features/row-sorting/rowSortingFeature'
|
|
136
134
|
export * from './features/row-sorting/rowSortingFeature.types'
|
|
137
135
|
export * from './features/row-sorting/createSortedRowModel'
|
|
136
|
+
export * from './features/row-sorting/sortFns'
|
|
138
137
|
|
|
139
138
|
// force
|
package/src/static-functions.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './core/row-models/coreRowModelsFeature.utils'
|
|
|
15
15
|
export * from './core/table/coreTablesFeature.utils'
|
|
16
16
|
|
|
17
17
|
// Features
|
|
18
|
+
export * from './features/aggregation/aggregationFeature.utils'
|
|
18
19
|
export * from './features/column-faceting/columnFacetingFeature.utils'
|
|
19
20
|
export * from './features/column-filtering/columnFilteringFeature.utils'
|
|
20
21
|
export * from './features/column-grouping/columnGroupingFeature.utils'
|
package/src/types/Cell.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Cell_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
2
|
+
import type { Cell_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
2
3
|
import type { CellData, RowData } from './type-utils'
|
|
3
4
|
import type { ExtractFeatureMapTypes, TableFeatures } from './TableFeatures'
|
|
4
5
|
import type { Cell_Cell } from '../core/cells/coreCellsFeature.types'
|
|
@@ -10,6 +11,7 @@ export interface Cell_Core<
|
|
|
10
11
|
> extends Cell_Cell<TFeatures, TData, TValue> {}
|
|
11
12
|
|
|
12
13
|
export interface Cell_FeatureMap {
|
|
14
|
+
aggregationFeature: Cell_Aggregation
|
|
13
15
|
columnGroupingFeature: Cell_ColumnGrouping
|
|
14
16
|
}
|
|
15
17
|
|
package/src/types/Column.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Table_Internal } from './Table'
|
|
2
2
|
import type { Column_RowSorting } from '../features/row-sorting/rowSortingFeature.types'
|
|
3
|
+
import type { Column_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
3
4
|
import type { Column_ColumnFaceting } from '../features/column-faceting/columnFacetingFeature.types'
|
|
4
5
|
import type { Column_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
5
6
|
import type { Column_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
@@ -24,9 +25,10 @@ export interface Column_FeatureMap<
|
|
|
24
25
|
in out TFeatures extends TableFeatures,
|
|
25
26
|
in out TData extends RowData,
|
|
26
27
|
> {
|
|
28
|
+
aggregationFeature: Column_Aggregation<TFeatures, TData>
|
|
27
29
|
columnFacetingFeature: Column_ColumnFaceting<TFeatures, TData>
|
|
28
30
|
columnFilteringFeature: Column_ColumnFiltering<TFeatures, TData>
|
|
29
|
-
columnGroupingFeature: Column_ColumnGrouping
|
|
31
|
+
columnGroupingFeature: Column_ColumnGrouping
|
|
30
32
|
columnOrderingFeature: Column_ColumnOrdering
|
|
31
33
|
columnPinningFeature: Column_ColumnPinning
|
|
32
34
|
columnResizingFeature: Column_ColumnResizing
|
package/src/types/ColumnDef.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
import type { CellContext } from '../core/cells/coreCellsFeature.types'
|
|
8
8
|
import type { HeaderContext } from '../core/headers/coreHeadersFeature.types'
|
|
9
9
|
import type { ColumnDef_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
10
|
+
import type { ColumnDef_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
10
11
|
import type { ColumnDef_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
11
12
|
import type { ColumnDef_ColumnPinning } from '../features/column-pinning/columnPinningFeature.types'
|
|
12
13
|
import type { ColumnDef_ColumnResizing } from '../features/column-resizing/columnResizingFeature.types'
|
|
@@ -132,12 +133,13 @@ export interface ColumnDef_FeatureMap<
|
|
|
132
133
|
in out TData extends RowData,
|
|
133
134
|
TValue extends CellData,
|
|
134
135
|
> {
|
|
136
|
+
aggregationFeature: ColumnDef_Aggregation<TFeatures, TData, TValue>
|
|
135
137
|
columnVisibilityFeature: ColumnDef_ColumnVisibility
|
|
136
138
|
columnPinningFeature: ColumnDef_ColumnPinning
|
|
137
139
|
columnFilteringFeature: ColumnDef_ColumnFiltering<TFeatures, TData>
|
|
138
140
|
globalFilteringFeature: ColumnDef_GlobalFiltering
|
|
139
141
|
rowSortingFeature: ColumnDef_RowSorting<TFeatures, TData>
|
|
140
|
-
columnGroupingFeature: ColumnDef_ColumnGrouping<TFeatures, TData
|
|
142
|
+
columnGroupingFeature: ColumnDef_ColumnGrouping<TFeatures, TData>
|
|
141
143
|
columnSizingFeature: ColumnDef_ColumnSizing
|
|
142
144
|
columnResizingFeature: ColumnDef_ColumnResizing
|
|
143
145
|
}
|
|
@@ -158,12 +160,13 @@ export type ColumnDefBase_All<
|
|
|
158
160
|
TValue extends CellData = CellData,
|
|
159
161
|
> = ColumnDefBase_Core<TFeatures, TData, TValue> &
|
|
160
162
|
Partial<
|
|
161
|
-
|
|
163
|
+
ColumnDef_Aggregation<TFeatures, TData, TValue> &
|
|
164
|
+
ColumnDef_ColumnVisibility &
|
|
162
165
|
ColumnDef_ColumnPinning &
|
|
163
166
|
ColumnDef_ColumnFiltering<TFeatures, TData> &
|
|
164
167
|
ColumnDef_GlobalFiltering &
|
|
165
168
|
ColumnDef_RowSorting<TFeatures, TData> &
|
|
166
|
-
ColumnDef_ColumnGrouping<TFeatures, TData
|
|
169
|
+
ColumnDef_ColumnGrouping<TFeatures, TData> &
|
|
167
170
|
ColumnDef_ColumnSizing &
|
|
168
171
|
ColumnDef_ColumnResizing
|
|
169
172
|
>
|
package/src/types/Row.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Row_ColumnVisibility } from '../features/column-visibility/columnVisibilityFeature.types'
|
|
2
|
+
import type { Row_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
2
3
|
import type { Row_ColumnPinning } from '../features/column-pinning/columnPinningFeature.types'
|
|
3
4
|
import type { Row_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
4
5
|
import type { Row_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
@@ -18,6 +19,7 @@ export interface Row_FeatureMap<
|
|
|
18
19
|
in out TFeatures extends TableFeatures,
|
|
19
20
|
in out TData extends RowData,
|
|
20
21
|
> {
|
|
22
|
+
aggregationFeature: Row_Aggregation
|
|
21
23
|
columnFilteringFeature: Row_ColumnFiltering<TFeatures, TData>
|
|
22
24
|
columnGroupingFeature: Row_ColumnGrouping
|
|
23
25
|
columnPinningFeature: Row_ColumnPinning<TFeatures, TData>
|
package/src/types/RowModelFns.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RowModelFns_RowSorting } from '../features/row-sorting/rowSortingFeature.types'
|
|
2
|
-
import type {
|
|
2
|
+
import type { RowModelFns_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
3
3
|
import type { RowData } from './type-utils'
|
|
4
4
|
import type { RowModelFns_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
5
5
|
import type { ExtractFeatureMapTypes, TableFeatures } from './TableFeatures'
|
|
@@ -10,8 +10,8 @@ export interface RowModelFns_FeatureMap<
|
|
|
10
10
|
in out TFeatures extends TableFeatures,
|
|
11
11
|
in out TData extends RowData,
|
|
12
12
|
> {
|
|
13
|
+
aggregationFeature: RowModelFns_Aggregation<TFeatures, TData>
|
|
13
14
|
columnFilteringFeature: RowModelFns_ColumnFiltering<TFeatures, TData>
|
|
14
|
-
columnGroupingFeature: RowModelFns_ColumnGrouping<TFeatures, TData>
|
|
15
15
|
rowSortingFeature: RowModelFns_RowSorting<TFeatures, TData>
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -27,6 +27,6 @@ export interface RowModelFns_All<
|
|
|
27
27
|
in out TData extends RowData,
|
|
28
28
|
> extends Partial<
|
|
29
29
|
RowModelFns_ColumnFiltering<TFeatures, TData> &
|
|
30
|
-
|
|
30
|
+
RowModelFns_Aggregation<TFeatures, TData> &
|
|
31
31
|
RowModelFns_RowSorting<TFeatures, TData>
|
|
32
32
|
> {}
|
|
@@ -10,7 +10,7 @@ import type { StockFeatures } from '../features/stockFeatures'
|
|
|
10
10
|
import type { RowModel } from '../core/row-models/coreRowModelsFeature.types'
|
|
11
11
|
import type { FilterFn } from '../features/column-filtering/columnFilteringFeature.types'
|
|
12
12
|
import type { SortFn } from '../features/row-sorting/rowSortingFeature.types'
|
|
13
|
-
import type {
|
|
13
|
+
import type { AggregationFnDef } from '../features/aggregation/aggregationFeature.types'
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Detects whether a type is `any`.
|
|
@@ -90,9 +90,9 @@ export type NonFeatureKeys =
|
|
|
90
90
|
*/
|
|
91
91
|
export interface FeatureSlotPrereqs {
|
|
92
92
|
/**
|
|
93
|
-
* Named aggregation functions
|
|
93
|
+
* Named aggregation functions require the independent aggregation feature.
|
|
94
94
|
*/
|
|
95
|
-
aggregationFns: '
|
|
95
|
+
aggregationFns: 'aggregationFeature'
|
|
96
96
|
/**
|
|
97
97
|
* Column resizing builds on the column sizing state and APIs.
|
|
98
98
|
*/
|
|
@@ -190,7 +190,7 @@ export interface TableFeatures
|
|
|
190
190
|
* Spreading the exported `aggregationFns` registry also works, but puts
|
|
191
191
|
* every built-in aggregation function in your bundle.
|
|
192
192
|
*/
|
|
193
|
-
aggregationFns?: Record<string,
|
|
193
|
+
aggregationFns?: Record<string, AggregationFnDef<any, any, any, any>>
|
|
194
194
|
/**
|
|
195
195
|
* Type-only slot for declaring the type of `columnDef.meta` for all columns
|
|
196
196
|
* of this table.
|
|
@@ -4,6 +4,7 @@ import type { TableOptions_Columns } from '../core/columns/coreColumnsFeature.ty
|
|
|
4
4
|
import type { TableOptions_Rows } from '../core/rows/coreRowsFeature.types'
|
|
5
5
|
import type { TableOptions_Table } from '../core/table/coreTablesFeature.types'
|
|
6
6
|
import type { TableOptions_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
|
|
7
|
+
import type { TableOptions_Aggregation } from '../features/aggregation/aggregationFeature.types'
|
|
7
8
|
import type { TableOptions_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
|
|
8
9
|
import type { TableOptions_ColumnOrdering } from '../features/column-ordering/columnOrderingFeature.types'
|
|
9
10
|
import type { TableOptions_ColumnPinning } from '../features/column-pinning/columnPinningFeature.types'
|
|
@@ -58,6 +59,7 @@ export interface TableOptions_FeatureMap<
|
|
|
58
59
|
in out TFeatures extends TableFeatures,
|
|
59
60
|
in out TData extends RowData,
|
|
60
61
|
> {
|
|
62
|
+
aggregationFeature: TableOptions_Aggregation
|
|
61
63
|
columnFilteringFeature: TableOptions_ColumnFiltering<TFeatures, TData>
|
|
62
64
|
columnGroupingFeature: TableOptions_ColumnGrouping
|
|
63
65
|
columnOrderingFeature: TableOptions_ColumnOrdering
|
|
@@ -74,6 +76,7 @@ export interface TableOptions_FeatureMap<
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
type TableOptions_StockFeatureKeys =
|
|
79
|
+
| 'aggregationFeature'
|
|
77
80
|
| 'columnFilteringFeature'
|
|
78
81
|
| 'columnGroupingFeature'
|
|
79
82
|
| 'columnOrderingFeature'
|
|
@@ -133,7 +136,8 @@ export type TableOptions_All<
|
|
|
133
136
|
TData extends RowData,
|
|
134
137
|
> = TableOptions_Core<TFeatures, TData> &
|
|
135
138
|
Partial<
|
|
136
|
-
|
|
139
|
+
TableOptions_Aggregation &
|
|
140
|
+
TableOptions_ColumnFiltering<TFeatures, TData> &
|
|
137
141
|
TableOptions_ColumnGrouping &
|
|
138
142
|
TableOptions_ColumnOrdering &
|
|
139
143
|
TableOptions_ColumnPinning &
|
|
@@ -84,7 +84,7 @@ export function initTableWorker<
|
|
|
84
84
|
// per group. Sync tables aggregate lazily (visible cells only), so
|
|
85
85
|
// auto-aggregating every column would explode on high-cardinality
|
|
86
86
|
// grouping for values nothing renders. Read the RAW column defs:
|
|
87
|
-
//
|
|
87
|
+
// aggregationFeature injects default aggregatedCell/aggregationFn
|
|
88
88
|
// into every resolved columnDef, so the resolved defs can't tell
|
|
89
89
|
// explicit from default.
|
|
90
90
|
aggregateColumnIds = flattenColumnDefs(config.columns as Array<any>)
|