@tanstack/table-core 9.0.0-beta.47 → 9.0.0-beta.49

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.
Files changed (186) hide show
  1. package/dist/core/row-models/coreRowModelsFeature.types.d.cts +1 -1
  2. package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
  3. package/dist/core/row-models/coreRowModelsFeature.utils.cjs +1 -1
  4. package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
  5. package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
  6. package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
  7. package/dist/core/row-models/coreRowModelsFeature.utils.js +1 -1
  8. package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
  9. package/dist/features/aggregation/aggregationFeature.cjs +38 -0
  10. package/dist/features/aggregation/aggregationFeature.cjs.map +1 -0
  11. package/dist/features/aggregation/aggregationFeature.d.cts +10 -0
  12. package/dist/features/aggregation/aggregationFeature.d.ts +10 -0
  13. package/dist/features/aggregation/aggregationFeature.js +38 -0
  14. package/dist/features/aggregation/aggregationFeature.js.map +1 -0
  15. package/dist/features/aggregation/aggregationFeature.types.cjs +13 -0
  16. package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -0
  17. package/dist/features/aggregation/aggregationFeature.types.d.cts +172 -0
  18. package/dist/features/aggregation/aggregationFeature.types.d.ts +172 -0
  19. package/dist/features/aggregation/aggregationFeature.types.js +12 -0
  20. package/dist/features/aggregation/aggregationFeature.types.js.map +1 -0
  21. package/dist/features/aggregation/aggregationFeature.utils.cjs +198 -0
  22. package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -0
  23. package/dist/features/aggregation/aggregationFeature.utils.d.cts +33 -0
  24. package/dist/features/aggregation/aggregationFeature.utils.d.ts +33 -0
  25. package/dist/features/aggregation/aggregationFeature.utils.js +192 -0
  26. package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -0
  27. package/dist/features/aggregation/aggregationFns.cjs +240 -0
  28. package/dist/features/aggregation/aggregationFns.cjs.map +1 -0
  29. package/dist/features/aggregation/aggregationFns.d.cts +67 -0
  30. package/dist/features/aggregation/aggregationFns.d.ts +67 -0
  31. package/dist/features/aggregation/aggregationFns.js +229 -0
  32. package/dist/features/aggregation/aggregationFns.js.map +1 -0
  33. package/dist/features/column-faceting/createFacetedMinMaxValues.cjs +7 -4
  34. package/dist/features/column-faceting/createFacetedMinMaxValues.cjs.map +1 -1
  35. package/dist/features/column-faceting/createFacetedMinMaxValues.js +8 -5
  36. package/dist/features/column-faceting/createFacetedMinMaxValues.js.map +1 -1
  37. package/dist/features/column-faceting/createFacetedRowModel.cjs +1 -1
  38. package/dist/features/column-faceting/createFacetedRowModel.cjs.map +1 -1
  39. package/dist/features/column-faceting/createFacetedRowModel.js +1 -1
  40. package/dist/features/column-faceting/createFacetedRowModel.js.map +1 -1
  41. package/dist/features/column-faceting/createFacetedUniqueValues.cjs +8 -4
  42. package/dist/features/column-faceting/createFacetedUniqueValues.cjs.map +1 -1
  43. package/dist/features/column-faceting/createFacetedUniqueValues.js +9 -5
  44. package/dist/features/column-faceting/createFacetedUniqueValues.js.map +1 -1
  45. package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +1 -1
  46. package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +1 -1
  47. package/dist/{fns → features/column-filtering}/filterFns.cjs +1 -1
  48. package/dist/features/column-filtering/filterFns.cjs.map +1 -0
  49. package/dist/{fns → features/column-filtering}/filterFns.d.cts +4 -4
  50. package/dist/{fns → features/column-filtering}/filterFns.d.ts +4 -4
  51. package/dist/{fns → features/column-filtering}/filterFns.js +1 -1
  52. package/dist/features/column-filtering/filterFns.js.map +1 -0
  53. package/dist/features/column-grouping/columnGroupingFeature.cjs +3 -12
  54. package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
  55. package/dist/features/column-grouping/columnGroupingFeature.d.cts +1 -1
  56. package/dist/features/column-grouping/columnGroupingFeature.d.ts +1 -1
  57. package/dist/features/column-grouping/columnGroupingFeature.js +4 -13
  58. package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
  59. package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +6 -87
  60. package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -87
  61. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -64
  62. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
  63. package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -44
  64. package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -44
  65. package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -63
  66. package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
  67. package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -16
  68. package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
  69. package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -6
  70. package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -6
  71. package/dist/features/column-grouping/createGroupedRowModel.js +25 -18
  72. package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
  73. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +1 -1
  74. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
  75. package/dist/features/global-filtering/globalFilteringFeature.utils.js +1 -1
  76. package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
  77. package/dist/features/row-sorting/rowSortingFeature.types.d.cts +1 -1
  78. package/dist/features/row-sorting/rowSortingFeature.types.d.ts +1 -1
  79. package/dist/features/row-sorting/rowSortingFeature.utils.cjs +1 -1
  80. package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
  81. package/dist/features/row-sorting/rowSortingFeature.utils.js +1 -1
  82. package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
  83. package/dist/{fns → features/row-sorting}/sortFns.cjs +1 -1
  84. package/dist/{fns/sortFns.js.map → features/row-sorting/sortFns.cjs.map} +1 -1
  85. package/dist/{fns → features/row-sorting}/sortFns.d.cts +4 -4
  86. package/dist/{fns → features/row-sorting}/sortFns.d.ts +4 -4
  87. package/dist/{fns → features/row-sorting}/sortFns.js +1 -1
  88. package/dist/features/row-sorting/sortFns.js.map +1 -0
  89. package/dist/features/stockFeatures.cjs +2 -0
  90. package/dist/features/stockFeatures.cjs.map +1 -1
  91. package/dist/features/stockFeatures.d.cts +2 -0
  92. package/dist/features/stockFeatures.d.ts +2 -0
  93. package/dist/features/stockFeatures.js +2 -0
  94. package/dist/features/stockFeatures.js.map +1 -1
  95. package/dist/index.cjs +7 -4
  96. package/dist/index.d.cts +7 -5
  97. package/dist/index.d.ts +7 -5
  98. package/dist/index.js +6 -4
  99. package/dist/static-functions.cjs +8 -3
  100. package/dist/static-functions.d.cts +3 -2
  101. package/dist/static-functions.d.ts +3 -2
  102. package/dist/static-functions.js +3 -2
  103. package/dist/types/Cell.d.cts +3 -1
  104. package/dist/types/Cell.d.ts +3 -1
  105. package/dist/types/Column.d.cts +4 -2
  106. package/dist/types/Column.d.ts +4 -2
  107. package/dist/types/ColumnDef.d.cts +5 -3
  108. package/dist/types/ColumnDef.d.ts +5 -3
  109. package/dist/types/Row.d.cts +3 -1
  110. package/dist/types/Row.d.ts +3 -1
  111. package/dist/types/RowModel.d.cts +1 -1
  112. package/dist/types/RowModel.d.ts +1 -1
  113. package/dist/types/RowModelFns.d.cts +3 -3
  114. package/dist/types/RowModelFns.d.ts +3 -3
  115. package/dist/types/Table.d.cts +1 -1
  116. package/dist/types/Table.d.ts +1 -1
  117. package/dist/types/TableFeatures.d.cts +4 -4
  118. package/dist/types/TableFeatures.d.ts +4 -4
  119. package/dist/types/TableOptions.d.cts +5 -3
  120. package/dist/types/TableOptions.d.ts +5 -3
  121. package/dist/types/TableState.d.cts +1 -1
  122. package/dist/types/TableState.d.ts +1 -1
  123. package/dist/worker/initTableWorker.cjs.map +1 -1
  124. package/dist/worker/initTableWorker.js.map +1 -1
  125. package/package.json +1 -1
  126. package/skills/aggregation/SKILL.md +131 -0
  127. package/skills/api-not-found/SKILL.md +1 -1
  128. package/skills/client-vs-server/SKILL.md +1 -1
  129. package/skills/column-faceting/SKILL.md +1 -1
  130. package/skills/column-filtering/SKILL.md +1 -1
  131. package/skills/column-ordering/SKILL.md +1 -1
  132. package/skills/column-pinning/SKILL.md +1 -1
  133. package/skills/column-resizing/SKILL.md +1 -1
  134. package/skills/column-sizing/SKILL.md +1 -1
  135. package/skills/column-visibility/SKILL.md +1 -1
  136. package/skills/core/SKILL.md +1 -1
  137. package/skills/custom-features/SKILL.md +1 -1
  138. package/skills/expanding/SKILL.md +1 -1
  139. package/skills/global-filtering/SKILL.md +1 -1
  140. package/skills/grouping/SKILL.md +12 -18
  141. package/skills/migrate-v8-to-v9/SKILL.md +15 -2
  142. package/skills/pagination/SKILL.md +1 -1
  143. package/skills/row-pinning/SKILL.md +1 -1
  144. package/skills/row-selection/SKILL.md +1 -1
  145. package/skills/sorting/SKILL.md +1 -1
  146. package/skills/table-features/SKILL.md +5 -2
  147. package/skills/typescript/SKILL.md +1 -1
  148. package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
  149. package/src/features/aggregation/aggregationFeature.ts +59 -0
  150. package/src/features/aggregation/aggregationFeature.types.ts +312 -0
  151. package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
  152. package/src/features/aggregation/aggregationFns.ts +336 -0
  153. package/src/features/column-faceting/createFacetedMinMaxValues.ts +33 -7
  154. package/src/features/column-faceting/createFacetedRowModel.ts +4 -1
  155. package/src/features/column-faceting/createFacetedUniqueValues.ts +45 -11
  156. package/src/features/column-filtering/columnFilteringFeature.types.ts +1 -1
  157. package/src/{fns → features/column-filtering}/filterFns.ts +4 -4
  158. package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
  159. package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -141
  160. package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -122
  161. package/src/features/column-grouping/createGroupedRowModel.ts +32 -41
  162. package/src/features/global-filtering/globalFilteringFeature.utils.ts +1 -1
  163. package/src/features/row-sorting/rowSortingFeature.types.ts +1 -1
  164. package/src/features/row-sorting/rowSortingFeature.utils.ts +1 -1
  165. package/src/{fns → features/row-sorting}/sortFns.ts +4 -7
  166. package/src/features/stockFeatures.ts +3 -0
  167. package/src/index.ts +7 -8
  168. package/src/static-functions.ts +1 -0
  169. package/src/types/Cell.ts +2 -0
  170. package/src/types/Column.ts +3 -1
  171. package/src/types/ColumnDef.ts +6 -3
  172. package/src/types/Row.ts +2 -0
  173. package/src/types/RowModelFns.ts +3 -3
  174. package/src/types/TableFeatures.ts +4 -4
  175. package/src/types/TableOptions.ts +5 -1
  176. package/src/worker/initTableWorker.ts +1 -1
  177. package/dist/fns/aggregationFns.cjs +0 -234
  178. package/dist/fns/aggregationFns.cjs.map +0 -1
  179. package/dist/fns/aggregationFns.d.cts +0 -139
  180. package/dist/fns/aggregationFns.d.ts +0 -139
  181. package/dist/fns/aggregationFns.js +0 -221
  182. package/dist/fns/aggregationFns.js.map +0 -1
  183. package/dist/fns/filterFns.cjs.map +0 -1
  184. package/dist/fns/filterFns.js.map +0 -1
  185. package/dist/fns/sortFns.cjs.map +0 -1
  186. package/src/fns/aggregationFns.ts +0 -303
