@tanstack/table-core 8.3.6 → 8.5.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.3.6",
4
+ "version": "8.5.1",
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",
@@ -1,5 +1,5 @@
1
1
  import { AccessorFn, ColumnDef, RowData } from './types'
2
- import { DeepKeys, DeepValue } from './utils'
2
+ import { DeepKeys, DeepValue, RequiredKeys } from './utils'
3
3
 
4
4
  // type Person = {
5
5
  // firstName: string
@@ -53,6 +53,18 @@ export type ColumnHelper<TData extends RowData> = {
53
53
  accessor: TAccessor,
54
54
  column: Omit<ColumnDef<TData, TValue>, 'accessorKey'>
55
55
  ) => ColumnDef<TData, TValue>
56
+ display: (
57
+ column: RequiredKeys<
58
+ Omit<ColumnDef<TData, unknown>, 'accessorKey' | 'accessorFn'>,
59
+ 'id'
60
+ >
61
+ ) => ColumnDef<TData, unknown>
62
+ group: (
63
+ column: RequiredKeys<
64
+ Omit<ColumnDef<TData, unknown>, 'accessorKey' | 'accessorFn'>,
65
+ 'id' | 'columns'
66
+ >
67
+ ) => ColumnDef<TData, unknown>
56
68
  }
57
69
 
58
70
  export function createColumnHelper<
@@ -70,5 +82,7 @@ export function createColumnHelper<
70
82
  accessorKey: accessor,
71
83
  }
72
84
  },
85
+ display: column => column as ColumnDef<TData, unknown>,
86
+ group: column => column as ColumnDef<TData, unknown>,
73
87
  }
74
88
  }
@@ -9,6 +9,7 @@ import {
9
9
  Updater,
10
10
  RowData,
11
11
  FilterMeta,
12
+ FilterFns,
12
13
  } from '../types'
13
14
  import { functionalUpdate, isFunction, makeStateUpdater } from '../utils'
14
15
 
@@ -60,6 +61,7 @@ export type CustomFilterFns<TData extends RowData> = Record<
60
61
  export type FilterFnOption<TData extends RowData> =
61
62
  | 'auto'
62
63
  | BuiltInFilterFn
64
+ | keyof FilterFns
63
65
  | FilterFn<TData>
64
66
 
65
67
  export type FiltersColumnDef<TData extends RowData> = {
@@ -119,7 +121,13 @@ export type FiltersOptions<TData extends RowData> = {
119
121
  table: Table<TData>,
120
122
  columnId: string
121
123
  ) => () => undefined | [number, number]
122
- }
124
+ } & (keyof FilterFns extends never
125
+ ? {
126
+ filterFns?: Record<string, FilterFn<any>>
127
+ }
128
+ : {
129
+ filterFns: Record<keyof FilterFns, FilterFn<any>>
130
+ })
123
131
 
