@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/src/features/Filters.ts
DELETED
|
@@ -1,664 +0,0 @@
|
|
|
1
|
-
import { RowModel } from '..'
|
|
2
|
-
import { TableFeature } from '../core/table'
|
|
3
|
-
import { BuiltInFilterFn, filterFns } from '../filterFns'
|
|
4
|
-
import {
|
|
5
|
-
Column,
|
|
6
|
-
OnChangeFn,
|
|
7
|
-
Table,
|
|
8
|
-
Row,
|
|
9
|
-
Updater,
|
|
10
|
-
RowData,
|
|
11
|
-
FilterMeta,
|
|
12
|
-
FilterFns,
|
|
13
|
-
} from '../types'
|
|
14
|
-
import { functionalUpdate, isFunction, makeStateUpdater } from '../utils'
|
|
15
|
-
|
|
16
|
-
export interface FiltersTableState {
|
|
17
|
-
columnFilters: ColumnFiltersState
|
|
18
|
-
globalFilter: any
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type ColumnFiltersState = ColumnFilter[]
|
|
22
|
-
|
|
23
|
-
export interface ColumnFilter {
|
|
24
|
-
id: string
|
|
25
|
-
value: unknown
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface ResolvedColumnFilter<TData extends RowData> {
|
|
29
|
-
id: string
|
|
30
|
-
resolvedValue: unknown
|
|
31
|
-
filterFn: FilterFn<TData>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface FilterFn<TData extends RowData> {
|
|
35
|
-
(
|
|
36
|
-
row: Row<TData>,
|
|
37
|
-
columnId: string,
|
|
38
|
-
filterValue: any,
|
|
39
|
-
addMeta: (meta: FilterMeta) => void
|
|
40
|
-
): boolean
|
|
41
|
-
|
|
42
|
-
resolveFilterValue?: TransformFilterValueFn<TData>
|
|
43
|
-
autoRemove?: ColumnFilterAutoRemoveTestFn<TData>
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type TransformFilterValueFn<TData extends RowData> = (
|
|
47
|
-
value: any,
|
|
48
|
-
column?: Column<TData, unknown>
|
|
49
|
-
) => unknown
|
|
50
|
-
|
|
51
|
-
export type ColumnFilterAutoRemoveTestFn<TData extends RowData> = (
|
|
52
|
-
value: any,
|
|
53
|
-
column?: Column<TData, unknown>
|
|
54
|
-
) => boolean
|
|
55
|
-
|
|
56
|
-
export type CustomFilterFns<TData extends RowData> = Record<
|
|
57
|
-
string,
|
|
58
|
-
FilterFn<TData>
|
|
59
|
-
>
|
|
60
|
-
|
|
61
|
-
export type FilterFnOption<TData extends RowData> =
|
|
62
|
-
| 'auto'
|
|
63
|
-
| BuiltInFilterFn
|
|
64
|
-
| keyof FilterFns
|
|
65
|
-
| FilterFn<TData>
|
|
66
|
-
|
|
67
|
-
export interface FiltersColumnDef<TData extends RowData> {
|
|
68
|
-
/**
|
|
69
|
-
* The filter function to use with this column. Can be the name of a built-in filter function or a custom filter function.
|
|
70
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#filterfn)
|
|
71
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
72
|
-
*/
|
|
73
|
-
filterFn?: FilterFnOption<TData>
|
|
74
|
-
/**
|
|
75
|
-
* Enables/disables the **column** filter for this column.
|
|
76
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#enablecolumnfilter)
|
|
77
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
78
|
-
*/
|
|
79
|
-
enableColumnFilter?: boolean
|
|
80
|
-
/**
|
|
81
|
-
* Enables/disables the **global** filter for this column.
|
|
82
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#enableglobalfilter)
|
|
83
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
84
|
-
*/
|
|
85
|
-
enableGlobalFilter?: boolean
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface FiltersColumn<TData extends RowData> {
|
|
89
|
-
_getFacetedMinMaxValues?: () => undefined | [number, number]
|
|
90
|
-
_getFacetedRowModel?: () => RowModel<TData>
|
|
91
|
-
_getFacetedUniqueValues?: () => Map<any, number>
|
|
92
|
-
/**
|
|
93
|
-
* Returns an automatically calculated filter function for the column based off of the columns first known value.
|
|
94
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getautofilterfn)
|
|
95
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
96
|
-
*/
|
|
97
|
-
getAutoFilterFn: () => FilterFn<TData> | undefined
|
|
98
|
-
/**
|
|
99
|
-
* Returns whether or not the column can be **column** filtered.
|
|
100
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getcanfilter)
|
|
101
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
102
|
-
*/
|
|
103
|
-
getCanFilter: () => boolean
|
|
104
|
-
/**
|
|
105
|
-
* Returns whether or not the column can be **globally** filtered. Set to `false` to disable a column from being scanned during global filtering.
|
|
106
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getcanglobalfilter)
|
|
107
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
108
|
-
*/
|
|
109
|
-
getCanGlobalFilter: () => boolean
|
|
110
|
-
/**
|
|
111
|
-
* A function that **computes and returns** a min/max tuple derived from `column.getFacetedRowModel`. Useful for displaying faceted result values.
|
|
112
|
-
* > ⚠️ Requires that you pass a valid `getFacetedMinMaxValues` function to `options.getFacetedMinMaxValues`. A default implementation is provided via the exported `getFacetedMinMaxValues` function.
|
|
113
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfacetedminmaxvalues)
|
|
114
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
115
|
-
*/
|
|
116
|
-
getFacetedMinMaxValues: () => undefined | [number, number]
|
|
117
|
-
/**
|
|
118
|
-
* Returns the row model with all other column filters applied, excluding its own filter. Useful for displaying faceted result counts.
|
|
119
|
-
* > ⚠️ Requires that you pass a valid `getFacetedRowModel` function to `options.facetedRowModel`. A default implementation is provided via the exported `getFacetedRowModel` function.
|
|
120
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfacetedrowmodel)
|
|
121
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
122
|
-
*/
|
|
123
|
-
getFacetedRowModel: () => RowModel<TData>
|
|
124
|
-
/**
|
|
125
|
-
* A function that **computes and returns** a `Map` of unique values and their occurrences derived from `column.getFacetedRowModel`. Useful for displaying faceted result values.
|
|
126
|
-
* > ⚠️ Requires that you pass a valid `getFacetedUniqueValues` function to `options.getFacetedUniqueValues`. A default implementation is provided via the exported `getFacetedUniqueValues` function.
|
|
127
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfaceteduniquevalues)
|
|
128
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
129
|
-
*/
|
|
130
|
-
getFacetedUniqueValues: () => Map<any, number>
|
|
131
|
-
/**
|
|
132
|
-
* Returns the filter function (either user-defined or automatic, depending on configuration) for the columnId specified.
|
|
133
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfilterfn)
|
|
134
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
135
|
-
*/
|
|
136
|
-
getFilterFn: () => FilterFn<TData> | undefined
|
|
137
|
-
/**
|
|
138
|
-
* Returns the index (including `-1`) of the column filter in the table's `state.columnFilters` array.
|
|
139
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfilterindex)
|
|
140
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
141
|
-
*/
|
|
142
|
-
getFilterIndex: () => number
|
|
143
|
-
/**
|
|
144
|
-
* Returns the current filter value for the column.
|
|
145
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfiltervalue)
|
|
146
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
147
|
-
*/
|
|
148
|
-
getFilterValue: () => unknown
|
|
149
|
-
/**
|
|
150
|
-
* Returns whether or not the column is currently filtered.
|
|
151
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getisfiltered)
|
|
152
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
153
|
-
*/
|
|
154
|
-
getIsFiltered: () => boolean
|
|
155
|
-
/**
|
|
156
|
-
* A function that sets the current filter value for the column. You can pass it a value or an updater function for immutability-safe operations on existing values.
|
|
157
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#setfiltervalue)
|
|
158
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
159
|
-
*/
|
|
160
|
-
setFilterValue: (updater: Updater<any>) => void
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export interface FiltersRow<TData extends RowData> {
|
|
164
|
-
/**
|
|
165
|
-
* The column filters map for the row. This object tracks whether a row is passing/failing specific filters by their column ID.
|
|
166
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#columnfilters)
|
|
167
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
168
|
-
*/
|
|
169
|
-
columnFilters: Record<string, boolean>
|
|
170
|
-
/**
|
|
171
|
-
* The column filters meta map for the row. This object tracks any filter meta for a row as optionally provided during the filtering process.
|
|
172
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#columnfiltersmeta)
|
|
173
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
174
|
-
*/
|
|
175
|
-
columnFiltersMeta: Record<string, FilterMeta>
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
interface FiltersOptionsBase<TData extends RowData> {
|
|
179
|
-
/**
|
|
180
|
-
* Enables/disables all filtering for the table.
|
|
181
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#enablefilters)
|
|
182
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
183
|
-
*/
|
|
184
|
-
enableFilters?: boolean
|
|
185
|
-
/**
|
|
186
|
-
* By default, filtering is done from parent rows down (so if a parent row is filtered out, all of its children will be filtered out as well). Setting this option to `true` will cause filtering to be done from leaf rows up (which means parent rows will be included so long as one of their child or grand-child rows is also included).
|
|
187
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#filterfromleafrows)
|
|
188
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
189
|
-
*/
|
|
190
|
-
filterFromLeafRows?: boolean
|
|
191
|
-
/**
|
|
192
|
-
* If provided, this function is called **once** per table and should return a **new function** which will calculate and return the row model for the table when it's filtered.
|
|
193
|
-
* - For server-side filtering, this function is unnecessary and can be ignored since the server should already return the filtered row model.
|
|
194
|
-
* - For client-side filtering, this function is required. A default implementation is provided via any table adapter's `{ getFilteredRowModel }` export.
|
|
195
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfilteredrowmodel)
|
|
196
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
197
|
-
*/
|
|
198
|
-
getFilteredRowModel?: (table: Table<any>) => () => RowModel<any>
|
|
199
|
-
/**
|
|
200
|
-
* Disables the `getFilteredRowModel` from being used to filter data. This may be useful if your table needs to dynamically support both client-side and server-side filtering.
|
|
201
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#manualfiltering)
|
|
202
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
203
|
-
*/
|
|
204
|
-
manualFiltering?: boolean
|
|
205
|
-
/**
|
|
206
|
-
* By default, filtering is done for all rows (max depth of 100), no matter if they are root level parent rows or the child leaf rows of a parent row. Setting this option to `0` will cause filtering to only be applied to the root level parent rows, with all sub-rows remaining unfiltered. Similarly, setting this option to `1` will cause filtering to only be applied to child leaf rows 1 level deep, and so on.
|
|
207
|
-
|
|
208
|
-
* This is useful for situations where you want a row's entire child hierarchy to be visible regardless of the applied filter.
|
|
209
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#maxleafrowfilterdepth)
|
|
210
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
211
|
-
*/
|
|
212
|
-
maxLeafRowFilterDepth?: number
|
|
213
|
-
|
|
214
|
-
// Column
|
|
215
|
-
/**
|
|
216
|
-
* Enables/disables **column** filtering for all columns.
|
|
217
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#enablecolumnfilters)
|
|
218
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
219
|
-
*/
|
|
220
|
-
enableColumnFilters?: boolean
|
|
221
|
-
/**
|
|
222
|
-
* If provided, this function will be called with an `updaterFn` when `state.columnFilters` 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.
|
|
223
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#oncolumnfilterschange)
|
|
224
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
225
|
-
*/
|
|
226
|
-
onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>
|
|
227
|
-
|
|
228
|
-
// Global
|
|
229
|
-
/**
|
|
230
|
-
* Enables/disables **global** filtering for all columns.
|
|
231
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#enableglobalfilter)
|
|
232
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
233
|
-
*/
|
|
234
|
-
enableGlobalFilter?: boolean
|
|
235
|
-
/**
|
|
236
|
-
* 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.
|
|
237
|
-
*
|
|
238
|
-
* This is useful if the column can contain data that is not `string` or `number` (i.e. `undefined`).
|
|
239
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getcolumncanglobalfilter)
|
|
240
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
241
|
-
*/
|
|
242
|
-
getColumnCanGlobalFilter?: (column: Column<TData, unknown>) => boolean
|
|
243
|
-
/**
|
|
244
|
-
* The filter function to use for global filtering.
|
|
245
|
-
* - A `string` referencing a built-in filter function
|
|
246
|
-
* - A `string` that references a custom filter functions provided via the `tableOptions.filterFns` option
|
|
247
|
-
* - A custom filter function
|
|
248
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#globalfilterfn)
|
|
249
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
250
|
-
*/
|
|
251
|
-
globalFilterFn?: FilterFnOption<TData>
|
|
252
|
-
/**
|
|
253
|
-
* 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.
|
|
254
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#onglobalfilterchange)
|
|
255
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
256
|
-
*/
|
|
257
|
-
onGlobalFilterChange?: OnChangeFn<any>
|
|
258
|
-
|
|
259
|
-
// Faceting
|
|
260
|
-
getFacetedRowModel?: (
|
|
261
|
-
table: Table<TData>,
|
|
262
|
-
columnId: string
|
|
263
|
-
) => () => RowModel<TData>
|
|
264
|
-
getFacetedUniqueValues?: (
|
|
265
|
-
table: Table<TData>,
|
|
266
|
-
columnId: string
|
|
267
|
-
) => () => Map<any, number>
|
|
268
|
-
getFacetedMinMaxValues?: (
|
|
269
|
-
table: Table<TData>,
|
|
270
|
-
columnId: string
|
|
271
|
-
) => () => undefined | [number, number]
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
type ResolvedFilterFns = keyof FilterFns extends never
|
|
275
|
-
? {
|
|
276
|
-
filterFns?: Record<string, FilterFn<any>>
|
|
277
|
-
}
|
|
278
|
-
: {
|
|
279
|
-
filterFns: Record<keyof FilterFns, FilterFn<any>>
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export interface FiltersOptions<TData extends RowData>
|
|
283
|
-
extends FiltersOptionsBase<TData>,
|
|
284
|
-
ResolvedFilterFns {}
|
|
285
|
-
|
|
286
|
-
export interface FiltersInstance<TData extends RowData> {
|
|
287
|
-
/**
|
|
288
|
-
* Sets or updates the `state.columnFilters` state.
|
|
289
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#setcolumnfilters)
|
|
290
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
291
|
-
*/
|
|
292
|
-
setColumnFilters: (updater: Updater<ColumnFiltersState>) => void
|
|
293
|
-
/**
|
|
294
|
-
* Resets the **columnFilters** state to `initialState.columnFilters`, or `true` can be passed to force a default blank state reset to `[]`.
|
|
295
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#resetcolumnfilters)
|
|
296
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
297
|
-
*/
|
|
298
|
-
resetColumnFilters: (defaultState?: boolean) => void
|
|
299
|
-
|
|
300
|
-
// Column Filters
|
|
301
|
-
_getFilteredRowModel?: () => RowModel<TData>
|
|
302
|
-
/**
|
|
303
|
-
* Returns the row model for the table after **column** filtering has been applied.
|
|
304
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getfilteredrowmodel)
|
|
305
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
306
|
-
*/
|
|
307
|
-
getFilteredRowModel: () => RowModel<TData>
|
|
308
|
-
/**
|
|
309
|
-
* Returns the row model for the table before any **column** filtering has been applied.
|
|
310
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getprefilteredrowmodel)
|
|
311
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
312
|
-
*/
|
|
313
|
-
getPreFilteredRowModel: () => RowModel<TData>
|
|
314
|
-
|
|
315
|
-
// Global Filters
|
|
316
|
-
_getGlobalFacetedMinMaxValues?: () => undefined | [number, number]
|
|
317
|
-
_getGlobalFacetedRowModel?: () => RowModel<TData>
|
|
318
|
-
_getGlobalFacetedUniqueValues?: () => Map<any, number>
|
|
319
|
-
/**
|
|
320
|
-
* 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.
|
|
321
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getglobalautofilterfn)
|
|
322
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
323
|
-
*/
|
|
324
|
-
getGlobalAutoFilterFn: () => FilterFn<TData> | undefined
|
|
325
|
-
/**
|
|
326
|
-
* Returns the faceted min and max values for the global filter.
|
|
327
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getglobalfacetedminmaxvalues)
|
|
328
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
329
|
-
*/
|
|
330
|
-
getGlobalFacetedMinMaxValues: () => undefined | [number, number]
|
|
331
|
-
/**
|
|
332
|
-
* Returns the row model for the table after **global** filtering has been applied.
|
|
333
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getglobalfacetedrowmodel)
|
|
334
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
335
|
-
*/
|
|
336
|
-
getGlobalFacetedRowModel: () => RowModel<TData>
|
|
337
|
-
/**
|
|
338
|
-
* Returns the faceted unique values for the global filter.
|
|
339
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getglobalfaceteduniquevalues)
|
|
340
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
341
|
-
*/
|
|
342
|
-
getGlobalFacetedUniqueValues: () => Map<any, number>
|
|
343
|
-
/**
|
|
344
|
-
* Returns the filter function (either user-defined or automatic, depending on configuration) for the global filter.
|
|
345
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getglobalfilterfn)
|
|
346
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
347
|
-
*/
|
|
348
|
-
getGlobalFilterFn: () => FilterFn<TData> | undefined
|
|
349
|
-
/**
|
|
350
|
-
* Resets the **globalFilter** state to `initialState.globalFilter`, or `true` can be passed to force a default blank state reset to `undefined`.
|
|
351
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#resetglobalfilter)
|
|
352
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
353
|
-
*/
|
|
354
|
-
resetGlobalFilter: (defaultState?: boolean) => void
|
|
355
|
-
/**
|
|
356
|
-
* Sets or updates the `state.globalFilter` state.
|
|
357
|
-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#setglobalfilter)
|
|
358
|
-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
|
|
359
|
-
*/
|
|
360
|
-
setGlobalFilter: (updater: Updater<any>) => void
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
//
|
|
364
|
-
|
|
365
|
-
export const Filters: TableFeature = {
|
|
366
|
-
getDefaultColumnDef: <TData extends RowData>(): FiltersColumnDef<TData> => {
|
|
367
|
-
return {
|
|
368
|
-
filterFn: 'auto',
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
|
|
372
|
-
getInitialState: (state): FiltersTableState => {
|
|
373
|
-
return {
|
|
374
|
-
columnFilters: [],
|
|
375
|
-
globalFilter: undefined,
|
|
376
|
-
// filtersProgress: 1,
|
|
377
|
-
// facetProgress: {},
|
|
378
|
-
...state,
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
|
|
382
|
-
getDefaultOptions: <TData extends RowData>(
|
|
383
|
-
table: Table<TData>
|
|
384
|
-
): FiltersOptions<TData> => {
|
|
385
|
-
return {
|
|
386
|
-
onColumnFiltersChange: makeStateUpdater('columnFilters', table),
|
|
387
|
-
onGlobalFilterChange: makeStateUpdater('globalFilter', table),
|
|
388
|
-
filterFromLeafRows: false,
|
|
389
|
-
maxLeafRowFilterDepth: 100,
|
|
390
|
-
globalFilterFn: 'auto',
|
|
391
|
-
getColumnCanGlobalFilter: column => {
|
|
392
|
-
const value = table
|
|
393
|
-
.getCoreRowModel()
|
|
394
|
-
.flatRows[0]?._getAllCellsByColumnId()
|
|
395
|
-
[column.id]?.getValue()
|
|
396
|
-
|
|
397
|
-
return typeof value === 'string' || typeof value === 'number'
|
|
398
|
-
},
|
|
399
|
-
} as FiltersOptions<TData>
|
|
400
|
-
},
|
|
401
|
-
|
|
402
|
-
createColumn: <TData extends RowData>(
|
|
403
|
-
column: Column<TData, unknown>,
|
|
404
|
-
table: Table<TData>
|
|
405
|
-
): void => {
|
|
406
|
-
column.getAutoFilterFn = () => {
|
|
407
|
-
const firstRow = table.getCoreRowModel().flatRows[0]
|
|
408
|
-
|
|
409
|
-
const value = firstRow?.getValue(column.id)
|
|
410
|
-
|
|
411
|
-
if (typeof value === 'string') {
|
|
412
|
-
return filterFns.includesString
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
if (typeof value === 'number') {
|
|
416
|
-
return filterFns.inNumberRange
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
if (typeof value === 'boolean') {
|
|
420
|
-
return filterFns.equals
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
if (value !== null && typeof value === 'object') {
|
|
424
|
-
return filterFns.equals
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if (Array.isArray(value)) {
|
|
428
|
-
return filterFns.arrIncludes
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
return filterFns.weakEquals
|
|
432
|
-
}
|
|
433
|
-
column.getFilterFn = () => {
|
|
434
|
-
return isFunction(column.columnDef.filterFn)
|
|
435
|
-
? column.columnDef.filterFn
|
|
436
|
-
: column.columnDef.filterFn === 'auto'
|
|
437
|
-
? column.getAutoFilterFn()
|
|
438
|
-
: // @ts-ignore
|
|
439
|
-
table.options.filterFns?.[column.columnDef.filterFn as string] ??
|
|
440
|
-
filterFns[column.columnDef.filterFn as BuiltInFilterFn]
|
|
441
|
-
}
|
|
442
|
-
column.getCanFilter = () => {
|
|
443
|
-
return (
|
|
444
|
-
(column.columnDef.enableColumnFilter ?? true) &&
|
|
445
|
-
(table.options.enableColumnFilters ?? true) &&
|
|
446
|
-
(table.options.enableFilters ?? true) &&
|
|
447
|
-
!!column.accessorFn
|
|
448
|
-
)
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
column.getCanGlobalFilter = () => {
|
|
452
|
-
return (
|
|
453
|
-
(column.columnDef.enableGlobalFilter ?? true) &&
|
|
454
|
-
(table.options.enableGlobalFilter ?? true) &&
|
|
455
|
-
(table.options.enableFilters ?? true) &&
|
|
456
|
-
(table.options.getColumnCanGlobalFilter?.(column) ?? true) &&
|
|
457
|
-
!!column.accessorFn
|
|
458
|
-
)
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
column.getIsFiltered = () => column.getFilterIndex() > -1
|
|
462
|
-
|
|
463
|
-
column.getFilterValue = () =>
|
|
464
|
-
table.getState().columnFilters?.find(d => d.id === column.id)?.value
|
|
465
|
-
|
|
466
|
-
column.getFilterIndex = () =>
|
|
467
|
-
table.getState().columnFilters?.findIndex(d => d.id === column.id) ?? -1
|
|
468
|
-
|
|
469
|
-
column.setFilterValue = value => {
|
|
470
|
-
table.setColumnFilters(old => {
|
|
471
|
-
const filterFn = column.getFilterFn()
|
|
472
|
-
const previousfilter = old?.find(d => d.id === column.id)
|
|
473
|
-
|
|
474
|
-
const newFilter = functionalUpdate(
|
|
475
|
-
value,
|
|
476
|
-
previousfilter ? previousfilter.value : undefined
|
|
477
|
-
)
|
|
478
|
-
|
|
479
|
-
//
|
|
480
|
-
if (
|
|
481
|
-
shouldAutoRemoveFilter(filterFn as FilterFn<TData>, newFilter, column)
|
|
482
|
-
) {
|
|
483
|
-
return old?.filter(d => d.id !== column.id) ?? []
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
const newFilterObj = { id: column.id, value: newFilter }
|
|
487
|
-
|
|
488
|
-
if (previousfilter) {
|
|
489
|
-
return (
|
|
490
|
-
old?.map(d => {
|
|
491
|
-
if (d.id === column.id) {
|
|
492
|
-
return newFilterObj
|
|
493
|
-
}
|
|
494
|
-
return d
|
|
495
|
-
}) ?? []
|
|
496
|
-
)
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
if (old?.length) {
|
|
500
|
-
return [...old, newFilterObj]
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return [newFilterObj]
|
|
504
|
-
})
|
|
505
|
-
}
|
|
506
|
-
column._getFacetedRowModel =
|
|
507
|
-
table.options.getFacetedRowModel &&
|
|
508
|
-
table.options.getFacetedRowModel(table, column.id)
|
|
509
|
-
column.getFacetedRowModel = () => {
|
|
510
|
-
if (!column._getFacetedRowModel) {
|
|
511
|
-
return table.getPreFilteredRowModel()
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
return column._getFacetedRowModel()
|
|
515
|
-
}
|
|
516
|
-
column._getFacetedUniqueValues =
|
|
517
|
-
table.options.getFacetedUniqueValues &&
|
|
518
|
-
table.options.getFacetedUniqueValues(table, column.id)
|
|
519
|
-
column.getFacetedUniqueValues = () => {
|
|
520
|
-
if (!column._getFacetedUniqueValues) {
|
|
521
|
-
return new Map()
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
return column._getFacetedUniqueValues()
|
|
525
|
-
}
|
|
526
|
-
column._getFacetedMinMaxValues =
|
|
527
|
-
table.options.getFacetedMinMaxValues &&
|
|
528
|
-
table.options.getFacetedMinMaxValues(table, column.id)
|
|
529
|
-
column.getFacetedMinMaxValues = () => {
|
|
530
|
-
if (!column._getFacetedMinMaxValues) {
|
|
531
|
-
return undefined
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
return column._getFacetedMinMaxValues()
|
|
535
|
-
}
|
|
536
|
-
// () => [column.getFacetedRowModel()],
|
|
537
|
-
// facetedRowModel => getRowModelMinMaxValues(facetedRowModel, column.id),
|
|
538
|
-
},
|
|
539
|
-
|
|
540
|
-
createRow: <TData extends RowData>(
|
|
541
|
-
row: Row<TData>,
|
|
542
|
-
table: Table<TData>
|
|
543
|
-
): void => {
|
|
544
|
-
row.columnFilters = {}
|
|
545
|
-
row.columnFiltersMeta = {}
|
|
546
|
-
},
|
|
547
|
-
|
|
548
|
-
createTable: <TData extends RowData>(table: Table<TData>): void => {
|
|
549
|
-
table.getGlobalAutoFilterFn = () => {
|
|
550
|
-
return filterFns.includesString
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
table.getGlobalFilterFn = () => {
|
|
554
|
-
const { globalFilterFn: globalFilterFn } = table.options
|
|
555
|
-
|
|
556
|
-
return isFunction(globalFilterFn)
|
|
557
|
-
? globalFilterFn
|
|
558
|
-
: globalFilterFn === 'auto'
|
|
559
|
-
? table.getGlobalAutoFilterFn()
|
|
560
|
-
: // @ts-ignore
|
|
561
|
-
table.options.filterFns?.[globalFilterFn as string] ??
|
|
562
|
-
filterFns[globalFilterFn as BuiltInFilterFn]
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
table.setColumnFilters = (updater: Updater<ColumnFiltersState>) => {
|
|
566
|
-
const leafColumns = table.getAllLeafColumns()
|
|
567
|
-
|
|
568
|
-
const updateFn = (old: ColumnFiltersState) => {
|
|
569
|
-
return functionalUpdate(updater, old)?.filter(filter => {
|
|
570
|
-
const column = leafColumns.find(d => d.id === filter.id)
|
|
571
|
-
|
|
572
|
-
if (column) {
|
|
573
|
-
const filterFn = column.getFilterFn()
|
|
574
|
-
|
|
575
|
-
if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
|
|
576
|
-
return false
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
return true
|
|
581
|
-
})
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
table.options.onColumnFiltersChange?.(updateFn)
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
table.setGlobalFilter = updater => {
|
|
588
|
-
table.options.onGlobalFilterChange?.(updater)
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
table.resetGlobalFilter = defaultState => {
|
|
592
|
-
table.setGlobalFilter(
|
|
593
|
-
defaultState ? undefined : table.initialState.globalFilter
|
|
594
|
-
)
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
table.resetColumnFilters = defaultState => {
|
|
598
|
-
table.setColumnFilters(
|
|
599
|
-
defaultState ? [] : table.initialState?.columnFilters ?? []
|
|
600
|
-
)
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
table.getPreFilteredRowModel = () => table.getCoreRowModel()
|
|
604
|
-
table.getFilteredRowModel = () => {
|
|
605
|
-
if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
|
|
606
|
-
table._getFilteredRowModel = table.options.getFilteredRowModel(table)
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
if (table.options.manualFiltering || !table._getFilteredRowModel) {
|
|
610
|
-
return table.getPreFilteredRowModel()
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
return table._getFilteredRowModel()
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
table._getGlobalFacetedRowModel =
|
|
617
|
-
table.options.getFacetedRowModel &&
|
|
618
|
-
table.options.getFacetedRowModel(table, '__global__')
|
|
619
|
-
|
|
620
|
-
table.getGlobalFacetedRowModel = () => {
|
|
621
|
-
if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
|
|
622
|
-
return table.getPreFilteredRowModel()
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
return table._getGlobalFacetedRowModel()
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
table._getGlobalFacetedUniqueValues =
|
|
629
|
-
table.options.getFacetedUniqueValues &&
|
|
630
|
-
table.options.getFacetedUniqueValues(table, '__global__')
|
|
631
|
-
table.getGlobalFacetedUniqueValues = () => {
|
|
632
|
-
if (!table._getGlobalFacetedUniqueValues) {
|
|
633
|
-
return new Map()
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
return table._getGlobalFacetedUniqueValues()
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
table._getGlobalFacetedMinMaxValues =
|
|
640
|
-
table.options.getFacetedMinMaxValues &&
|
|
641
|
-
table.options.getFacetedMinMaxValues(table, '__global__')
|
|
642
|
-
table.getGlobalFacetedMinMaxValues = () => {
|
|
643
|
-
if (!table._getGlobalFacetedMinMaxValues) {
|
|
644
|
-
return
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
return table._getGlobalFacetedMinMaxValues()
|
|
648
|
-
}
|
|
649
|
-
},
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
export function shouldAutoRemoveFilter<TData extends RowData>(
|
|
653
|
-
filterFn?: FilterFn<TData>,
|
|
654
|
-
value?: any,
|
|
655
|
-
column?: Column<TData, unknown>
|
|
656
|
-
) {
|
|
657
|
-
return (
|
|
658
|
-
(filterFn && filterFn.autoRemove
|
|
659
|
-
? filterFn.autoRemove(value, column)
|
|
660
|
-
: false) ||
|
|
661
|
-
typeof value === 'undefined' ||
|
|
662
|
-
(typeof value === 'string' && !value)
|
|
663
|
-
)
|
|
664
|
-
}
|