@tanstack/table-core 8.0.0-beta.2 → 8.0.0-beta.5
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/build/cjs/core/cell.js +7 -1
- package/build/cjs/core/cell.js.map +1 -1
- package/build/cjs/core/instance.js +2 -2
- package/build/cjs/core/instance.js.map +1 -1
- package/build/cjs/features/Filters.js +1 -2
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +19 -6
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/RowSelection.js +3 -3
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +27 -9
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +0 -5
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +19 -5
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/esm/index.js +78 -33
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +322 -322
- package/build/types/core/instance.d.ts +1 -0
- package/build/types/features/Filters.d.ts +0 -3
- package/build/types/features/Grouping.d.ts +0 -3
- package/build/types/features/RowSelection.d.ts +2 -2
- package/build/types/features/Sorting.d.ts +1 -0
- package/build/types/types.d.ts +1 -1
- package/build/umd/index.development.js +78 -33
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/core/cell.ts +4 -1
- package/src/core/instance.ts +2 -1
- package/src/features/Filters.ts +5 -7
- package/src/features/Grouping.ts +19 -10
- package/src/features/RowSelection.ts +7 -5
- package/src/features/Sorting.ts +27 -12
- package/src/types.ts +1 -1
- package/src/utils/getGroupedRowModel.ts +0 -7
- package/src/utils/getPaginationRowModel.ts +21 -6
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-beta.
|
|
4
|
+
"version": "8.0.0-beta.5",
|
|
5
5
|
"description": "Headless UI for building powerful tables & datagrids for TS/JS.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/table#readme",
|
package/src/core/cell.ts
CHANGED
|
@@ -14,6 +14,9 @@ export function createCell<TGenerics extends TableGenerics>(
|
|
|
14
14
|
column: Column<TGenerics>,
|
|
15
15
|
columnId: string
|
|
16
16
|
) {
|
|
17
|
+
const getRenderValue = () =>
|
|
18
|
+
cell.getValue() ?? instance.options.renderFallbackValue
|
|
19
|
+
|
|
17
20
|
const cell: CoreCell<TGenerics> = {
|
|
18
21
|
id: `${row.id}_${column.id}`,
|
|
19
22
|
row,
|
|
@@ -26,7 +29,7 @@ export function createCell<TGenerics extends TableGenerics>(
|
|
|
26
29
|
column,
|
|
27
30
|
row,
|
|
28
31
|
cell: cell as Cell<TGenerics>,
|
|
29
|
-
getValue:
|
|
32
|
+
getValue: getRenderValue,
|
|
30
33
|
})
|
|
31
34
|
: null
|
|
32
35
|
},
|
package/src/core/instance.ts
CHANGED
|
@@ -85,6 +85,7 @@ export type CoreOptions<TGenerics extends TableGenerics> = {
|
|
|
85
85
|
) => string
|
|
86
86
|
columns: ColumnDef<TGenerics>[]
|
|
87
87
|
defaultColumn?: Partial<ColumnDef<TGenerics>>
|
|
88
|
+
renderFallbackValue: any
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
export type CoreInstance<TGenerics extends TableGenerics> = {
|
|
@@ -254,7 +255,7 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
254
255
|
return {
|
|
255
256
|
header: props => props.header.column.id,
|
|
256
257
|
footer: props => props.header.column.id,
|
|
257
|
-
cell: props => props.getValue()
|
|
258
|
+
cell: props => props.getValue()?.toString?.() ?? null,
|
|
258
259
|
...instance._features.reduce((obj, feature) => {
|
|
259
260
|
return Object.assign(obj, feature.getDefaultColumnDef?.())
|
|
260
261
|
}, {}),
|
package/src/features/Filters.ts
CHANGED
|
@@ -75,7 +75,6 @@ export type FiltersColumnDef<TGenerics extends TableGenerics> = {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
export type FiltersColumn<TGenerics extends TableGenerics> = {
|
|
78
|
-
filterFn: FilterFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
79
78
|
getAutoFilterFn: () => FilterFn<TGenerics> | undefined
|
|
80
79
|
getFilterFn: () => FilterFn<TGenerics> | undefined
|
|
81
80
|
setFilterValue: (updater: Updater<any>) => void
|
|
@@ -197,7 +196,6 @@ export const Filters: TableFeature = {
|
|
|
197
196
|
instance: TableInstance<TGenerics>
|
|
198
197
|
): FiltersColumn<TGenerics> => {
|
|
199
198
|
return {
|
|
200
|
-
filterFn: column.filterFn,
|
|
201
199
|
getAutoFilterFn: () => {
|
|
202
200
|
const firstRow = instance.getCoreRowModel().flatRows[0]
|
|
203
201
|
|
|
@@ -228,15 +226,15 @@ export const Filters: TableFeature = {
|
|
|
228
226
|
getFilterFn: () => {
|
|
229
227
|
const userFilterFns = instance.options.filterFns
|
|
230
228
|
|
|
231
|
-
return isFunction(column.filterFn)
|
|
232
|
-
? column.filterFn
|
|
233
|
-
: column.filterFn === 'auto'
|
|
229
|
+
return isFunction(column.columnDef.filterFn)
|
|
230
|
+
? column.columnDef.filterFn
|
|
231
|
+
: column.columnDef.filterFn === 'auto'
|
|
234
232
|
? column.getAutoFilterFn()
|
|
235
233
|
: (userFilterFns as Record<string, any>)?.[
|
|
236
|
-
column.filterFn as string
|
|
234
|
+
column.columnDef.filterFn as string
|
|
237
235
|
] ??
|
|
238
236
|
(filterFns[
|
|
239
|
-
column.filterFn as BuiltInFilterFn
|
|
237
|
+
column.columnDef.filterFn as BuiltInFilterFn
|
|
240
238
|
] as FilterFn<TGenerics>)
|
|
241
239
|
},
|
|
242
240
|
getCanFilter: () => {
|
package/src/features/Grouping.ts
CHANGED
|
@@ -52,7 +52,6 @@ export type GroupingColumnDef<TGenerics extends TableGenerics> = {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
export type GroupingColumn<TGenerics extends TableGenerics> = {
|
|
55
|
-
aggregationFn?: AggregationFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
56
55
|
getCanGroup: () => boolean
|
|
57
56
|
getIsGrouped: () => boolean
|
|
58
57
|
getGroupedIndex: () => number
|
|
@@ -108,6 +107,7 @@ export const Grouping: TableFeature = {
|
|
|
108
107
|
TGenerics extends TableGenerics
|
|
109
108
|
>(): GroupingColumnDef<TGenerics> => {
|
|
110
109
|
return {
|
|
110
|
+
aggregatedCell: props => props.getValue()?.toString?.() ?? null,
|
|
111
111
|
aggregationFn: 'auto',
|
|
112
112
|
}
|
|
113
113
|
},
|
|
@@ -180,8 +180,6 @@ export const Grouping: TableFeature = {
|
|
|
180
180
|
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
181
181
|
return aggregationFns.extent
|
|
182
182
|
}
|
|
183
|
-
|
|
184
|
-
return aggregationFns.count
|
|
185
183
|
},
|
|
186
184
|
getAggregationFn: () => {
|
|
187
185
|
const userAggregationFns = instance.options.aggregationFns
|
|
@@ -190,15 +188,15 @@ export const Grouping: TableFeature = {
|
|
|
190
188
|
throw new Error()
|
|
191
189
|
}
|
|
192
190
|
|
|
193
|
-
return isFunction(column.aggregationFn)
|
|
194
|
-
? column.aggregationFn
|
|
195
|
-
: column.aggregationFn === 'auto'
|
|
191
|
+
return isFunction(column.columnDef.aggregationFn)
|
|
192
|
+
? column.columnDef.aggregationFn
|
|
193
|
+
: column.columnDef.aggregationFn === 'auto'
|
|
196
194
|
? column.getAutoAggregationFn()
|
|
197
195
|
: (userAggregationFns as Record<string, any>)?.[
|
|
198
|
-
column.aggregationFn as string
|
|
196
|
+
column.columnDef.aggregationFn as string
|
|
199
197
|
] ??
|
|
200
198
|
(aggregationFns[
|
|
201
|
-
column.aggregationFn as BuiltInAggregationFn
|
|
199
|
+
column.columnDef.aggregationFn as BuiltInAggregationFn
|
|
202
200
|
] as AggregationFn<TGenerics>)
|
|
203
201
|
},
|
|
204
202
|
}
|
|
@@ -250,6 +248,9 @@ export const Grouping: TableFeature = {
|
|
|
250
248
|
row: Row<TGenerics>,
|
|
251
249
|
instance: TableInstance<TGenerics>
|
|
252
250
|
): GroupingCell<TGenerics> => {
|
|
251
|
+
const getRenderValue = () =>
|
|
252
|
+
cell.getValue() ?? instance.options.renderFallbackValue
|
|
253
|
+
|
|
253
254
|
return {
|
|
254
255
|
getIsGrouped: () =>
|
|
255
256
|
column.getIsGrouped() && column.id === row.groupingColumnId,
|
|
@@ -259,8 +260,16 @@ export const Grouping: TableFeature = {
|
|
|
259
260
|
!cell.getIsPlaceholder() &&
|
|
260
261
|
row.subRows?.length > 1,
|
|
261
262
|
renderAggregatedCell: () => {
|
|
263
|
+
if (process.env.NODE_ENV === 'development') {
|
|
264
|
+
if (!column.columnDef.aggregatedCell) {
|
|
265
|
+
console.warn(
|
|
266
|
+
'A columnDef.aggregatedCell template is recommended for displaying aggregated values.'
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
262
271
|
const template =
|
|
263
|
-
column.columnDef.aggregatedCell
|
|
272
|
+
column.columnDef.aggregatedCell || column.columnDef.cell
|
|
264
273
|
|
|
265
274
|
return template
|
|
266
275
|
? instance._render(template, {
|
|
@@ -268,7 +277,7 @@ export const Grouping: TableFeature = {
|
|
|
268
277
|
column,
|
|
269
278
|
row,
|
|
270
279
|
cell,
|
|
271
|
-
getValue:
|
|
280
|
+
getValue: getRenderValue,
|
|
272
281
|
})
|
|
273
282
|
: null
|
|
274
283
|
},
|
|
@@ -58,8 +58,8 @@ export type RowSelectionInstance<TGenerics extends TableGenerics> = {
|
|
|
58
58
|
getIsAllPageRowsSelected: () => boolean
|
|
59
59
|
getIsSomeRowsSelected: () => boolean
|
|
60
60
|
getIsSomePageRowsSelected: () => boolean
|
|
61
|
-
toggleAllRowsSelected: (value
|
|
62
|
-
toggleAllPageRowsSelected: (value
|
|
61
|
+
toggleAllRowsSelected: (value?: boolean) => void
|
|
62
|
+
toggleAllPageRowsSelected: (value?: boolean) => void
|
|
63
63
|
getPreSelectedRowModel: () => RowModel<TGenerics>
|
|
64
64
|
getSelectedRowModel: () => RowModel<TGenerics>
|
|
65
65
|
getFilteredSelectedRowModel: () => RowModel<TGenerics>
|
|
@@ -128,7 +128,7 @@ export const RowSelection: TableFeature = {
|
|
|
128
128
|
},
|
|
129
129
|
toggleAllPageRowsSelected: value =>
|
|
130
130
|
instance.setRowSelection(old => {
|
|
131
|
-
const
|
|
131
|
+
const resolvedValue =
|
|
132
132
|
typeof value !== 'undefined'
|
|
133
133
|
? value
|
|
134
134
|
: !instance.getIsAllPageRowsSelected()
|
|
@@ -136,7 +136,7 @@ export const RowSelection: TableFeature = {
|
|
|
136
136
|
const rowSelection: RowSelectionState = { ...old }
|
|
137
137
|
|
|
138
138
|
instance.getRowModel().rows.forEach(row => {
|
|
139
|
-
mutateRowIsSelected(rowSelection, row.id,
|
|
139
|
+
mutateRowIsSelected(rowSelection, row.id, resolvedValue, instance)
|
|
140
140
|
})
|
|
141
141
|
|
|
142
142
|
return rowSelection
|
|
@@ -325,7 +325,9 @@ export const RowSelection: TableFeature = {
|
|
|
325
325
|
const paginationFlatRows = instance.getPaginationRowModel().flatRows
|
|
326
326
|
return instance.getIsAllPageRowsSelected()
|
|
327
327
|
? false
|
|
328
|
-
:
|
|
328
|
+
: paginationFlatRows.some(
|
|
329
|
+
d => d.getIsSelected() || d.getIsSomeSelected()
|
|
330
|
+
)
|
|
329
331
|
},
|
|
330
332
|
|
|
331
333
|
getToggleAllRowsSelectedHandler: () => {
|
package/src/features/Sorting.ts
CHANGED
|
@@ -58,6 +58,7 @@ export type SortingColumn<TGenerics extends TableGenerics> = {
|
|
|
58
58
|
getAutoSortingFn: () => SortingFn<TGenerics>
|
|
59
59
|
getAutoSortDir: () => SortDirection
|
|
60
60
|
getSortingFn: () => SortingFn<TGenerics>
|
|
61
|
+
getNextSortingOrder: () => SortDirection | false
|
|
61
62
|
getCanSort: () => boolean
|
|
62
63
|
getCanMultiSort: () => boolean
|
|
63
64
|
getSortIndex: () => number
|
|
@@ -189,6 +190,9 @@ export const Sorting: TableFeature = {
|
|
|
189
190
|
// return
|
|
190
191
|
// }
|
|
191
192
|
|
|
193
|
+
// this needs to be outside of instance.setSorting to be in sync with rerender
|
|
194
|
+
const nextSortingOrder = column.getNextSortingOrder()
|
|
195
|
+
|
|
192
196
|
instance.setSorting(old => {
|
|
193
197
|
// Find any existing sorting for this column
|
|
194
198
|
const existingSorting = old?.find(d => d.id === column.id)
|
|
@@ -198,7 +202,7 @@ export const Sorting: TableFeature = {
|
|
|
198
202
|
let newSorting: SortingState = []
|
|
199
203
|
|
|
200
204
|
// What should we do with this sort action?
|
|
201
|
-
let sortAction
|
|
205
|
+
let sortAction: 'add' | 'remove' | 'toggle' | 'replace'
|
|
202
206
|
|
|
203
207
|
if (column.getCanMultiSort() && multi) {
|
|
204
208
|
if (existingSorting) {
|
|
@@ -217,20 +221,13 @@ export const Sorting: TableFeature = {
|
|
|
217
221
|
}
|
|
218
222
|
}
|
|
219
223
|
|
|
220
|
-
const sortDescFirst =
|
|
221
|
-
column.columnDef.sortDescFirst ??
|
|
222
|
-
instance.options.sortDescFirst ??
|
|
223
|
-
column.getAutoSortDir() === 'desc'
|
|
224
|
-
|
|
225
224
|
// Handle toggle states that will remove the sorting
|
|
226
225
|
if (
|
|
227
226
|
sortAction === 'toggle' && // Must be toggling
|
|
228
227
|
(instance.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general
|
|
229
228
|
!hasDescDefined && // Must not be setting desc
|
|
230
229
|
(multi ? instance.options.enableMultiRemove ?? true : true) && // If multi, don't allow if enableMultiRemove
|
|
231
|
-
|
|
232
|
-
? !sortDescFirst
|
|
233
|
-
: sortDescFirst)
|
|
230
|
+
!nextSortingOrder // Finally, detect if it should indeed be removed
|
|
234
231
|
) {
|
|
235
232
|
sortAction = 'remove'
|
|
236
233
|
}
|
|
@@ -239,7 +236,7 @@ export const Sorting: TableFeature = {
|
|
|
239
236
|
newSorting = [
|
|
240
237
|
{
|
|
241
238
|
id: column.id,
|
|
242
|
-
desc: hasDescDefined ? desc! :
|
|
239
|
+
desc: hasDescDefined ? desc! : nextSortingOrder! === 'desc',
|
|
243
240
|
},
|
|
244
241
|
]
|
|
245
242
|
} else if (sortAction === 'add' && old?.length) {
|
|
@@ -247,7 +244,7 @@ export const Sorting: TableFeature = {
|
|
|
247
244
|
...old,
|
|
248
245
|
{
|
|
249
246
|
id: column.id,
|
|
250
|
-
desc: hasDescDefined ? desc! :
|
|
247
|
+
desc: hasDescDefined ? desc! : nextSortingOrder! === 'desc',
|
|
251
248
|
},
|
|
252
249
|
]
|
|
253
250
|
// Take latest n columns
|
|
@@ -263,7 +260,7 @@ export const Sorting: TableFeature = {
|
|
|
263
260
|
if (d.id === column.id) {
|
|
264
261
|
return {
|
|
265
262
|
...d,
|
|
266
|
-
desc: hasDescDefined ? desc! : !
|
|
263
|
+
desc: hasDescDefined ? desc! : nextSortingOrder! === 'desc',
|
|
267
264
|
}
|
|
268
265
|
}
|
|
269
266
|
return d
|
|
@@ -276,6 +273,24 @@ export const Sorting: TableFeature = {
|
|
|
276
273
|
})
|
|
277
274
|
},
|
|
278
275
|
|
|
276
|
+
getNextSortingOrder: () => {
|
|
277
|
+
const sortDescFirst =
|
|
278
|
+
column.columnDef.sortDescFirst ??
|
|
279
|
+
instance.options.sortDescFirst ??
|
|
280
|
+
column.getAutoSortDir() === 'desc'
|
|
281
|
+
const firstSortDirection = sortDescFirst ? 'desc' : 'asc'
|
|
282
|
+
|
|
283
|
+
const isSorted = column.getIsSorted()
|
|
284
|
+
if (!isSorted) {
|
|
285
|
+
return firstSortDirection
|
|
286
|
+
}
|
|
287
|
+
if (isSorted === firstSortDirection) {
|
|
288
|
+
return isSorted === 'desc' ? 'asc' : 'desc'
|
|
289
|
+
} else {
|
|
290
|
+
return false
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
|
|
279
294
|
getCanSort: () => {
|
|
280
295
|
return (
|
|
281
296
|
(column.columnDef.enableSorting ?? true) &&
|
package/src/types.ts
CHANGED
|
@@ -123,7 +123,7 @@ export type TableOptionsResolved<TGenerics extends TableGenerics> =
|
|
|
123
123
|
|
|
124
124
|
export type TableOptions<TGenerics extends TableGenerics> = Omit<
|
|
125
125
|
PartialKeys<TableOptionsResolved<TGenerics>, 'state' | 'onStateChange'>,
|
|
126
|
-
'render'
|
|
126
|
+
'render' | 'renderFallbackValue'
|
|
127
127
|
>
|
|
128
128
|
|
|
129
129
|
export type TableState = CoreTableState &
|
|
@@ -93,13 +93,6 @@ export function getGroupedRowModel<TGenerics extends TableGenerics>(): (
|
|
|
93
93
|
)
|
|
94
94
|
|
|
95
95
|
return row._groupingValuesCache[columnId]
|
|
96
|
-
} else if (column.aggregationFn) {
|
|
97
|
-
console.info({ column })
|
|
98
|
-
throw new Error(
|
|
99
|
-
process.env.NODE_ENV !== 'production'
|
|
100
|
-
? `Table: Invalid column.aggregateType option for column listed above`
|
|
101
|
-
: ''
|
|
102
|
-
)
|
|
103
96
|
}
|
|
104
97
|
},
|
|
105
98
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TableInstance, RowModel, TableGenerics } from '../types'
|
|
1
|
+
import { TableInstance, RowModel, TableGenerics, Row } from '../types'
|
|
2
2
|
import { memo } from '../utils'
|
|
3
3
|
import { expandRows } from './getExpandedRowModel'
|
|
4
4
|
|
|
@@ -23,8 +23,10 @@ export function getPaginationRowModel<TGenerics extends TableGenerics>(opts?: {
|
|
|
23
23
|
|
|
24
24
|
rows = rows.slice(pageStart, pageEnd)
|
|
25
25
|
|
|
26
|
+
let paginatedRowModel: RowModel<TGenerics>
|
|
27
|
+
|
|
26
28
|
if (!instance.options.paginateExpandedRows) {
|
|
27
|
-
|
|
29
|
+
paginatedRowModel = expandRows(
|
|
28
30
|
{
|
|
29
31
|
rows,
|
|
30
32
|
flatRows,
|
|
@@ -32,13 +34,26 @@ export function getPaginationRowModel<TGenerics extends TableGenerics>(opts?: {
|
|
|
32
34
|
},
|
|
33
35
|
instance
|
|
34
36
|
)
|
|
37
|
+
} else {
|
|
38
|
+
paginatedRowModel = {
|
|
39
|
+
rows,
|
|
40
|
+
flatRows,
|
|
41
|
+
rowsById,
|
|
42
|
+
}
|
|
35
43
|
}
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
paginatedRowModel.flatRows = []
|
|
46
|
+
|
|
47
|
+
const handleRow = (row: Row<TGenerics>) => {
|
|
48
|
+
paginatedRowModel.flatRows.push(row)
|
|
49
|
+
if (row.subRows.length) {
|
|
50
|
+
row.subRows.forEach(handleRow)
|
|
51
|
+
}
|
|
41
52
|
}
|
|
53
|
+
|
|
54
|
+
paginatedRowModel.rows.forEach(handleRow)
|
|
55
|
+
|
|
56
|
+
return paginatedRowModel
|
|
42
57
|
},
|
|
43
58
|
{
|
|
44
59
|
key: process.env.NODE_ENV === 'development' && 'getPaginationRowModel',
|