@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.
Files changed (108) hide show
  1. package/build/lib/aggregationFns.d.ts +1 -1
  2. package/build/lib/aggregationFns.js.map +1 -1
  3. package/build/lib/core/column.js +1 -1
  4. package/build/lib/core/column.js.map +1 -1
  5. package/build/lib/core/headers.d.ts +1 -2
  6. package/build/lib/core/headers.js.map +1 -1
  7. package/build/lib/core/row.d.ts +1 -1
  8. package/build/lib/core/row.js.map +1 -1
  9. package/build/lib/core/table.d.ts +7 -11
  10. package/build/lib/core/table.js +24 -13
  11. package/build/lib/core/table.js.map +1 -1
  12. package/build/lib/features/ColumnFaceting.d.ts +34 -0
  13. package/build/lib/features/ColumnFaceting.js +42 -0
  14. package/build/lib/features/ColumnFaceting.js.map +1 -0
  15. package/build/lib/features/ColumnFiltering.d.ts +194 -0
  16. package/build/lib/features/{Filters.js → ColumnFiltering.js} +8 -83
  17. package/build/lib/features/ColumnFiltering.js.map +1 -0
  18. package/build/lib/features/{Grouping.d.ts → ColumnGrouping.d.ts} +2 -3
  19. package/build/lib/features/{Grouping.js → ColumnGrouping.js} +3 -3
  20. package/build/lib/features/ColumnGrouping.js.map +1 -0
  21. package/build/lib/features/{Ordering.d.ts → ColumnOrdering.d.ts} +2 -3
  22. package/build/lib/features/{Ordering.js → ColumnOrdering.js} +9 -9
  23. package/build/lib/features/ColumnOrdering.js.map +1 -0
  24. package/build/lib/features/ColumnPinning.d.ts +126 -0
  25. package/build/lib/features/{Pinning.js → ColumnPinning.js} +4 -115
  26. package/build/lib/features/ColumnPinning.js.map +1 -0
  27. package/build/lib/features/ColumnSizing.d.ts +2 -3
  28. package/build/lib/features/ColumnSizing.js +3 -3
  29. package/build/lib/features/ColumnSizing.js.map +1 -1
  30. package/build/lib/features/{Visibility.d.ts → ColumnVisibility.d.ts} +2 -3
  31. package/build/lib/features/{Visibility.js → ColumnVisibility.js} +3 -3
  32. package/build/lib/features/ColumnVisibility.js.map +1 -0
  33. package/build/lib/features/GlobalFaceting.d.ts +26 -0
  34. package/build/lib/features/GlobalFaceting.js +42 -0
  35. package/build/lib/features/GlobalFaceting.js.map +1 -0
  36. package/build/lib/features/GlobalFiltering.d.ts +79 -0
  37. package/build/lib/features/GlobalFiltering.js +63 -0
  38. package/build/lib/features/GlobalFiltering.js.map +1 -0
  39. package/build/lib/features/{Expanding.d.ts → RowExpanding.d.ts} +2 -3
  40. package/build/lib/features/{Expanding.js → RowExpanding.js} +3 -3
  41. package/build/lib/features/RowExpanding.js.map +1 -0
  42. package/build/lib/features/{Pagination.d.ts → RowPagination.d.ts} +2 -3
  43. package/build/lib/features/{Pagination.js → RowPagination.js} +3 -3
  44. package/build/lib/features/RowPagination.js.map +1 -0
  45. package/build/lib/features/RowPinning.d.ts +98 -0
  46. package/build/lib/features/RowPinning.js +145 -0
  47. package/build/lib/features/RowPinning.js.map +1 -0
  48. package/build/lib/features/RowSelection.d.ts +1 -2
  49. package/build/lib/features/RowSelection.js.map +1 -1
  50. package/build/lib/features/{Sorting.d.ts → RowSorting.d.ts} +5 -3
  51. package/build/lib/features/{Sorting.js → RowSorting.js} +3 -3
  52. package/build/lib/features/RowSorting.js.map +1 -0
  53. package/build/lib/filterFns.d.ts +1 -1
  54. package/build/lib/filterFns.js.map +1 -1
  55. package/build/lib/index.d.ts +22 -18
  56. package/build/lib/index.esm.js +1509 -1457
  57. package/build/lib/index.esm.js.map +1 -1
  58. package/build/lib/index.js +49 -41
  59. package/build/lib/index.js.map +1 -1
  60. package/build/lib/index.mjs +1509 -1457
  61. package/build/lib/index.mjs.map +1 -1
  62. package/build/lib/sortingFns.d.ts +1 -1
  63. package/build/lib/sortingFns.js.map +1 -1
  64. package/build/lib/types.d.ts +32 -17
  65. package/build/lib/utils/getFilteredRowModel.js.map +1 -1
  66. package/build/lib/utils/getSortedRowModel.js.map +1 -1
  67. package/build/umd/index.development.js +1520 -1464
  68. package/build/umd/index.development.js.map +1 -1
  69. package/build/umd/index.production.js +1 -1
  70. package/build/umd/index.production.js.map +1 -1
  71. package/package.json +1 -1
  72. package/src/aggregationFns.ts +1 -1
  73. package/src/core/column.ts +2 -2
  74. package/src/core/headers.ts +9 -3
  75. package/src/core/row.ts +1 -1
  76. package/src/core/table.ts +42 -32
  77. package/src/features/ColumnFaceting.ts +84 -0
  78. package/src/features/ColumnFiltering.ts +429 -0
  79. package/src/features/{Grouping.ts → ColumnGrouping.ts} +6 -6
  80. package/src/features/{Ordering.ts → ColumnOrdering.ts} +11 -5
  81. package/src/features/ColumnPinning.ts +336 -0
  82. package/src/features/ColumnSizing.ts +10 -3
  83. package/src/features/{Visibility.ts → ColumnVisibility.ts} +2 -2
  84. package/src/features/GlobalFaceting.ts +66 -0
  85. package/src/features/GlobalFiltering.ts +162 -0
  86. package/src/features/{Expanding.ts → RowExpanding.ts} +9 -3
  87. package/src/features/{Pagination.ts → RowPagination.ts} +9 -3
  88. package/src/features/RowPinning.ts +273 -0
  89. package/src/features/RowSelection.ts +9 -2
  90. package/src/features/{Sorting.ts → RowSorting.ts} +5 -2
  91. package/src/filterFns.ts +1 -1
  92. package/src/index.ts +31 -18
  93. package/src/sortingFns.ts +1 -1
  94. package/src/types.ts +66 -25
  95. package/src/utils/getFilteredRowModel.ts +1 -1
  96. package/src/utils/getSortedRowModel.ts +1 -1
  97. package/build/lib/features/Expanding.js.map +0 -1
  98. package/build/lib/features/Filters.d.ts +0 -297
  99. package/build/lib/features/Filters.js.map +0 -1
  100. package/build/lib/features/Grouping.js.map +0 -1
  101. package/build/lib/features/Ordering.js.map +0 -1
  102. package/build/lib/features/Pagination.js.map +0 -1
  103. package/build/lib/features/Pinning.d.ts +0 -222
  104. package/build/lib/features/Pinning.js.map +0 -1
  105. package/build/lib/features/Sorting.js.map +0 -1
  106. package/build/lib/features/Visibility.js.map +0 -1
  107. package/src/features/Filters.ts +0 -664
  108. package/src/features/Pinning.ts +0 -573
