@tanstack/table-core 8.13.2 → 8.15.1
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.d.ts +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 +24 -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/ColumnFiltering.d.ts +194 -0
- 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/GlobalFaceting.d.ts +26 -0
- package/build/lib/features/GlobalFaceting.js +42 -0
- package/build/lib/features/GlobalFaceting.js.map +1 -0
- package/build/lib/features/GlobalFiltering.d.ts +79 -0
- package/build/lib/features/GlobalFiltering.js +63 -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 +22 -18
- package/build/lib/index.esm.js +1509 -1457
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +49 -41
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1509 -1457
- 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 +32 -17
- package/build/lib/utils/getFilteredRowModel.js.map +1 -1
- package/build/lib/utils/getSortedRowModel.js.map +1 -1
- package/build/umd/index.development.js +1520 -1464
- 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 +42 -32
- package/src/features/ColumnFaceting.ts +84 -0
- package/src/features/ColumnFiltering.ts +429 -0
- 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/GlobalFaceting.ts +66 -0
- package/src/features/GlobalFiltering.ts +162 -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 +31 -18
- package/src/sortingFns.ts +1 -1
- package/src/types.ts +66 -25
- 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.d.ts +0 -297
- 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/Filters.ts +0 -664
- 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,35 @@ 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 {
|
|
32
|
+
import { ColumnVisibility } from '../features/ColumnVisibility'
|
|
33
|
+
import { GlobalFaceting } from '../features/GlobalFaceting'
|
|
34
|
+
import { GlobalFiltering } from '../features/GlobalFiltering'
|
|
35
|
+
import { RowExpanding } from '../features/RowExpanding'
|
|
36
|
+
import { RowPagination } from '../features/RowPagination'
|
|
37
|
+
import { RowPinning } from '../features/RowPinning'
|
|
32
38
|
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
|
-
}
|
|
39
|
+
import { RowSorting } from '../features/RowSorting'
|
|
46
40
|
|
|
47
|
-
const
|
|
41
|
+
const builtInFeatures = [
|
|
48
42
|
Headers,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
ColumnVisibility,
|
|
44
|
+
ColumnOrdering,
|
|
45
|
+
ColumnPinning,
|
|
46
|
+
ColumnFaceting,
|
|
47
|
+
ColumnFiltering,
|
|
48
|
+
GlobalFaceting, //depends on ColumnFaceting
|
|
49
|
+
GlobalFiltering, //depends on ColumnFiltering
|
|
50
|
+
RowSorting,
|
|
51
|
+
ColumnGrouping, //depends on RowSorting
|
|
52
|
+
RowExpanding,
|
|
53
|
+
RowPagination,
|
|
54
|
+
RowPinning,
|
|
57
55
|
RowSelection,
|
|
58
56
|
ColumnSizing,
|
|
59
57
|
] as const
|
|
@@ -63,6 +61,12 @@ const features = [
|
|
|
63
61
|
export interface CoreTableState {}
|
|
64
62
|
|
|
65
63
|
export interface CoreOptions<TData extends RowData> {
|
|
64
|
+
/**
|
|
65
|
+
* An array of extra features that you can add to the table instance.
|
|
66
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#_features)
|
|
67
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
|
|
68
|
+
*/
|
|
69
|
+
_features?: TableFeature[]
|
|
66
70
|
/**
|
|
67
71
|
* Set this option to override any of the `autoReset...` feature options.
|
|
68
72
|
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#autoresetall)
|
|
@@ -279,11 +283,16 @@ export interface CoreInstance<TData extends RowData> {
|
|
|
279
283
|
export function createTable<TData extends RowData>(
|
|
280
284
|
options: TableOptionsResolved<TData>
|
|
281
285
|
): Table<TData> {
|
|
282
|
-
if (
|
|
286
|
+
if (
|
|
287
|
+
process.env.NODE_ENV !== 'production' &&
|
|
288
|
+
(options.debugAll || options.debugTable)
|
|
289
|
+
) {
|
|
283
290
|
console.info('Creating Table Instance...')
|
|
284
291
|
}
|
|
285
292
|
|
|
286
|
-
|
|
293
|
+
const _features = [...builtInFeatures, ...(options._features ?? [])]
|
|
294
|
+
|
|
295
|
+
let table = { _features } as unknown as Table<TData>
|
|
287
296
|
|
|
288
297
|
const defaultOptions = table._features.reduce((obj, feature) => {
|
|
289
298
|
return Object.assign(obj, feature.getDefaultOptions?.(table))
|
|
@@ -308,14 +317,15 @@ export function createTable<TData extends RowData>(
|
|
|
308
317
|
} as TableState
|
|
309
318
|
|
|
310
319
|
table._features.forEach(feature => {
|
|
311
|
-
initialState = feature.getInitialState?.(initialState) ??
|
|
320
|
+
initialState = (feature.getInitialState?.(initialState) ??
|
|
321
|
+
initialState) as TableState
|
|
312
322
|
})
|
|
313
323
|
|
|
314
324
|
const queued: (() => void)[] = []
|
|
315
325
|
let queuedTimeout = false
|
|
316
326
|
|
|
317
327
|
const coreInstance: CoreInstance<TData> = {
|
|
318
|
-
_features
|
|
328
|
+
_features,
|
|
319
329
|
options: {
|
|
320
330
|
...defaultOptions,
|
|
321
331
|
...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/column-faceting#getfacetedminmaxvalues)
|
|
12
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting)
|
|
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/column-faceting#getfacetedrowmodel)
|
|
19
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting)
|
|
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/column-faceting#getfaceteduniquevalues)
|
|
26
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting)
|
|
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
|
+
}
|