@tanstack/table-core 8.13.2 → 8.14.0
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/lib/aggregationFns.d.ts +1 -1
- package/build/lib/aggregationFns.js.map +1 -1
- package/build/lib/core/column.js +1 -1
- package/build/lib/core/column.js.map +1 -1
- package/build/lib/core/headers.d.ts +1 -2
- package/build/lib/core/headers.js.map +1 -1
- package/build/lib/core/row.js.map +1 -1
- package/build/lib/core/table.d.ts +7 -11
- package/build/lib/core/table.js +21 -13
- package/build/lib/core/table.js.map +1 -1
- package/build/lib/features/ColumnFaceting.d.ts +34 -0
- package/build/lib/features/ColumnFaceting.js +42 -0
- package/build/lib/features/ColumnFaceting.js.map +1 -0
- package/build/lib/features/{Filters.d.ts → ColumnFiltering.d.ts} +29 -132
- package/build/lib/features/{Filters.js → ColumnFiltering.js} +8 -83
- package/build/lib/features/ColumnFiltering.js.map +1 -0
- package/build/lib/features/{Grouping.d.ts → ColumnGrouping.d.ts} +2 -3
- package/build/lib/features/{Grouping.js → ColumnGrouping.js} +3 -3
- package/build/lib/features/ColumnGrouping.js.map +1 -0
- package/build/lib/features/{Ordering.d.ts → ColumnOrdering.d.ts} +2 -3
- package/build/lib/features/{Ordering.js → ColumnOrdering.js} +9 -9
- package/build/lib/features/ColumnOrdering.js.map +1 -0
- package/build/lib/features/ColumnPinning.d.ts +126 -0
- package/build/lib/features/{Pinning.js → ColumnPinning.js} +4 -115
- package/build/lib/features/ColumnPinning.js.map +1 -0
- package/build/lib/features/ColumnSizing.d.ts +2 -3
- package/build/lib/features/ColumnSizing.js +3 -3
- package/build/lib/features/ColumnSizing.js.map +1 -1
- package/build/lib/features/{Visibility.d.ts → ColumnVisibility.d.ts} +2 -3
- package/build/lib/features/{Visibility.js → ColumnVisibility.js} +3 -3
- package/build/lib/features/ColumnVisibility.js.map +1 -0
- package/build/lib/features/GlobalFiltering.d.ts +100 -0
- package/build/lib/features/GlobalFiltering.js +85 -0
- package/build/lib/features/GlobalFiltering.js.map +1 -0
- package/build/lib/features/{Expanding.d.ts → RowExpanding.d.ts} +2 -3
- package/build/lib/features/{Expanding.js → RowExpanding.js} +3 -3
- package/build/lib/features/RowExpanding.js.map +1 -0
- package/build/lib/features/{Pagination.d.ts → RowPagination.d.ts} +2 -3
- package/build/lib/features/{Pagination.js → RowPagination.js} +3 -3
- package/build/lib/features/RowPagination.js.map +1 -0
- package/build/lib/features/RowPinning.d.ts +98 -0
- package/build/lib/features/RowPinning.js +145 -0
- package/build/lib/features/RowPinning.js.map +1 -0
- package/build/lib/features/RowSelection.d.ts +1 -2
- package/build/lib/features/RowSelection.js.map +1 -1
- package/build/lib/features/{Sorting.d.ts → RowSorting.d.ts} +5 -3
- package/build/lib/features/{Sorting.js → RowSorting.js} +3 -3
- package/build/lib/features/RowSorting.js.map +1 -0
- package/build/lib/filterFns.d.ts +1 -1
- package/build/lib/filterFns.js.map +1 -1
- package/build/lib/index.d.ts +21 -18
- package/build/lib/index.esm.js +1490 -1446
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +47 -41
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1490 -1446
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/sortingFns.d.ts +1 -1
- package/build/lib/sortingFns.js.map +1 -1
- package/build/lib/types.d.ts +30 -16
- package/build/lib/utils/getFilteredRowModel.js.map +1 -1
- package/build/lib/utils/getSortedRowModel.js.map +1 -1
- package/build/umd/index.development.js +1500 -1453
- 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/aggregationFns.ts +1 -1
- package/src/core/column.ts +2 -2
- package/src/core/headers.ts +9 -3
- package/src/core/row.ts +1 -1
- package/src/core/table.ts +40 -32
- package/src/features/ColumnFaceting.ts +84 -0
- package/src/features/{Filters.ts → ColumnFiltering.ts} +44 -279
- package/src/features/{Grouping.ts → ColumnGrouping.ts} +6 -6
- package/src/features/{Ordering.ts → ColumnOrdering.ts} +11 -5
- package/src/features/ColumnPinning.ts +336 -0
- package/src/features/ColumnSizing.ts +10 -3
- package/src/features/{Visibility.ts → ColumnVisibility.ts} +2 -2
- package/src/features/GlobalFiltering.ts +218 -0
- package/src/features/{Expanding.ts → RowExpanding.ts} +9 -3
- package/src/features/{Pagination.ts → RowPagination.ts} +9 -3
- package/src/features/RowPinning.ts +273 -0
- package/src/features/RowSelection.ts +9 -2
- package/src/features/{Sorting.ts → RowSorting.ts} +5 -2
- package/src/filterFns.ts +1 -1
- package/src/index.ts +30 -18
- package/src/sortingFns.ts +1 -1
- package/src/types.ts +60 -23
- package/src/utils/getFilteredRowModel.ts +1 -1
- package/src/utils/getSortedRowModel.ts +1 -1
- package/build/lib/features/Expanding.js.map +0 -1
- package/build/lib/features/Filters.js.map +0 -1
- package/build/lib/features/Grouping.js.map +0 -1
- package/build/lib/features/Ordering.js.map +0 -1
- package/build/lib/features/Pagination.js.map +0 -1
- package/build/lib/features/Pinning.d.ts +0 -222
- package/build/lib/features/Pinning.js.map +0 -1
- package/build/lib/features/Sorting.js.map +0 -1
- package/build/lib/features/Visibility.js.map +0 -1
- package/src/features/Pinning.ts +0 -573
package/package.json
CHANGED
package/src/aggregationFns.ts
CHANGED
package/src/core/column.ts
CHANGED
|
@@ -157,9 +157,9 @@ export function createColumn<TData extends RowData, TValue>(
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
for (const feature of table._features) {
|
|
160
|
-
feature.createColumn?.(column, table)
|
|
160
|
+
feature.createColumn?.(column as Column<TData, TValue>, table)
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
// Yes, we have to convert table to
|
|
163
|
+
// Yes, we have to convert table to unknown, because we know more than the compiler here.
|
|
164
164
|
return column as Column<TData, TValue>
|
|
165
165
|
}
|
package/src/core/headers.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
RowData,
|
|
3
|
+
Column,
|
|
4
|
+
Header,
|
|
5
|
+
HeaderGroup,
|
|
6
|
+
Table,
|
|
7
|
+
TableFeature,
|
|
8
|
+
} from '../types'
|
|
2
9
|
import { getMemoOptions, memo } from '../utils'
|
|
3
|
-
import { TableFeature } from './table'
|
|
4
10
|
|
|
5
11
|
const debug = 'debugHeaders'
|
|
6
12
|
|
|
@@ -250,7 +256,7 @@ function createHeader<TData extends RowData, TValue>(
|
|
|
250
256
|
}
|
|
251
257
|
|
|
252
258
|
table._features.forEach(feature => {
|
|
253
|
-
feature.createHeader?.(header, table)
|
|
259
|
+
feature.createHeader?.(header as Header<TData, TValue>, table)
|
|
254
260
|
})
|
|
255
261
|
|
|
256
262
|
return header as Header<TData, TValue>
|
package/src/core/row.ts
CHANGED
|
@@ -194,7 +194,7 @@ export const createRow = <TData extends RowData>(
|
|
|
194
194
|
|
|
195
195
|
for (let i = 0; i < table._features.length; i++) {
|
|
196
196
|
const feature = table._features[i]
|
|
197
|
-
feature?.createRow?.(row
|
|
197
|
+
feature?.createRow?.(row as Row<TData>, table)
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
return row as Row<TData>
|
package/src/core/table.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
TableMeta,
|
|
16
16
|
ColumnDefResolved,
|
|
17
17
|
GroupColumnDef,
|
|
18
|
+
TableFeature,
|
|
18
19
|
} from '../types'
|
|
19
20
|
|
|
20
21
|
//
|
|
@@ -22,38 +23,33 @@ import { createColumn } from './column'
|
|
|
22
23
|
import { Headers } from './headers'
|
|
23
24
|
//
|
|
24
25
|
|
|
26
|
+
import { ColumnFaceting } from '../features/ColumnFaceting'
|
|
27
|
+
import { ColumnFiltering } from '../features/ColumnFiltering'
|
|
28
|
+
import { ColumnGrouping } from '../features/ColumnGrouping'
|
|
29
|
+
import { ColumnOrdering } from '../features/ColumnOrdering'
|
|
30
|
+
import { ColumnPinning } from '../features/ColumnPinning'
|
|
25
31
|
import { ColumnSizing } from '../features/ColumnSizing'
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { Pinning } from '../features/Pinning'
|
|
32
|
+
import { ColumnVisibility } from '../features/ColumnVisibility'
|
|
33
|
+
import { GlobalFiltering } from '../features/GlobalFiltering'
|
|
34
|
+
import { RowExpanding } from '../features/RowExpanding'
|
|
35
|
+
import { RowPagination } from '../features/RowPagination'
|
|
36
|
+
import { RowPinning } from '../features/RowPinning'
|
|
32
37
|
import { RowSelection } from '../features/RowSelection'
|
|
33
|
-
import {
|
|
34
|
-
import { Visibility } from '../features/Visibility'
|
|
35
|
-
|
|
36
|
-
export interface TableFeature {
|
|
37
|
-
createCell?: (cell: any, column: any, row: any, table: any) => any
|
|
38
|
-
createColumn?: (column: any, table: any) => any
|
|
39
|
-
createHeader?: (column: any, table: any) => any
|
|
40
|
-
createRow?: (row: any, table: any) => any
|
|
41
|
-
createTable?: (table: any) => any
|
|
42
|
-
getDefaultColumnDef?: () => any
|
|
43
|
-
getDefaultOptions?: (table: any) => any
|
|
44
|
-
getInitialState?: (initialState?: InitialTableState) => any
|
|
45
|
-
}
|
|
38
|
+
import { RowSorting } from '../features/RowSorting'
|
|
46
39
|
|
|
47
|
-
const
|
|
40
|
+
const builtInFeatures = [
|
|
48
41
|
Headers,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
ColumnVisibility,
|
|
43
|
+
ColumnOrdering,
|
|
44
|
+
ColumnPinning,
|
|
45
|
+
ColumnFaceting,
|
|
46
|
+
ColumnFiltering,
|
|
47
|
+
GlobalFiltering, //depends on ColumnFiltering and ColumnFaceting
|
|
48
|
+
RowSorting,
|
|
49
|
+
ColumnGrouping, //depends on RowSorting
|
|
50
|
+
RowExpanding,
|
|
51
|
+
RowPagination,
|
|
52
|
+
RowPinning,
|
|
57
53
|
RowSelection,
|
|
58
54
|
ColumnSizing,
|
|
59
55
|
] as const
|
|
@@ -63,6 +59,12 @@ const features = [
|
|
|
63
59
|
export interface CoreTableState {}
|
|
64
60
|
|
|
65
61
|
export interface CoreOptions<TData extends RowData> {
|
|
62
|
+
/**
|
|
63
|
+
* An array of extra features that you can add to the table instance.
|
|
64
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#_features)
|
|
65
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
|
|
66
|
+
*/
|
|
67
|
+
_features?: TableFeature[]
|
|
66
68
|
/**
|
|
67
69
|
* Set this option to override any of the `autoReset...` feature options.
|
|
68
70
|
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#autoresetall)
|
|
@@ -279,11 +281,16 @@ export interface CoreInstance<TData extends RowData> {
|
|
|
279
281
|
export function createTable<TData extends RowData>(
|
|
280
282
|
options: TableOptionsResolved<TData>
|
|
281
283
|
): Table<TData> {
|
|
282
|
-
if (
|
|
284
|
+
if (
|
|
285
|
+
process.env.NODE_ENV !== 'production' &&
|
|
286
|
+
(options.debugAll || options.debugTable)
|
|
287
|
+
) {
|
|
283
288
|
console.info('Creating Table Instance...')
|
|
284
289
|
}
|
|
285
290
|
|
|
286
|
-
|
|
291
|
+
const _features = [...builtInFeatures, ...(options._features ?? [])]
|
|
292
|
+
|
|
293
|
+
let table = { _features } as unknown as Table<TData>
|
|
287
294
|
|
|
288
295
|
const defaultOptions = table._features.reduce((obj, feature) => {
|
|
289
296
|
return Object.assign(obj, feature.getDefaultOptions?.(table))
|
|
@@ -308,14 +315,15 @@ export function createTable<TData extends RowData>(
|
|
|
308
315
|
} as TableState
|
|
309
316
|
|
|
310
317
|
table._features.forEach(feature => {
|
|
311
|
-
initialState = feature.getInitialState?.(initialState) ??
|
|
318
|
+
initialState = (feature.getInitialState?.(initialState) ??
|
|
319
|
+
initialState) as TableState
|
|
312
320
|
})
|
|
313
321
|
|
|
314
322
|
const queued: (() => void)[] = []
|
|
315
323
|
let queuedTimeout = false
|
|
316
324
|
|
|
317
325
|
const coreInstance: CoreInstance<TData> = {
|
|
318
|
-
_features
|
|
326
|
+
_features,
|
|
319
327
|
options: {
|
|
320
328
|
...defaultOptions,
|
|
321
329
|
...options,
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { RowModel } from '..'
|
|
2
|
+
import { Column, RowData, Table, TableFeature } from '../types'
|
|
3
|
+
|
|
4
|
+
export interface FacetedColumn<TData extends RowData> {
|
|
5
|
+
_getFacetedMinMaxValues?: () => undefined | [number, number]
|
|
6
|
+
_getFacetedRowModel?: () => RowModel<TData>
|
|
7
|
+
_getFacetedUniqueValues?: () => Map<any, number>
|
|
8
|
+
/**
|
|
9
|
+
* A function that **computes and returns** a min/max tuple derived from `column.getFacetedRowModel`. Useful for displaying faceted result values.
|
|
10
|
+
* > ⚠️ Requires that you pass a valid `getFacetedMinMaxValues` function to `options.getFacetedMinMaxValues`. A default implementation is provided via the exported `getFacetedMinMaxValues` function.
|
|
11
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfacetedminmaxvalues)
|
|
12
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
13
|
+
*/
|
|
14
|
+
getFacetedMinMaxValues: () => undefined | [number, number]
|
|
15
|
+
/**
|
|
16
|
+
* Returns the row model with all other column filters applied, excluding its own filter. Useful for displaying faceted result counts.
|
|
17
|
+
* > ⚠️ Requires that you pass a valid `getFacetedRowModel` function to `options.facetedRowModel`. A default implementation is provided via the exported `getFacetedRowModel` function.
|
|
18
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfacetedrowmodel)
|
|
19
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
20
|
+
*/
|
|
21
|
+
getFacetedRowModel: () => RowModel<TData>
|
|
22
|
+
/**
|
|
23
|
+
* A function that **computes and returns** a `Map` of unique values and their occurrences derived from `column.getFacetedRowModel`. Useful for displaying faceted result values.
|
|
24
|
+
* > ⚠️ Requires that you pass a valid `getFacetedUniqueValues` function to `options.getFacetedUniqueValues`. A default implementation is provided via the exported `getFacetedUniqueValues` function.
|
|
25
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfaceteduniquevalues)
|
|
26
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
27
|
+
*/
|
|
28
|
+
getFacetedUniqueValues: () => Map<any, number>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface FacetedOptions<TData extends RowData> {
|
|
32
|
+
getFacetedMinMaxValues?: (
|
|
33
|
+
table: Table<TData>,
|
|
34
|
+
columnId: string
|
|
35
|
+
) => () => undefined | [number, number]
|
|
36
|
+
getFacetedRowModel?: (
|
|
37
|
+
table: Table<TData>,
|
|
38
|
+
columnId: string
|
|
39
|
+
) => () => RowModel<TData>
|
|
40
|
+
getFacetedUniqueValues?: (
|
|
41
|
+
table: Table<TData>,
|
|
42
|
+
columnId: string
|
|
43
|
+
) => () => Map<any, number>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//
|
|
47
|
+
|
|
48
|
+
export const ColumnFaceting: TableFeature = {
|
|
49
|
+
createColumn: <TData extends RowData>(
|
|
50
|
+
column: Column<TData, unknown>,
|
|
51
|
+
table: Table<TData>
|
|
52
|
+
): void => {
|
|
53
|
+
column._getFacetedRowModel =
|
|
54
|
+
table.options.getFacetedRowModel &&
|
|
55
|
+
table.options.getFacetedRowModel(table, column.id)
|
|
56
|
+
column.getFacetedRowModel = () => {
|
|
57
|
+
if (!column._getFacetedRowModel) {
|
|
58
|
+
return table.getPreFilteredRowModel()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return column._getFacetedRowModel()
|
|
62
|
+
}
|
|
63
|
+
column._getFacetedUniqueValues =
|
|
64
|
+
table.options.getFacetedUniqueValues &&
|
|
65
|
+
table.options.getFacetedUniqueValues(table, column.id)
|
|
66
|
+
column.getFacetedUniqueValues = () => {
|
|
67
|
+
if (!column._getFacetedUniqueValues) {
|
|
68
|
+
return new Map()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return column._getFacetedUniqueValues()
|
|
72
|
+
}
|
|
73
|
+
column._getFacetedMinMaxValues =
|
|
74
|
+
table.options.getFacetedMinMaxValues &&
|
|
75
|
+
table.options.getFacetedMinMaxValues(table, column.id)
|
|
76
|
+
column.getFacetedMinMaxValues = () => {
|
|
77
|
+
if (!column._getFacetedMinMaxValues) {
|
|
78
|
+
return undefined
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return column._getFacetedMinMaxValues()
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
}
|