@@ -0,0 +1,336 @@
1
+ import {
2
+ OnChangeFn,
3
+ Updater,
4
+ Table,
5
+ Column,
6
+ Row,
7
+ Cell,
8
+ RowData,
9
+ TableFeature,
10
+ } from '../types'
11
+ import { getMemoOptions, makeStateUpdater, memo } from '../utils'
12
+
13
+ export type ColumnPinningPosition = false | 'left' | 'right'
14
+
15
+ export interface ColumnPinningState {
16
+ left?: string[]
17
+ right?: string[]
18
+ }
19
+
20
+ export interface ColumnPinningTableState {
21
+ columnPinning: ColumnPinningState
22
+ }
23
+
24
+ export interface ColumnPinningOptions {
25
+ /**
26
+ * Enables/disables column pinning for the table. Defaults to `true`.
27
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#enablecolumnpinning)
28
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
29
+ */
30
+ enableColumnPinning?: boolean
31
+ /**
32
+ * @deprecated Use `enableColumnPinning` or `enableRowPinning` instead.
33
+ * Enables/disables all pinning for the table. Defaults to `true`.
34
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#enablepinning)
35
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
36
+ */
37
+ enablePinning?: boolean
38
+ /**
39
+ * If provided, this function will be called with an `updaterFn` when `state.columnPinning` changes. This overrides the default internal state management, so you will also need to supply `state.columnPinning` from your own managed state.
40
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#oncolumnpinningchange)
41
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/oncolumnpinningchange)
42
+ */
43
+ onColumnPinningChange?: OnChangeFn<ColumnPinningState>
44
+ }
45
+
46
+ export interface ColumnPinningDefaultOptions {
47
+ onColumnPinningChange: OnChangeFn<ColumnPinningState>
48
+ }
49
+
50
+ export interface ColumnPinningColumnDef {
51
+ /**
52
+ * Enables/disables column pinning for this column. Defaults to `true`.
53
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#enablepinning-1)
54
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
55
+ */
56
+ enablePinning?: boolean
57
+ }
58
+
59
+ export interface ColumnPinningColumn {
60
+ /**
61
+ * Returns whether or not the column can be pinned.
62
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getcanpin)
63
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
64
+ */
65
+ getCanPin: () => boolean
66
+ /**
67
+ * Returns the pinned position of the column. (`'left'`, `'right'` or `false`)
68
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getispinned)
69
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
70
+ */
71
+ getIsPinned: () => ColumnPinningPosition
72
+ /**
73
+ * Returns the numeric pinned index of the column within a pinned column group.
74
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getpinnedindex)
75
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
76
+ */
77
+ getPinnedIndex: () => number
78
+ /**
79
+ * Pins a column to the `'left'` or `'right'`, or unpins the column to the center if `false` is passed.
80
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#pin)
81
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
82
+ */
83
+ pin: (position: ColumnPinningPosition) => void
84
+ }
85
+
86
+ export interface ColumnPinningRow<TData extends RowData> {
87
+ /**
88
+ * Returns all center pinned (unpinned) leaf cells in the row.
89
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getcentervisiblecells)
90
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
91
+ */
92
+ getCenterVisibleCells: () => Cell<TData, unknown>[]
93
+ /**
94
+ * Returns all left pinned leaf cells in the row.
95
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getleftvisiblecells)
96
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
97
+ */
98
+ getLeftVisibleCells: () => Cell<TData, unknown>[]
99
+ /**
100
+ * Returns all right pinned leaf cells in the row.
101
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getrightvisiblecells)
102
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
103
+ */
104
+ getRightVisibleCells: () => Cell<TData, unknown>[]
105
+ }
106
+
107
+ export interface ColumnPinningInstance<TData extends RowData> {
108
+ /**
109
+ * Returns all center pinned (unpinned) leaf columns.
110
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getcenterleafcolumns)
111
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
112
+ */
113
+ getCenterLeafColumns: () => Column<TData, unknown>[]
114
+ /**
115
+ * Returns whether or not any columns are pinned. Optionally specify to only check for pinned columns in either the `left` or `right` position.
116
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getissomecolumnspinned)
117
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
118
+ */
119
+ getIsSomeColumnsPinned: (position?: ColumnPinningPosition) => boolean
120
+ /**
121
+ * Returns all left pinned leaf columns.
122
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getleftleafcolumns)
123
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
124
+ */
125
+ getLeftLeafColumns: () => Column<TData, unknown>[]
126
+ /**
127
+ * Returns all right pinned leaf columns.
128
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#getrightleafcolumns)
129
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
130
+ */
131
+ getRightLeafColumns: () => Column<TData, unknown>[]
132
+ /**
133
+ * Resets the **columnPinning** state to `initialState.columnPinning`, or `true` can be passed to force a default blank state reset to `{ left: [], right: [], }`.
134
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#resetcolumnpinning)
135
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
136
+ */
137
+ resetColumnPinning: (defaultState?: boolean) => void
138
+ /**
139
+ * Sets or updates the `state.columnPinning` state.
140
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#setcolumnpinning)
141
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning)
142
+ */
143
+ setColumnPinning: (updater: Updater<ColumnPinningState>) => void
144
+ }
145
+
146
+ //
147
+
148
+ const getDefaultColumnPinningState = (): ColumnPinningState => ({
149
+ left: [],
150
+ right: [],
151
+ })
152
+
153
+ export const ColumnPinning: TableFeature = {
154
+ getInitialState: (state): ColumnPinningTableState => {
155
+ return {
156
+ columnPinning: getDefaultColumnPinningState(),
157
+ ...state,
158
+ }
159
+ },
160
+
161
+ getDefaultOptions: <TData extends RowData>(
162
+ table: Table<TData>
163
+ ): ColumnPinningDefaultOptions => {
164
+ return {
165
+ onColumnPinningChange: makeStateUpdater('columnPinning', table),
166
+ }
167
+ },
168
+
169
+ createColumn: <TData extends RowData, TValue>(
170
+ column: Column<TData, TValue>,
171
+ table: Table<TData>
172
+ ): void => {
173
+ column.pin = position => {
174
+ const columnIds = column
175
+ .getLeafColumns()
176
+ .map(d => d.id)
177
+ .filter(Boolean) as string[]
178
+
179
+ table.setColumnPinning(old => {
180
+ if (position === 'right') {
181
+ return {
182
+ left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
183
+ right: [
184
+ ...(old?.right ?? []).filter(d => !columnIds?.includes(d)),
185
+ ...columnIds,
186
+ ],
187
+ }
188
+ }
189
+
190
+ if (position === 'left') {
191
+ return {
192
+ left: [
193
+ ...(old?.left ?? []).filter(d => !columnIds?.includes(d)),
194
+ ...columnIds,
195
+ ],
196
+ right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
197
+ }
198
+ }
199
+
200
+ return {
201
+ left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
202
+ right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
203
+ }
204
+ })
205
+ }
206
+
207
+ column.getCanPin = () => {
208
+ const leafColumns = column.getLeafColumns()
209
+
210
+ return leafColumns.some(
211
+ d =>
212
+ (d.columnDef.enablePinning ?? true) &&
213
+ (table.options.enableColumnPinning ??
214
+ table.options.enablePinning ??
215
+ true)
216
+ )
217
+ }
218
+
219
+ column.getIsPinned = () => {
220
+ const leafColumnIds = column.getLeafColumns().map(d => d.id)
221
+
222
+ const { left, right } = table.getState().columnPinning
223
+
224
+ const isLeft = leafColumnIds.some(d => left?.includes(d))
225
+ const isRight = leafColumnIds.some(d => right?.includes(d))
226
+
227
+ return isLeft ? 'left' : isRight ? 'right' : false
228
+ }
229
+
230
+ column.getPinnedIndex = () => {
231
+ const position = column.getIsPinned()
232
+
233
+ return position
234
+ ? table.getState().columnPinning?.[position]?.indexOf(column.id) ?? -1
235
+ : 0
236
+ }
237
+ },
238
+
239
+ createRow: <TData extends RowData>(
240
+ row: Row<TData>,
241
+ table: Table<TData>
242
+ ): void => {
243
+ row.getCenterVisibleCells = memo(
244
+ () => [
245
+ row._getAllVisibleCells(),
246
+ table.getState().columnPinning.left,
247
+ table.getState().columnPinning.right,
248
+ ],
249
+ (allCells, left, right) => {
250
+ const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
251
+
252
+ return allCells.filter(d => !leftAndRight.includes(d.column.id))
253
+ },
254
+ getMemoOptions(table.options, 'debugRows', 'getCenterVisibleCells')
255
+ )
256
+ row.getLeftVisibleCells = memo(
257
+ () => [row._getAllVisibleCells(), table.getState().columnPinning.left],
258
+ (allCells, left) => {
259
+ const cells = (left ?? [])
260
+ .map(columnId => allCells.find(cell => cell.column.id === columnId)!)
261
+ .filter(Boolean)
262
+ .map(d => ({ ...d, position: 'left' }) as Cell<TData, unknown>)
263
+
264
+ return cells
265
+ },
266
+ getMemoOptions(table.options, 'debugRows', 'getLeftVisibleCells')
267
+ )
268
+ row.getRightVisibleCells = memo(
269
+ () => [row._getAllVisibleCells(), table.getState().columnPinning.right],
270
+ (allCells, right) => {
271
+ const cells = (right ?? [])
272
+ .map(columnId => allCells.find(cell => cell.column.id === columnId)!)
273
+ .filter(Boolean)
274
+ .map(d => ({ ...d, position: 'right' }) as Cell<TData, unknown>)
275
+
276
+ return cells
277
+ },
278
+ getMemoOptions(table.options, 'debugRows', 'getRightVisibleCells')
279
+ )
280
+ },
281
+
282
+ createTable: <TData extends RowData>(table: Table<TData>): void => {
283
+ table.setColumnPinning = updater =>
284
+ table.options.onColumnPinningChange?.(updater)
285
+
286
+ table.resetColumnPinning = defaultState =>
287
+ table.setColumnPinning(
288
+ defaultState
289
+ ? getDefaultColumnPinningState()
290
+ : table.initialState?.columnPinning ?? getDefaultColumnPinningState()
291
+ )
292
+
293
+ table.getIsSomeColumnsPinned = position => {
294
+ const pinningState = table.getState().columnPinning
295
+
296
+ if (!position) {
297
+ return Boolean(pinningState.left?.length || pinningState.right?.length)
298
+ }
299
+ return Boolean(pinningState[position]?.length)
300
+ }
301
+
302
+ table.getLeftLeafColumns = memo(
303
+ () => [table.getAllLeafColumns(), table.getState().columnPinning.left],
304
+ (allColumns, left) => {
305
+ return (left ?? [])
306
+ .map(columnId => allColumns.find(column => column.id === columnId)!)
307
+ .filter(Boolean)
308
+ },
309
+ getMemoOptions(table.options, 'debugColumns', 'getLeftLeafColumns')
310
+ )
311
+
312
+ table.getRightLeafColumns = memo(
313
+ () => [table.getAllLeafColumns(), table.getState().columnPinning.right],
314
+ (allColumns, right) => {
315
+ return (right ?? [])
316
+ .map(columnId => allColumns.find(column => column.id === columnId)!)
317
+ .filter(Boolean)
318
+ },
319
+ getMemoOptions(table.options, 'debugColumns', 'getRightLeafColumns')
320
+ )
321
+
322
+ table.getCenterLeafColumns = memo(
323
+ () => [
324
+ table.getAllLeafColumns(),
325
+ table.getState().columnPinning.left,
326
+ table.getState().columnPinning.right,
327
+ ],
328
+ (allColumns, left, right) => {
329
+ const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
330
+
331
+ return allColumns.filter(d => !leftAndRight.includes(d.id))
332
+ },
333
+ getMemoOptions(table.options, 'debugColumns', 'getCenterLeafColumns')
334
+ )
335
+ },
336
+ }
@@ -1,8 +1,15 @@
1
1
  import { _getVisibleLeafColumns } from '..'