@@ -1,16 +1,7 @@
1
1
  import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'
2
- import type { BuiltInAggregationFn } from '../../fns/aggregationFns'
3
- import type {
4
- CellData,
5
- OnChangeFn,
6
- RowData,
7
- TransformDataValueFn,
8
- Updater,
9
- } from '../../types/type-utils'
10
- import type { IsAny, TableFeatures } from '../../types/TableFeatures'
2
+ import type { OnChangeFn, RowData, Updater } from '../../types/type-utils'
3
+ import type { TableFeatures } from '../../types/TableFeatures'
11
4
  import type { Row } from '../../types/Row'
12
- import type { Cell } from '../../types/Cell'
13
- import type { ColumnDefTemplate } from '../../types/ColumnDef'
14
5
 
15
6
  export type GroupingState = Array<string>
16
7
 
@@ -18,123 +9,10 @@ export interface TableState_ColumnGrouping {
18
9
  grouping: GroupingState
19
10
  }
20
11
 
21
- export interface RowModelFns_ColumnGrouping<
22
- in out TFeatures extends TableFeatures,
23
- in out TData extends RowData,
24
- > {
25
- aggregationFns: Record<string, AggregationFn<TFeatures, TData>>
26
- }
27
-
28
- export interface AggregationFns {}
29
-
30
- export interface AggregationFn<
31
- in out TFeatures extends TableFeatures,
32
- in out TData extends RowData,
33
- > {
34
- (
35
- columnId: string,
36
- leafRows: Array<Row<TFeatures, TData>>,
37
- childRows: Array<Row<TFeatures, TData>>,
38
- ): any
39
- /**
40
- * Normalizes each row's value before it is aggregated. Only honored by
41
- * aggregation functions built with `constructAggregationFn` (including the
42
- * value-based built-in aggregation functions).
43
- */
44
- resolveDataValue?: TransformDataValueFn
45
- }
46
-
47
- /**
48
- * The definition object accepted by `constructAggregationFn`.
49
- *
50
- * `aggregate` is a value-level reducer: it receives the rows' (resolved)
51
- * values instead of the rows themselves, so normalization concerns stay in
52
- * `resolveDataValue`.
53
- */
54
- export interface AggregationFnDef<
55
- in out TFeatures extends TableFeatures,
56
- in out TData extends RowData,
57
- > {
58
- aggregate: (
59
- values: Array<any>,
60
- rows: Array<Row<TFeatures, TData>>,
61
- columnId: string,
62
- ) => any
63
- /**
64
- * Which of the group's rows feed the aggregation: all of its `leafRows`
65
- * (the default) or its immediate `childRows`. For nested groups, child rows
66
- * expose already-aggregated values, which is faster for reaggregatable
67
- * computations like sums and extents.
68
- */
69
- fromRows?: 'leafRows' | 'childRows'
70
- resolveDataValue?: TransformDataValueFn
71
- }
72
-
73
- /**
74
- * The shape returned by `constructAggregationFn`: an `AggregationFn` with its
75
- * definition attached, so variants can be built by spreading it into another
76
- * `constructAggregationFn` call.
77
- *
78
- * The call signature is generic so a created aggregation function can be used
79
- * with any table's rows, regardless of the feature set it was defined
80
- * against.
81
- */
82
- export interface CreatedAggregationFn<
83
- in out TFeatures extends TableFeatures,
84
- in out TData extends RowData,
85
- > extends AggregationFnDef<TFeatures, TData> {
86
- <TRowFeatures extends TableFeatures, TRowData extends RowData>(
87
- columnId: string,
88
- leafRows: Array<Row<TRowFeatures, TRowData>>,
89
- childRows: Array<Row<TRowFeatures, TRowData>>,
90
- ): any
91
- }
92
-
93
- export type CustomAggregationFns<
94
- TFeatures extends TableFeatures,
95
- TData extends RowData,
96
- > = Record<string, AggregationFn<TFeatures, TData>>
97
-
98
- /**
99
- * Resolves the valid string names for `columnDef.aggregationFn` for a feature
100
- * set.
101
- *
102
- * When the features object declares an `aggregationFns` registry
103
- * (`tableFeatures({ ..., aggregationFns })`), its keys are the only valid
104
- * names; a name is only assignable if an aggregation function is actually
105
- * registered for it. Otherwise this falls back to the global
106
- * declaration-merged `AggregationFns` interface.
107
- */
108
- export type ExtractAggregationFnKeys<TFeatures extends TableFeatures> =
109
- IsAny<TFeatures> extends true
110
- ? keyof AggregationFns | BuiltInAggregationFn
111
- : TFeatures extends { aggregationFns: infer TAggregationFns extends object }
112
- ? Extract<keyof TAggregationFns, string>
113
- : keyof AggregationFns
114
-
115
- export type AggregationFnOption<
116
- TFeatures extends TableFeatures,
117
- TData extends RowData,
118
- > =
119
- | 'auto'
120
- | ExtractAggregationFnKeys<TFeatures>
121
- | AggregationFn<TFeatures, TData>
122
-
123
12
  export interface ColumnDef_ColumnGrouping<