124
132
  export type FiltersInstance<TData extends RowData> = {
125
133
  setColumnFilters: (updater: Updater<ColumnFiltersState>) => void
@@ -219,9 +227,8 @@ export const Filters: TableFeature = {
219
227
  ? column.columnDef.filterFn
220
228
  : column.columnDef.filterFn === 'auto'
221
229
  ? column.getAutoFilterFn()
222
- : (filterFns[
223
- column.columnDef.filterFn as BuiltInFilterFn
224
- ] as FilterFn<TData>)
230
+ : table.options.filterFns?.[column.columnDef.filterFn as string] ??
231
+ filterFns[column.columnDef.filterFn as BuiltInFilterFn]
225
232
  },
226
233
  getCanFilter: () => {
227
234
  return (
@@ -352,7 +359,8 @@ export const Filters: TableFeature = {
352
359
  ? globalFilterFn
353
360
  : globalFilterFn === 'auto'
354
361
  ? table.getGlobalAutoFilterFn()
355
- : (filterFns[globalFilterFn as BuiltInFilterFn] as FilterFn<TData>)
362
+ : table.options.filterFns?.[globalFilterFn as string] ??
363
+ filterFns[globalFilterFn as BuiltInFilterFn]
356
364
  },
357
365
 
358
366
  setColumnFilters: (updater: Updater<ColumnFiltersState>) => {
@@ -394,10 +402,11 @@ export const Filters: TableFeature = {
394
402
  },
395
403
 
396
404
  getPreFilteredRowModel: () => table.getCoreRowModel(),
397
- _getFilteredRowModel:
398
- table.options.getFilteredRowModel &&
399
- table.options.getFilteredRowModel(table),
400
405
  getFilteredRowModel: () => {
406
+ if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
407
+ table._getFilteredRowModel = table.options.getFilteredRowModel(table)
408
+ }
409
+
401
410
  if (table.options.manualFiltering || !table._getFilteredRowModel) {
402
411
  return table.getPreFilteredRowModel()
403
412
  }
@@ -10,8 +10,9 @@ import {
10
10
  Updater,
11
11
  ColumnDefTemplate,
12
12
  RowData,
13
+ AggregationFns,
13
14
  } from '../types'
14
- import { isFunction, makeStateUpdater, Overwrite } from '../utils'
15
+ import { isFunction, makeStateUpdater } from '../utils'
15
16
 
16
17
  export type GroupingState = string[]
17
18
 
@@ -29,6 +30,7 @@ export type CustomAggregationFns = Record<string, AggregationFn<any>>
29
30
 
30
31
  export type AggregationFnOption<TData extends RowData> =
31
32
  | 'auto'
33
+ | keyof AggregationFns
32
34
  | BuiltInAggregationFn
33
35
  | AggregationFn<TData>
34
36
 
@@ -75,7 +77,13 @@ export type GroupingOptions = {
75
77
  enableGrouping?: boolean
76
78
  getGroupedRowModel?: (table: Table<any>) => () => RowModel<any>
77
79
  groupedColumnMode?: false | 'reorder' | 'remove'
78
- }
80
+ } & (keyof AggregationFns extends never
81
+ ? {
82
+ aggregationFns?: Record<string, AggregationFn<any>>
83
+ }
84
+ : {
85
+ aggregationFns: Record<keyof AggregationFns, AggregationFn<any>>
86
+ })
79
87
 
80
88
  export type GroupingColumnMode = false | 'reorder' | 'remove'
81
89
 
@@ -178,9 +186,12 @@ export const Grouping: TableFeature = {
178
186
  ? column.columnDef.aggregationFn
179
187
  : column.columnDef.aggregationFn === 'auto'
180
188
  ? column.getAutoAggregationFn()
181
- : (aggregationFns[
189
+ : table.options.aggregationFns?.[
190
+ column.columnDef.aggregationFn as string
191
+ ] ??
192
+ aggregationFns[
182
193
  column.columnDef.aggregationFn as BuiltInAggregationFn
183
- ] as AggregationFn<TData>)
194
+ ]
184
195
  },
185
196
  }
186
197
  },
@@ -6,9 +6,17 @@ import {
6
6
  sortingFns,
7
7
  } from '../sortingFns'
8
8
 
9
- import { Column, OnChangeFn, Table, Row, Updater, RowData } from '../types'
9
+ import {
10
+ Column,
11
+ OnChangeFn,
12
+ Table,
13
+ Row,
14
+ Updater,
15
+ RowData,
16
+ SortingFns,
17
+ } from '../types'
10
18
 
11
- import { isFunction, makeStateUpdater, Overwrite } from '../utils'
19
+ import { isFunction, makeStateUpdater } from '../utils'
12
20
 
13
21
  export type SortDirection = 'asc' | 'desc'
14
22
 
@@ -34,6 +42,7 @@ export type CustomSortingFns<TData extends RowData> = Record<
34
42
 
35
43
  export type SortingFnOption<TData extends RowData> =
36
44
  | 'auto'
45
+ | keyof SortingFns
37
46
  | BuiltInSortingFn
38
47
  | SortingFn<TData>
39
48
 
@@ -72,7 +81,13 @@ export type SortingOptions<TData extends RowData> = {
72
81
  getSortedRowModel?: (table: Table<any>) => () => RowModel<any>
73
82
  maxMultiSortColCount?: number
74
83
  isMultiSortEvent?: (e: unknown) => boolean
75
- }
84
+ } & (keyof SortingFns extends never
85
+ ? {
86
+ sortingFns?: Record<string, SortingFn<any>>
87
+ }
88
+ : {
89
+ sortingFns: Record<keyof SortingFns, SortingFn<any>>
90
+ })
76
91
 
77
92
  export type SortingInstance<TData extends RowData> = {
78
93
  setSorting: (updater: Updater<SortingState>) => void
@@ -161,9 +176,8 @@ export const Sorting: TableFeature = {
161
176
  ? column.columnDef.sortingFn
162
177
  : column.columnDef.sortingFn === 'auto'
163
178
  ? column.getAutoSortingFn()
164
- : (sortingFns[
165
- column.columnDef.sortingFn as BuiltInSortingFn
166
- ] as SortingFn<TData>)
179
+ : table.options.sortingFns?.[column.columnDef.sortingFn as string] ??
180
+ sortingFns[column.columnDef.sortingFn as BuiltInSortingFn]
167
181
  },
168
182
  toggleSorting: (desc, multi) => {
169
183
  // if (column.columns.length) {
package/src/types.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  } from './features/Pinning'
24
24
  import { CoreHeader, CoreHeaderGroup, HeadersInstance } from './core/headers'
25
25
  import {
26
+ FilterFn,
26
27
  FiltersColumn,
27
28
  FiltersColumnDef,
28
29
  FiltersInstance,
@@ -80,6 +81,9 @@ import { CoreCell } from './core/cell'
80
81
  export interface TableMeta<TData extends RowData> {}
81
82
  export interface ColumnMeta<TData extends RowData, TValue> {}
82
83
  export interface FilterMeta {}
84
+ export interface FilterFns {}
85
+ export interface SortingFns {}
86
+ export interface AggregationFns {}
83
87
 
84
88
  export type Updater<T> = T | ((old: T) => T)
85
89
  export type OnChangeFn<T> = (updaterOrValue: Updater<T>) => void