2
- import { TableFeature } from '../core/table'
3
- import { RowData, Column, Header, OnChangeFn, Table, Updater } from '../types'
2
+ import {
3
+ RowData,
4
+ Column,
5
+ Header,
6
+ OnChangeFn,
7
+ Table,
8
+ Updater,
9
+ TableFeature,
10
+ } from '../types'
4
11
  import { getMemoOptions, makeStateUpdater, memo } from '../utils'
5
- import { ColumnPinningPosition } from './Pinning'
12
+ import { ColumnPinningPosition } from './ColumnPinning'
6
13
 
7
14
  //
8
15
 
@@ -1,5 +1,4 @@
1
1
  import { ColumnPinningPosition } from '..'
2
- import { TableFeature } from '../core/table'
3
2
  import {
4
3
  Cell,
5
4
  Column,
@@ -8,6 +7,7 @@ import {
8
7
  Updater,
9
8
  Row,
10
9
  RowData,
10
+ TableFeature,
11
11
  } from '../types'
12
12
  import { getMemoOptions, makeStateUpdater, memo } from '../utils'
13
13
 
@@ -149,7 +149,7 @@ export interface VisibilityColumn {
149
149
 
150
150
  //
151
151
 
152
- export const Visibility: TableFeature = {
152
+ export const ColumnVisibility: TableFeature = {
153
153
  getInitialState: (state): VisibilityTableState => {
154
154
  return {
155
155
  columnVisibility: {},
@@ -0,0 +1,66 @@
1
+ import { RowModel } from '..'
2
+ import { Table, RowData, TableFeature } from '../types'
3
+
4
+ export interface GlobalFacetingInstance<TData extends RowData> {
5
+ _getGlobalFacetedMinMaxValues?: () => undefined | [number, number]
6
+ _getGlobalFacetedRowModel?: () => RowModel<TData>
7
+ _getGlobalFacetedUniqueValues?: () => Map<any, number>
8
+ /**
9
+ * Currently, this function returns the built-in `includesString` filter function. In future releases, it may return more dynamic filter functions based on the nature of the data provided.
10
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-faceting#getglobalautofilterfn)
11
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-faceting)
12
+ */
13
+ getGlobalFacetedMinMaxValues: () => undefined | [number, number]
14
+ /**
15
+ * Returns the row model for the table after **global** filtering has been applied.
16
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-faceting#getglobalfacetedrowmodel)
17
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-faceting)
18
+ */
19
+ getGlobalFacetedRowModel: () => RowModel<TData>
20
+ /**
21
+ * Returns the faceted unique values for the global filter.
22
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-faceting#getglobalfaceteduniquevalues)
23
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-faceting)
24
+ */
25
+ getGlobalFacetedUniqueValues: () => Map<any, number>
26
+ }
27
+
28
+ //
29
+
30
+ export const GlobalFaceting: TableFeature = {
31
+ createTable: <TData extends RowData>(table: Table<TData>): void => {
32
+ table._getGlobalFacetedRowModel =
33
+ table.options.getFacetedRowModel &&
34
+ table.options.getFacetedRowModel(table, '__global__')
35
+
36
+ table.getGlobalFacetedRowModel = () => {
37
+ if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
38
+ return table.getPreFilteredRowModel()
39
+ }
40
+
41
+ return table._getGlobalFacetedRowModel()
42
+ }
43
+
44
+ table._getGlobalFacetedUniqueValues =
45
+ table.options.getFacetedUniqueValues &&
46
+ table.options.getFacetedUniqueValues(table, '__global__')
47
+ table.getGlobalFacetedUniqueValues = () => {
48
+ if (!table._getGlobalFacetedUniqueValues) {
49
+ return new Map()
50
+ }
51
+
52
+ return table._getGlobalFacetedUniqueValues()
53
+ }
54
+
55
+ table._getGlobalFacetedMinMaxValues =
56
+ table.options.getFacetedMinMaxValues &&
57
+ table.options.getFacetedMinMaxValues(table, '__global__')
58
+ table.getGlobalFacetedMinMaxValues = () => {
59
+ if (!table._getGlobalFacetedMinMaxValues) {
60
+ return
61
+ }
62
+
63
+ return table._getGlobalFacetedMinMaxValues()
64
+ }
65
+ },
66
+ }
@@ -0,0 +1,162 @@
1
+ import { FilterFn, FilterFnOption } from '..'
2
+ import { BuiltInFilterFn, filterFns } from '../filterFns'
3
+ import {
4
+ Column,
5
+ OnChangeFn,
6
+ Table,
7
+ Updater,
8
+ RowData,
9
+ TableFeature,
10
+ } from '../types'
11
+ import { isFunction, makeStateUpdater } from '../utils'
12
+
13
+ export interface GlobalFilterTableState {
14
+ globalFilter: any
15
+ }
16
+
17
+ export interface GlobalFilterColumnDef {
18
+ /**
19
+ * Enables/disables the **global** filter for this column.
20
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#enableglobalfilter)
21
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
22
+ */
23
+ enableGlobalFilter?: boolean
24
+ }
25
+
26
+ export interface GlobalFilterColumn {
27
+ /**
28
+ * Returns whether or not the column can be **globally** filtered. Set to `false` to disable a column from being scanned during global filtering.
29
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#getcanglobalfilter)
30
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
31
+ */
32
+ getCanGlobalFilter: () => boolean
33
+ }
34
+
35
+ export interface GlobalFilterOptions<TData extends RowData> {
36
+ /**
37
+ * Enables/disables **global** filtering for all columns.
38
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#enableglobalfilter)
39
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
40
+ */
41
+ enableGlobalFilter?: boolean
42
+ /**
43
+ * If provided, this function will be called with the column and should return `true` or `false` to indicate whether this column should be used for global filtering.
44
+ *
45
+ * This is useful if the column can contain data that is not `string` or `number` (i.e. `undefined`).
46
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#getcolumncanglobalfilter)
47
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
48
+ */
49
+ getColumnCanGlobalFilter?: (column: Column<TData, unknown>) => boolean
50
+ /**
51
+ * The filter function to use for global filtering.
52
+ * - A `string` referencing a built-in filter function
53
+ * - A `string` that references a custom filter functions provided via the `tableOptions.filterFns` option
54
+ * - A custom filter function
55
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#globalfilterfn)
56
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
57
+ */
58
+ globalFilterFn?: FilterFnOption<TData>
59
+ /**
60
+ * If provided, this function will be called with an `updaterFn` when `state.globalFilter` changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
61
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#onglobalfilterchange)
62
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
63
+ */
64
+ onGlobalFilterChange?: OnChangeFn<any>
65
+ }
66
+
67
+ export interface GlobalFilterInstance<TData extends RowData> {
68
+ /**
69
+ * Currently, this function returns the built-in `includesString` filter function. In future releases, it may return more dynamic filter functions based on the nature of the data provided.
70
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#getglobalautofilterfn)
71
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
72
+ */
73
+ getGlobalAutoFilterFn: () => FilterFn<TData> | undefined
74
+ /**
75
+ * Returns the filter function (either user-defined or automatic, depending on configuration) for the global filter.
76
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#getglobalfilterfn)
77
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
78
+ */
79
+ getGlobalFilterFn: () => FilterFn<TData> | undefined
80
+ /**
81
+ * Resets the **globalFilter** state to `initialState.globalFilter`, or `true` can be passed to force a default blank state reset to `undefined`.
82
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#resetglobalfilter)
83
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
84
+ */
85
+ resetGlobalFilter: (defaultState?: boolean) => void
86
+ /**
87
+ * Sets or updates the `state.globalFilter` state.
88
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#setglobalfilter)
89
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
90
+ */
91
+ setGlobalFilter: (updater: Updater<any>) => void
92
+ }
93
+
94
+ //
95
+
96
+ export const GlobalFiltering: TableFeature = {
97
+ getInitialState: (state): GlobalFilterTableState => {
98
+ return {
99
+ globalFilter: undefined,
100
+ ...state,
101
+ }
102
+ },
103
+
104
+ getDefaultOptions: <TData extends RowData>(
105
+ table: Table<TData>
106
+ ): GlobalFilterOptions<TData> => {
107
+ return {
108
+ onGlobalFilterChange: makeStateUpdater('globalFilter', table),
109
+ globalFilterFn: 'auto',
110
+ getColumnCanGlobalFilter: column => {
111
+ const value = table
112
+ .getCoreRowModel()
113
+ .flatRows[0]?._getAllCellsByColumnId()
114
+ [column.id]?.getValue()
115
+
116
+ return typeof value === 'string' || typeof value === 'number'
117
+ },
118
+ } as GlobalFilterOptions<TData>
119
+ },
120
+
121
+ createColumn: <TData extends RowData>(
122
+ column: Column<TData, unknown>,
123
+ table: Table<TData>
124
+ ): void => {
125
+ column.getCanGlobalFilter = () => {
126
+ return (
127
+ (column.columnDef.enableGlobalFilter ?? true) &&
128
+ (table.options.enableGlobalFilter ?? true) &&
129
+ (table.options.enableFilters ?? true) &&
130
+ (table.options.getColumnCanGlobalFilter?.(column) ?? true) &&
131
+ !!column.accessorFn
132
+ )
133
+ }
134
+ },
135
+
136
+ createTable: <TData extends RowData>(table: Table<TData>): void => {
137
+ table.getGlobalAutoFilterFn = () => {
138
+ return filterFns.includesString
139
+ }
140
+
141
+ table.getGlobalFilterFn = () => {
142
+ const { globalFilterFn: globalFilterFn } = table.options
143
+
144
+ return isFunction(globalFilterFn)
145
+ ? globalFilterFn
146
+ : globalFilterFn === 'auto'
147
+ ? table.getGlobalAutoFilterFn()
148
+ : table.options.filterFns?.[globalFilterFn as string] ??
149
+ filterFns[globalFilterFn as BuiltInFilterFn]
150
+ }
151
+
152
+ table.setGlobalFilter = updater => {
153
+ table.options.onGlobalFilterChange?.(updater)
154
+ }
155
+
156
+ table.resetGlobalFilter = defaultState => {
157
+ table.setGlobalFilter(
158
+ defaultState ? undefined : table.initialState.globalFilter
159
+ )
160
+ }
161
+ },
162
+ }
@@ -1,6 +1,12 @@
1
1
  import { RowModel } from '..'
2
- import { TableFeature } from '../core/table'
3
- import { OnChangeFn, Table, Row, Updater, RowData } from '../types'
2
+ import {
3
+ OnChangeFn,
4
+ Table,
5
+ Row,
6
+ Updater,
7
+ RowData,
8
+ TableFeature,
9
+ } from '../types'
4
10
  import { makeStateUpdater } from '../utils'
5
11
 
6
12
  export type ExpandedStateList = Record<string, boolean>
@@ -160,7 +166,7 @@ export interface ExpandedInstance<TData extends RowData> {
160
166
 
161
167
  //
162
168
 
163
- export const Expanding: TableFeature = {
169
+ export const RowExpanding: TableFeature = {
164
170
  getInitialState: (state): ExpandedTableState => {
165
171
  return {
166
172
  expanded: {},
@@ -1,5 +1,11 @@
1
- import { TableFeature } from '../core/table'
2
- import { OnChangeFn, Table, RowModel, Updater, RowData } from '../types'
1
+ import {
2
+ OnChangeFn,
3
+ Table,
4
+ RowModel,
5
+ Updater,
6
+ RowData,
7
+ TableFeature,
8
+ } from '../types'
3
9
  import {
4
10
  functionalUpdate,
5
11
  getMemoOptions,
@@ -186,7 +192,7 @@ const getDefaultPaginationState = (): PaginationState => ({
186
192
  pageSize: defaultPageSize,
187
193
  })
188
194
 
189
- export const Pagination: TableFeature = {
195
+ export const RowPagination: TableFeature = {
190
196
  getInitialState: (state): PaginationTableState => {
191
197
  return {
192
198
  ...state,