@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,429 @@
1
+ import { RowModel } from '..'
2
+ import { BuiltInFilterFn, filterFns } from '../filterFns'
3
+ import {
4
+ Column,
5
+ FilterFns,
6
+ FilterMeta,
7
+ OnChangeFn,
8
+ Row,
9
+ RowData,
10
+ Table,
11
+ TableFeature,
12
+ Updater,
13
+ } from '../types'
14
+ import { functionalUpdate, isFunction, makeStateUpdater } from '../utils'
15
+
16
+ export interface ColumnFiltersTableState {
17
+ columnFilters: ColumnFiltersState
18
+ }
19
+
20
+ export type ColumnFiltersState = ColumnFilter[]
21
+
22
+ export interface ColumnFilter {
23
+ id: string
24
+ value: unknown
25
+ }
26
+
27
+ export interface ResolvedColumnFilter<TData extends RowData> {
28
+ filterFn: FilterFn<TData>
29
+ id: string
30
+ resolvedValue: unknown
31
+ }
32
+
33
+ export interface FilterFn<TData extends RowData> {
34
+ (
35
+ row: Row<TData>,
36
+ columnId: string,
37
+ filterValue: any,
38
+ addMeta: (meta: FilterMeta) => void
39
+ ): boolean
40
+ autoRemove?: ColumnFilterAutoRemoveTestFn<TData>
41
+ resolveFilterValue?: TransformFilterValueFn<TData>
42
+ }
43
+
44
+ export type TransformFilterValueFn<TData extends RowData> = (
45
+ value: any,
46
+ column?: Column<TData, unknown>
47
+ ) => unknown
48
+
49
+ export type ColumnFilterAutoRemoveTestFn<TData extends RowData> = (
50
+ value: any,
51
+ column?: Column<TData, unknown>
52
+ ) => boolean
53
+
54
+ export type CustomFilterFns<TData extends RowData> = Record<
55
+ string,
56
+ FilterFn<TData>
57
+ >
58
+
59
+ export type FilterFnOption<TData extends RowData> =
60
+ | 'auto'
61
+ | BuiltInFilterFn
62
+ | keyof FilterFns
63
+ | FilterFn<TData>
64
+
65
+ export interface ColumnFiltersColumnDef<TData extends RowData> {
66
+ /**
67
+ * Enables/disables the **column** filter for this column.
68
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#enablecolumnfilter)
69
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
70
+ */
71
+ enableColumnFilter?: boolean
72
+ /**
73
+ * The filter function to use with this column. Can be the name of a built-in filter function or a custom filter function.
74
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#filterfn)
75
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
76
+ */
77
+ filterFn?: FilterFnOption<TData>
78
+ }
79
+
80
+ export interface ColumnFiltersColumn<TData extends RowData> {
81
+ /**
82
+ * Returns an automatically calculated filter function for the column based off of the columns first known value.
83
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getautofilterfn)
84
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
85
+ */
86
+ getAutoFilterFn: () => FilterFn<TData> | undefined
87
+ /**
88
+ * Returns whether or not the column can be **column** filtered.
89
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getcanfilter)
90
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
91
+ */
92
+ getCanFilter: () => boolean
93
+ /**
94
+ * Returns the filter function (either user-defined or automatic, depending on configuration) for the columnId specified.
95
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilterfn)
96
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
97
+ */
98
+ getFilterFn: () => FilterFn<TData> | undefined
99
+ /**
100
+ * Returns the index (including `-1`) of the column filter in the table's `state.columnFilters` array.
101
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilterindex)
102
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
103
+ */
104
+ getFilterIndex: () => number
105
+ /**
106
+ * Returns the current filter value for the column.
107
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfiltervalue)
108
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
109
+ */
110
+ getFilterValue: () => unknown
111
+ /**
112
+ * Returns whether or not the column is currently filtered.
113
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getisfiltered)
114
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
115
+ */
116
+ getIsFiltered: () => boolean
117
+ /**
118
+ * 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.
119
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setfiltervalue)
120
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
121
+ */
122
+ setFilterValue: (updater: Updater<any>) => void
123
+ }
124
+
125
+ export interface ColumnFiltersRow<TData extends RowData> {
126
+ /**
127
+ * The column filters map for the row. This object tracks whether a row is passing/failing specific filters by their column ID.
128
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#columnfilters)
129
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
130
+ */
131
+ columnFilters: Record<string, boolean>
132
+ /**
133
+ * The column filters meta map for the row. This object tracks any filter meta for a row as optionally provided during the filtering process.
134
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#columnfiltersmeta)
135
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
136
+ */
137
+ columnFiltersMeta: Record<string, FilterMeta>
138
+ }
139
+
140
+ interface ColumnFiltersOptionsBase<TData extends RowData> {
141
+ /**
142
+ * Enables/disables **column** filtering for all columns.
143
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#enablecolumnfilters)
144
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
145
+ */
146
+ enableColumnFilters?: boolean
147
+ /**
148
+ * Enables/disables all filtering for the table.
149
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#enablefilters)
150
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
151
+ */
152
+ enableFilters?: boolean
153
+ /**
154
+ * 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).
155
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#filterfromleafrows)
156
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
157
+ */
158
+ filterFromLeafRows?: boolean
159
+ /**
160
+ * 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.
161
+ * - For server-side filtering, this function is unnecessary and can be ignored since the server should already return the filtered row model.
162
+ * - For client-side filtering, this function is required. A default implementation is provided via any table adapter's `{ getFilteredRowModel }` export.
163
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilteredrowmodel)
164
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
165
+ */
166
+ getFilteredRowModel?: (table: Table<any>) => () => RowModel<any>
167
+ /**
168
+ * 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.
169
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#manualfiltering)
170
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
171
+ */
172
+ manualFiltering?: boolean
173
+ /**
174
+ * 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.
175
+
176
+ * This is useful for situations where you want a row's entire child hierarchy to be visible regardless of the applied filter.
177
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#maxleafrowfilterdepth)
178
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
179
+ */
180
+ maxLeafRowFilterDepth?: number
181
+ /**
182
+ * 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.
183
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#oncolumnfilterschange)
184
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
185
+ */
186
+ onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>
187
+ }
188
+
189
+ type ResolvedFilterFns = keyof FilterFns extends never
190
+ ? {
191
+ filterFns?: Record<string, FilterFn<any>>
192
+ }
193
+ : {
194
+ filterFns: Record<keyof FilterFns, FilterFn<any>>
195
+ }
196
+
197
+ export interface ColumnFiltersOptions<TData extends RowData>
198
+ extends ColumnFiltersOptionsBase<TData>,
199
+ ResolvedFilterFns {}
200
+
201
+ export interface ColumnFiltersInstance<TData extends RowData> {
202
+ _getFilteredRowModel?: () => RowModel<TData>
203
+ /**
204
+ * Returns the row model for the table after **column** filtering has been applied.
205
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilteredrowmodel)
206
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
207
+ */
208
+ getFilteredRowModel: () => RowModel<TData>
209
+ /**
210
+ * Returns the row model for the table before any **column** filtering has been applied.
211
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getprefilteredrowmodel)
212
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
213
+ */
214
+ getPreFilteredRowModel: () => RowModel<TData>
215
+ /**
216
+ * Resets the **columnFilters** state to `initialState.columnFilters`, or `true` can be passed to force a default blank state reset to `[]`.
217
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#resetcolumnfilters)
218
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
219
+ */
220
+ resetColumnFilters: (defaultState?: boolean) => void
221
+ /**
222
+ * Resets the **globalFilter** state to `initialState.globalFilter`, or `true` can be passed to force a default blank state reset to `undefined`.
223
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#resetglobalfilter)
224
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
225
+ */
226
+ resetGlobalFilter: (defaultState?: boolean) => void
227
+ /**
228
+ * Sets or updates the `state.columnFilters` state.
229
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setcolumnfilters)
230
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
231
+ */
232
+ setColumnFilters: (updater: Updater<ColumnFiltersState>) => void
233
+ /**
234
+ * Sets or updates the `state.globalFilter` state.
235
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setglobalfilter)
236
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
237
+ */
238
+ setGlobalFilter: (updater: Updater<any>) => void
239
+ }
240
+
241
+ //
242
+
243
+ export const ColumnFiltering: TableFeature = {
244
+ getDefaultColumnDef: <
245
+ TData extends RowData,
246
+ >(): ColumnFiltersColumnDef<TData> => {
247
+ return {
248
+ filterFn: 'auto',
249
+ }
250
+ },
251
+
252
+ getInitialState: (state): ColumnFiltersTableState => {
253
+ return {
254
+ columnFilters: [],
255
+ ...state,
256
+ }
257
+ },
258
+
259
+ getDefaultOptions: <TData extends RowData>(
260
+ table: Table<TData>
261
+ ): ColumnFiltersOptions<TData> => {
262
+ return {
263
+ onColumnFiltersChange: makeStateUpdater('columnFilters', table),
264
+ filterFromLeafRows: false,
265
+ maxLeafRowFilterDepth: 100,
266
+ } as ColumnFiltersOptions<TData>
267
+ },
268
+
269
+ createColumn: <TData extends RowData>(
270
+ column: Column<TData, unknown>,
271
+ table: Table<TData>
272
+ ): void => {
273
+ column.getAutoFilterFn = () => {
274
+ const firstRow = table.getCoreRowModel().flatRows[0]
275
+
276
+ const value = firstRow?.getValue(column.id)
277
+
278
+ if (typeof value === 'string') {
279
+ return filterFns.includesString
280
+ }
281
+
282
+ if (typeof value === 'number') {
283
+ return filterFns.inNumberRange
284
+ }
285
+
286
+ if (typeof value === 'boolean') {
287
+ return filterFns.equals
288
+ }
289
+
290
+ if (value !== null && typeof value === 'object') {
291
+ return filterFns.equals
292
+ }
293
+
294
+ if (Array.isArray(value)) {
295
+ return filterFns.arrIncludes
296
+ }
297
+
298
+ return filterFns.weakEquals
299
+ }
300
+ column.getFilterFn = () => {
301
+ return isFunction(column.columnDef.filterFn)
302
+ ? column.columnDef.filterFn
303
+ : column.columnDef.filterFn === 'auto'
304
+ ? column.getAutoFilterFn()
305
+ : // @ts-ignore
306
+ table.options.filterFns?.[column.columnDef.filterFn as string] ??
307
+ filterFns[column.columnDef.filterFn as BuiltInFilterFn]
308
+ }
309
+ column.getCanFilter = () => {
310
+ return (
311
+ (column.columnDef.enableColumnFilter ?? true) &&
312
+ (table.options.enableColumnFilters ?? true) &&
313
+ (table.options.enableFilters ?? true) &&
314
+ !!column.accessorFn
315
+ )
316
+ }
317
+
318
+ column.getIsFiltered = () => column.getFilterIndex() > -1
319
+
320
+ column.getFilterValue = () =>
321
+ table.getState().columnFilters?.find(d => d.id === column.id)?.value
322
+
323
+ column.getFilterIndex = () =>
324
+ table.getState().columnFilters?.findIndex(d => d.id === column.id) ?? -1
325
+
326
+ column.setFilterValue = value => {
327
+ table.setColumnFilters(old => {
328
+ const filterFn = column.getFilterFn()
329
+ const previousFilter = old?.find(d => d.id === column.id)
330
+
331
+ const newFilter = functionalUpdate(
332
+ value,
333
+ previousFilter ? previousFilter.value : undefined
334
+ )
335
+
336
+ //
337
+ if (
338
+ shouldAutoRemoveFilter(filterFn as FilterFn<TData>, newFilter, column)
339
+ ) {
340
+ return old?.filter(d => d.id !== column.id) ?? []
341
+ }
342
+
343
+ const newFilterObj = { id: column.id, value: newFilter }
344
+
345
+ if (previousFilter) {
346
+ return (
347
+ old?.map(d => {
348
+ if (d.id === column.id) {
349
+ return newFilterObj
350
+ }
351
+ return d
352
+ }) ?? []
353
+ )
354
+ }
355
+
356
+ if (old?.length) {
357
+ return [...old, newFilterObj]
358
+ }
359
+
360
+ return [newFilterObj]
361
+ })
362
+ }
363
+ },
364
+
365
+ createRow: <TData extends RowData>(
366
+ row: Row<TData>,
367
+ _table: Table<TData>
368
+ ): void => {
369
+ row.columnFilters = {}
370
+ row.columnFiltersMeta = {}
371
+ },
372
+
373
+ createTable: <TData extends RowData>(table: Table<TData>): void => {
374
+ table.setColumnFilters = (updater: Updater<ColumnFiltersState>) => {
375
+ const leafColumns = table.getAllLeafColumns()
376
+
377
+ const updateFn = (old: ColumnFiltersState) => {
378
+ return functionalUpdate(updater, old)?.filter(filter => {
379
+ const column = leafColumns.find(d => d.id === filter.id)
380
+
381
+ if (column) {
382
+ const filterFn = column.getFilterFn()
383
+
384
+ if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
385
+ return false
386
+ }
387
+ }
388
+
389
+ return true
390
+ })
391
+ }
392
+
393
+ table.options.onColumnFiltersChange?.(updateFn)
394
+ }
395
+
396
+ table.resetColumnFilters = defaultState => {
397
+ table.setColumnFilters(
398
+ defaultState ? [] : table.initialState?.columnFilters ?? []
399
+ )
400
+ }
401
+
402
+ table.getPreFilteredRowModel = () => table.getCoreRowModel()
403
+ table.getFilteredRowModel = () => {
404
+ if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
405
+ table._getFilteredRowModel = table.options.getFilteredRowModel(table)
406
+ }
407
+
408
+ if (table.options.manualFiltering || !table._getFilteredRowModel) {
409
+ return table.getPreFilteredRowModel()
410
+ }
411
+
412
+ return table._getFilteredRowModel()
413
+ }
414
+ },
415
+ }
416
+
417
+ export function shouldAutoRemoveFilter<TData extends RowData>(
418
+ filterFn?: FilterFn<TData>,
419
+ value?: any,
420
+ column?: Column<TData, unknown>
421
+ ) {
422
+ return (
423
+ (filterFn && filterFn.autoRemove
424
+ ? filterFn.autoRemove(value, column)
425
+ : false) ||
426
+ typeof value === 'undefined' ||
427
+ (typeof value === 'string' && !value)
428
+ )
429
+ }
@@ -1,16 +1,16 @@
1
1
  import { RowModel } from '..'
