@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
|
@@ -141,6 +141,11 @@ export function column_getToggleGroupingHandler<
|
|
|
141
141
|
* Numeric columns default to `sum`, date-like values default to `extent`, and
|
|
142
142
|
* other value types leave aggregation unspecified.
|
|
143
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
|
+
*
|
|
144
149
|
* @example
|
|
145
150
|
* ```ts
|
|
146
151
|
* const aggregationFn = column_getAutoAggregationFn(column)
|
|
@@ -159,15 +164,27 @@ export function column_getAutoAggregationFn<
|
|
|
159
164
|
|
|
160
165
|
const value = firstRow?.getValue(column.id)
|
|
161
166
|
|
|
167
|
+
let aggregationFnName: string | undefined
|
|
168
|
+
|
|
162
169
|
if (typeof value === 'number') {
|
|
163
|
-
|
|
170
|
+
aggregationFnName = 'sum'
|
|
171
|
+
} else if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
172
|
+
aggregationFnName = 'extent'
|
|
164
173
|
}
|
|
165
174
|
|
|
166
|
-
if (
|
|
167
|
-
return
|
|
175
|
+
if (!aggregationFnName) {
|
|
176
|
+
return undefined
|
|
168
177
|
}
|
|
169
178
|
|
|
170
|
-
|
|
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
|
|
171
188
|
}
|
|
172
189
|
|
|
173
190
|
/**
|
|
@@ -191,11 +208,28 @@ export function column_getAggregationFn<
|
|
|
191
208
|
| Record<string, AggregationFn<TFeatures, TData>>
|
|
192
209
|
| undefined = column.table._rowModelFns.aggregationFns
|
|
193
210
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
|
199
233
|
}
|
|
200
234
|
|
|
201
235
|
/**
|
|
@@ -20,9 +20,12 @@ 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 aggregation functions with the `aggregationFns` slot
|
|
24
|
-
* `features` option:
|
|
25
|
-
* `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns })`.
|
|
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.
|
|
26
29
|
*/
|
|
27
30
|
export function createGroupedRowModel<
|
|
28
31
|
TFeatures extends TableFeatures,
|
|
@@ -74,6 +74,14 @@ export function table_getGlobalFilterFn<
|
|
|
74
74
|
? table_getGlobalAutoFilterFn()
|
|
75
75
|
: filterFns?.[globalFilterFn as string]
|
|
76
76
|
|
|
77
|
+
if (
|
|
78
|
+
process.env.NODE_ENV === 'development' &&
|
|
79
|
+
!filterFn &&
|
|
80
|
+
globalFilterFn != null
|
|
81
|
+
) {
|
|
82
|
+
console.warn(`globalFilterFn '${String(globalFilterFn)}' is not registered`)
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
return filterFn
|
|
78
86
|
}
|
|
79
87
|
|
|
@@ -14,8 +14,12 @@ import type { RowData } from '../../types/type-utils'
|
|
|
14
14
|
*
|
|
15
15
|
* The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
|
|
16
16
|
*
|
|
17
|
-
* Register sorting functions with the `sortFns` slot on the
|
|
18
|
-
* `
|
|
17
|
+
* Register the sorting functions you use with the `sortFns` slot on the
|
|
18
|
+
* `features` option:
|
|
19
|
+
* `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns: { alphanumeric: sortFn_alphanumeric } })`.
|
|
20
|
+
* Importing individual `sortFn_*` functions keeps unused built-ins out of
|
|
21
|
+
* your bundle; sorting functions passed directly to the `sortFn` column
|
|
22
|
+
* option need no registration at all.
|
|
19
23
|
*/
|
|
20
24
|
export function createSortedRowModel<
|
|
21
25
|
TFeatures extends TableFeatures,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'
|
|
2
2
|
import type { BuiltInSortFn } from '../../fns/sortFns'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
OnChangeFn,
|
|
5
|
+
RowData,
|
|
6
|
+
TransformDataValueFn,
|
|
7
|
+
Updater,
|
|
8
|
+
} from '../../types/type-utils'
|
|
4
9
|
import type { IsAny, TableFeatures } from '../../types/TableFeatures'
|
|
5
10
|
import type { Row } from '../../types/Row'
|
|
6
11
|
|
|
@@ -35,6 +40,53 @@ export interface SortFn<
|
|
|
35
40
|
rowB: Row<TFeatures, TData>,
|
|
36
41
|
columnId: string,
|
|
37
42
|
): number
|
|
43
|
+
/**
|
|
44
|
+
* Normalizes each row's value before the two sides are compared. Only
|
|
45
|
+
* honored by sorting functions built with `constructSortFn` (including all
|
|
46
|
+
* built-in sorting functions).
|
|
47
|
+
*/
|
|
48
|
+
resolveDataValue?: TransformDataValueFn
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The definition object accepted by `constructSortFn`.
|
|
53
|
+
*
|
|
54
|
+
* `sort` is a value-level comparator: it receives both rows' (resolved) data
|
|
55
|
+
* values instead of the whole rows, so normalization concerns stay in
|
|
56
|
+
* `resolveDataValue`.
|
|
57
|
+
*/
|
|
58
|
+
export interface SortFnDef<
|
|
59
|
+
in out TFeatures extends TableFeatures,
|
|
60
|
+
in out TData extends RowData,
|
|
61
|
+
> {
|
|
62
|
+
sort: (
|
|
63
|
+
dataValueA: any,
|
|
64
|
+
dataValueB: any,
|
|
65
|
+
rowA: Row<TFeatures, TData>,
|
|
66
|
+
rowB: Row<TFeatures, TData>,
|
|
67
|
+
columnId: string,
|
|
68
|
+
) => number
|
|
69
|
+
resolveDataValue?: TransformDataValueFn
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The shape returned by `constructSortFn`: a `SortFn` with its definition
|
|
74
|
+
* attached, so variants can be built by spreading it into another
|
|
75
|
+
* `constructSortFn` call.
|
|
76
|
+
*
|
|
77
|
+
* The call signature is generic so a created sorting function can be used
|
|
78
|
+
* with any table's rows, regardless of the feature set it was defined
|
|
79
|
+
* against.
|
|
80
|
+
*/
|
|
81
|
+
export interface CreatedSortFn<
|
|
82
|
+
in out TFeatures extends TableFeatures,
|
|
83
|
+
in out TData extends RowData,
|
|
84
|
+
> extends SortFnDef<TFeatures, TData> {
|
|
85
|
+
<TRowFeatures extends TableFeatures, TRowData extends RowData>(
|
|
86
|
+
rowA: Row<TRowFeatures, TRowData>,
|
|
87
|
+
rowB: Row<TRowFeatures, TRowData>,
|
|
88
|
+
columnId: string,
|
|
89
|
+
): number
|
|
38
90
|
}
|
|
39
91
|
|
|
40
92
|
export type CustomSortFns<
|
|
@@ -91,30 +91,50 @@ export function column_getAutoSortFn<
|
|
|
91
91
|
|
|
92
92
|
const firstRows = column.table.getFilteredRowModel().flatRows.slice(0, 10)
|
|
93
93
|
|
|
94
|
+
let sortFnName: string | undefined
|
|
94
95
|
let isString = false
|
|
95
96
|
|
|
96
97
|
for (let i = 0; i < firstRows.length; i++) {
|
|
97
98
|
const value = firstRows[i]!.getValue(column.id)
|
|
98
99
|
|
|
99
100
|
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
101
|
+
sortFnName = 'datetime'
|
|
102
|
+
break
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
if (typeof value === 'string') {
|
|
106
106
|
isString = true
|
|
107
107
|
|
|
108
108
|
if (value.split(reSplitAlphaNumeric).length > 1) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
109
|
+
sortFnName = 'alphanumeric'
|
|
110
|
+
break
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
if (isString) {
|
|
117
|
-
|
|
115
|
+
if (!sortFnName && isString) {
|
|
116
|
+
sortFnName = 'text'
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (sortFnName) {
|
|
120
|
+
let sortFn = sortFns?.[sortFnName]
|
|
121
|
+
|
|
122
|
+
if (!sortFn) {
|
|
123
|
+
if (process.env.NODE_ENV === 'development') {
|
|
124
|
+
console.warn(
|
|
125
|
+
`sortFn '${sortFnName}' (auto) for column '${column.id}' is not registered`,
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// String columns degrade to a registered text sort before basic
|
|
130
|
+
if (sortFnName === 'alphanumeric') {
|
|
131
|
+
sortFn = sortFns?.text
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (sortFn) {
|
|
136
|
+
return sortFn
|
|
137
|
+
}
|
|
118
138
|
}
|
|
119
139
|
|
|
120
140
|
return sortFn_basic
|
|
@@ -167,11 +187,23 @@ export function column_getSortFn<
|
|
|
167
187
|
const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =
|
|
168
188
|
column.table._rowModelFns.sortFns
|
|
169
189
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
190
|
+
if (isFunction(column.columnDef.sortFn)) {
|
|
191
|
+
return column.columnDef.sortFn
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (column.columnDef.sortFn === 'auto') {
|
|
195
|
+
return column_getAutoSortFn(column)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const sortFn = sortFns?.[column.columnDef.sortFn as string]
|
|
199
|
+
|
|
200
|
+
if (process.env.NODE_ENV === 'development' && !sortFn) {
|
|
201
|
+
console.warn(
|
|
202
|
+
`sortFn '${String(column.columnDef.sortFn)}' for column '${column.id}' is not registered`,
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return sortFn ?? sortFn_basic
|
|
175
207
|
}
|
|
176
208
|
|
|
177
209
|
/**
|