124
13
  in out TFeatures extends TableFeatures,
125
14
  in out TData extends RowData,
126
- TValue extends CellData = CellData,
127
15
  > {
128
- /**
129
- * The cell to display each row for the column if the cell is an aggregate. If a function is passed, it will be passed a props object with the context of the cell and should return the property type for your adapter (the exact type depends on the adapter being used).
130
- */
131
- aggregatedCell?: ColumnDefTemplate<
132
- ReturnType<Cell<TFeatures, TData, TValue>['getContext']>
133
- >
134
- /**
135
- * The resolved aggregation function for the column.
136
- */
137
- aggregationFn?: AggregationFnOption<TFeatures, TData>
138
16
  /**
139
17
  * Allows this column to be added to grouping state.
140
18
  *
@@ -154,18 +32,7 @@ export interface ColumnDef_ColumnGrouping<
154
32
  ) => any
155
33
  }
156
34
 
157
- export interface Column_ColumnGrouping<
158
- in out TFeatures extends TableFeatures,
159
- in out TData extends RowData,
160
- > {
161
- /**
162
- * Returns the aggregation function for the column.
163
- */
164
- getAggregationFn: () => AggregationFn<TFeatures, TData> | undefined
165
- /**
166
- * Returns the automatically inferred aggregation function for the column.
167
- */
168
- getAutoAggregationFn: () => AggregationFn<TFeatures, TData> | undefined
35
+ export interface Column_ColumnGrouping {
169
36
  /**
170
37
  * Checks whether this column can currently be grouped.
171
38
  */
@@ -209,10 +76,6 @@ export interface Row_ColumnGrouping {
209
76
  }
210
77
 
211
78
  export interface Cell_ColumnGrouping {
212
- /**
213
- * Checks whether this cell should render an aggregated value.
214
- */
215
- getIsAggregated: () => boolean
216
79
  /**
217
80
  * Checks whether this cell represents the active grouping column.
218
81
  */
@@ -272,7 +135,7 @@ export interface Table_RowModels_Grouped<
272
135
  in out TData extends RowData,
273
136
  > {
274
137
  /**
275
- * Resolves the row model after grouping and aggregation have been applied.
138
+ * Resolves the row model after grouping has been applied.
276
139
  */
277
140
  getGroupedRowModel: () => RowModel<TFeatures, TData>
278
141
  /**
@@ -1,4 +1,4 @@
1
- import { cloneState, hasOwn, isFunction } from '../../utils'
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 { flattenBy, hasOwn, makeObjectMap, tableMemo } from '../../utils'
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
- column_getAggregationFn,
8
- row_getGroupingValue,
9
- } from './columnGroupingFeature.utils'
10
- import type { Column } from '../../types/Column'
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
- * Register the aggregation functions you use with the `aggregationFns` slot
24
- * on the `features` option:
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
- // Flatten the leaf rows of the rows in this group
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
- // Don't aggregate columns that are in the grouping
146
- if (existingGrouping.includes(colId)) {
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
- if (
160
- row._groupingValuesCache &&
161
- hasOwn(row._groupingValuesCache, colId)
162
- ) {
163
- return row._groupingValuesCache[colId]
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
- if (aggregateFn) {
177
- row._groupingValuesCache[colId] = aggregateFn(
178
- colId,
179
- leafRows,
180
- groupedRows,
181
- )
182
-
183
- return row._groupingValuesCache[colId]
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 '../../fns/filterFns'
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
1
  import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'
2
- import type { BuiltInSortFn } from '../../fns/sortFns'
2
+ import type { BuiltInSortFn } from './sortFns'
3
3
  import type {
4
4
  OnChangeFn,
5
5
  RowData,
@@ -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
- CreatedSortFn,
3
- SortFnDef,
4
- } from '../features/row-sorting/rowSortingFeature.types'
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
@@ -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
 
@@ -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<TFeatures, TData>
31
+ columnGroupingFeature: Column_ColumnGrouping
30
32
  columnOrderingFeature: Column_ColumnOrdering
31
33
  columnPinningFeature: Column_ColumnPinning
32
34
  columnResizingFeature: Column_ColumnResizing
@@ -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, TValue>
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
- ColumnDef_ColumnVisibility &
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, TValue> &
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>
@@ -1,5 +1,5 @@
1
1
  import type { RowModelFns_RowSorting } from '../features/row-sorting/rowSortingFeature.types'
2
- import type { RowModelFns_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
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
- RowModelFns_ColumnGrouping<TFeatures, TData> &
30
+ RowModelFns_Aggregation<TFeatures, TData> &
31
31
  RowModelFns_RowSorting<TFeatures, TData>
32
32
  > {}