2
2
  import { BuiltInAggregationFn, aggregationFns } from '../aggregationFns'
3
- import { TableFeature } from '../core/table'
4
3
  import {
4
+ AggregationFns,
5
5
  Cell,
6
6
  Column,
7
+ ColumnDefTemplate,
7
8
  OnChangeFn,
8
- Table,
9
9
  Row,
10
- Updater,
11
- ColumnDefTemplate,
12
10
  RowData,
13
- AggregationFns,
11
+ Table,
12
+ TableFeature,
13
+ Updater,
14
14
  } from '../types'
15
15
  import { isFunction, makeStateUpdater } from '../utils'
16
16
 
@@ -239,7 +239,7 @@ export interface GroupingInstance<TData extends RowData> {
239
239
 
240
240
  //
241
241
 
242
- export const Grouping: TableFeature = {
242
+ export const ColumnGrouping: TableFeature = {
243
243
  getDefaultColumnDef: <TData extends RowData>(): GroupingColumnDef<
244
244
  TData,
245
245
  unknown
@@ -1,9 +1,15 @@
1
1
  import { getMemoOptions, makeStateUpdater, memo } from '../utils'
2
2
 
3
- import { Table, OnChangeFn, Updater, Column, RowData } from '../types'
4
-
5
- import { orderColumns } from './Grouping'
6
- import { TableFeature } from '../core/table'
3
+ import {
4
+ Column,
5
+ OnChangeFn,
6
+ RowData,
7
+ Table,
8
+ TableFeature,
9
+ Updater,
10
+ } from '../types'
11
+
12
+ import { orderColumns } from './ColumnGrouping'
7
13
  import { ColumnPinningPosition, _getVisibleLeafColumns } from '..'
8
14
 
9
15
  export interface ColumnOrderTableState {
@@ -66,7 +72,7 @@ export interface ColumnOrderInstance<TData extends RowData> {
66
72
 
67
73
  //
68
74
 
69
- export const Ordering: TableFeature = {
75
+ export const ColumnOrdering: TableFeature = {
70
76
  getInitialState: (state): ColumnOrderTableState => {
71
77
  return {
72
78
  columnOrder: [],