@tanstack/table-core 8.9.7 → 8.9.9
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/core/cell.js +1 -1
- package/build/lib/core/cell.js.map +1 -1
- package/build/lib/core/column.js +3 -3
- package/build/lib/core/column.js.map +1 -1
- package/build/lib/core/headers.js +182 -181
- package/build/lib/core/headers.js.map +1 -1
- package/build/lib/core/row.js +1 -1
- package/build/lib/core/row.js.map +1 -1
- package/build/lib/core/table.js +4 -3
- package/build/lib/core/table.js.map +1 -1
- package/build/lib/features/ColumnSizing.js +173 -179
- package/build/lib/features/ColumnSizing.js.map +1 -1
- package/build/lib/features/Expanding.js +119 -123
- package/build/lib/features/Expanding.js.map +1 -1
- package/build/lib/features/Filters.js +157 -165
- package/build/lib/features/Filters.js.map +1 -1
- package/build/lib/features/Grouping.js +71 -79
- package/build/lib/features/Grouping.js.map +1 -1
- package/build/lib/features/Ordering.js +32 -34
- package/build/lib/features/Ordering.js.map +1 -1
- package/build/lib/features/Pagination.js +112 -114
- package/build/lib/features/Pagination.js.map +1 -1
- package/build/lib/features/Pinning.js +120 -126
- package/build/lib/features/Pinning.js.map +1 -1
- package/build/lib/features/RowSelection.js +245 -247
- package/build/lib/features/RowSelection.js.map +1 -1
- package/build/lib/features/Sorting.js +163 -167
- package/build/lib/features/Sorting.js.map +1 -1
- package/build/lib/features/Visibility.js +60 -66
- package/build/lib/features/Visibility.js.map +1 -1
- package/build/lib/index.esm.js +1469 -1515
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.mjs +1469 -1515
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/utils.d.ts +2 -2
- package/build/lib/utils.js.map +1 -1
- package/build/umd/index.development.js +1469 -1515
- 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/core/cell.ts +5 -8
- package/src/core/column.ts +3 -3
- package/src/core/headers.ts +264 -280
- package/src/core/row.ts +1 -1
- package/src/core/table.ts +4 -3
- package/src/features/ColumnSizing.ts +220 -231
- package/src/features/Expanding.ts +132 -140
- package/src/features/Filters.ts +193 -206
- package/src/features/Grouping.ts +94 -110
- package/src/features/Ordering.ts +48 -51
- package/src/features/Pagination.ts +150 -154
- package/src/features/Pinning.ts +158 -178
- package/src/features/RowSelection.ts +280 -286
- package/src/features/Sorting.ts +196 -206
- package/src/features/Visibility.ts +98 -107
- package/src/utils.ts +11 -5
package/src/features/Filters.ts
CHANGED
|
@@ -201,262 +201,249 @@ export const Filters: TableFeature = {
|
|
|
201
201
|
createColumn: <TData extends RowData>(
|
|
202
202
|
column: Column<TData, unknown>,
|
|
203
203
|
table: Table<TData>
|
|
204
|
-
):
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const firstRow = table.getCoreRowModel().flatRows[0]
|
|
208
|
-
|
|
209
|
-
const value = firstRow?.getValue(column.id)
|
|
204
|
+
): void => {
|
|
205
|
+
column.getAutoFilterFn = () => {
|
|
206
|
+
const firstRow = table.getCoreRowModel().flatRows[0]
|
|
210
207
|
|
|
211
|
-
|
|
212
|
-
return filterFns.includesString
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (typeof value === 'number') {
|
|
216
|
-
return filterFns.inNumberRange
|
|
217
|
-
}
|
|
208
|
+
const value = firstRow?.getValue(column.id)
|
|
218
209
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (value !== null && typeof value === 'object') {
|
|
224
|
-
return filterFns.equals
|
|
225
|
-
}
|
|
210
|
+
if (typeof value === 'string') {
|
|
211
|
+
return filterFns.includesString
|
|
212
|
+
}
|
|
226
213
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
214
|
+
if (typeof value === 'number') {
|
|
215
|
+
return filterFns.inNumberRange
|
|
216
|
+
}
|
|
230
217
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return isFunction(column.columnDef.filterFn)
|
|
235
|
-
? column.columnDef.filterFn
|
|
236
|
-
: column.columnDef.filterFn === 'auto'
|
|
237
|
-
? column.getAutoFilterFn()
|
|
238
|
-
// @ts-ignore
|
|
239
|
-
: table.options.filterFns?.[column.columnDef.filterFn as string] ??
|
|
240
|
-
filterFns[column.columnDef.filterFn as BuiltInFilterFn]
|
|
241
|
-
},
|
|
242
|
-
getCanFilter: () => {
|
|
243
|
-
return (
|
|
244
|
-
(column.columnDef.enableColumnFilter ?? true) &&
|
|
245
|
-
(table.options.enableColumnFilters ?? true) &&
|
|
246
|
-
(table.options.enableFilters ?? true) &&
|
|
247
|
-
!!column.accessorFn
|
|
248
|
-
)
|
|
249
|
-
},
|
|
218
|
+
if (typeof value === 'boolean') {
|
|
219
|
+
return filterFns.equals
|
|
220
|
+
}
|
|
250
221
|
|
|
251
|
-
|
|
252
|
-
return
|
|
253
|
-
|
|
254
|
-
(table.options.enableGlobalFilter ?? true) &&
|
|
255
|
-
(table.options.enableFilters ?? true) &&
|
|
256
|
-
(table.options.getColumnCanGlobalFilter?.(column) ?? true) &&
|
|
257
|
-
!!column.accessorFn
|
|
258
|
-
)
|
|
259
|
-
},
|
|
222
|
+
if (value !== null && typeof value === 'object') {
|
|
223
|
+
return filterFns.equals
|
|
224
|
+
}
|
|
260
225
|
|
|
261
|
-
|
|
226
|
+
if (Array.isArray(value)) {
|
|
227
|
+
return filterFns.arrIncludes
|
|
228
|
+
}
|
|
262
229
|
|
|
263
|
-
|
|
264
|
-
|
|
230
|
+
return filterFns.weakEquals
|
|
231
|
+
}
|
|
232
|
+
column.getFilterFn = () => {
|
|
233
|
+
return isFunction(column.columnDef.filterFn)
|
|
234
|
+
? column.columnDef.filterFn
|
|
235
|
+
: column.columnDef.filterFn === 'auto'
|
|
236
|
+
? column.getAutoFilterFn()
|
|
237
|
+
: // @ts-ignore
|
|
238
|
+
table.options.filterFns?.[column.columnDef.filterFn as string] ??
|
|
239
|
+
filterFns[column.columnDef.filterFn as BuiltInFilterFn]
|
|
240
|
+
}
|
|
241
|
+
column.getCanFilter = () => {
|
|
242
|
+
return (
|
|
243
|
+
(column.columnDef.enableColumnFilter ?? true) &&
|
|
244
|
+
(table.options.enableColumnFilters ?? true) &&
|
|
245
|
+
(table.options.enableFilters ?? true) &&
|
|
246
|
+
!!column.accessorFn
|
|
247
|
+
)
|
|
248
|
+
}
|
|
265
249
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
250
|
+
column.getCanGlobalFilter = () => {
|
|
251
|
+
return (
|
|
252
|
+
(column.columnDef.enableGlobalFilter ?? true) &&
|
|
253
|
+
(table.options.enableGlobalFilter ?? true) &&
|
|
254
|
+
(table.options.enableFilters ?? true) &&
|
|
255
|
+
(table.options.getColumnCanGlobalFilter?.(column) ?? true) &&
|
|
256
|
+
!!column.accessorFn
|
|
257
|
+
)
|
|
258
|
+
}
|
|
269
259
|
|
|
270
|
-
|
|
271
|
-
table.setColumnFilters(old => {
|
|
272
|
-
const filterFn = column.getFilterFn()
|
|
273
|
-
const previousfilter = old?.find(d => d.id === column.id)
|
|
260
|
+
column.getIsFiltered = () => column.getFilterIndex() > -1
|
|
274
261
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
previousfilter ? previousfilter.value : undefined
|
|
278
|
-
)
|
|
262
|
+
column.getFilterValue = () =>
|
|
263
|
+
table.getState().columnFilters?.find(d => d.id === column.id)?.value
|
|
279
264
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
shouldAutoRemoveFilter(
|
|
283
|
-
filterFn as FilterFn<TData>,
|
|
284
|
-
newFilter,
|
|
285
|
-
column
|
|
286
|
-
)
|
|
287
|
-
) {
|
|
288
|
-
return old?.filter(d => d.id !== column.id) ?? []
|
|
289
|
-
}
|
|
265
|
+
column.getFilterIndex = () =>
|
|
266
|
+
table.getState().columnFilters?.findIndex(d => d.id === column.id) ?? -1
|
|
290
267
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
old?.map(d => {
|
|
296
|
-
if (d.id === column.id) {
|
|
297
|
-
return newFilterObj
|
|
298
|
-
}
|
|
299
|
-
return d
|
|
300
|
-
}) ?? []
|
|
301
|
-
)
|
|
302
|
-
}
|
|
268
|
+
column.setFilterValue = value => {
|
|
269
|
+
table.setColumnFilters(old => {
|
|
270
|
+
const filterFn = column.getFilterFn()
|
|
271
|
+
const previousfilter = old?.find(d => d.id === column.id)
|
|
303
272
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
273
|
+
const newFilter = functionalUpdate(
|
|
274
|
+
value,
|
|
275
|
+
previousfilter ? previousfilter.value : undefined
|
|
276
|
+
)
|
|
307
277
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
table.options.getFacetedRowModel(table, column.id),
|
|
314
|
-
getFacetedRowModel: () => {
|
|
315
|
-
if (!column._getFacetedRowModel) {
|
|
316
|
-
return table.getPreFilteredRowModel()
|
|
278
|
+
//
|
|
279
|
+
if (
|
|
280
|
+
shouldAutoRemoveFilter(filterFn as FilterFn<TData>, newFilter, column)
|
|
281
|
+
) {
|
|
282
|
+
return old?.filter(d => d.id !== column.id) ?? []
|
|
317
283
|
}
|
|
318
284
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
285
|
+
const newFilterObj = { id: column.id, value: newFilter }
|
|
286
|
+
|
|
287
|
+
if (previousfilter) {
|
|
288
|
+
return (
|
|
289
|
+
old?.map(d => {
|
|
290
|
+
if (d.id === column.id) {
|
|
291
|
+
return newFilterObj
|
|
292
|
+
}
|
|
293
|
+
return d
|
|
294
|
+
}) ?? []
|
|
295
|
+
)
|
|
327
296
|
}
|
|
328
297
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
_getFacetedMinMaxValues:
|
|
332
|
-
table.options.getFacetedMinMaxValues &&
|
|
333
|
-
table.options.getFacetedMinMaxValues(table, column.id),
|
|
334
|
-
getFacetedMinMaxValues: () => {
|
|
335
|
-
if (!column._getFacetedMinMaxValues) {
|
|
336
|
-
return undefined
|
|
298
|
+
if (old?.length) {
|
|
299
|
+
return [...old, newFilterObj]
|
|
337
300
|
}
|
|
338
301
|
|
|
339
|
-
return
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
302
|
+
return [newFilterObj]
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
column._getFacetedRowModel =
|
|
306
|
+
table.options.getFacetedRowModel &&
|
|
307
|
+
table.options.getFacetedRowModel(table, column.id)
|
|
308
|
+
column.getFacetedRowModel = () => {
|
|
309
|
+
if (!column._getFacetedRowModel) {
|
|
310
|
+
return table.getPreFilteredRowModel()
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return column._getFacetedRowModel()
|
|
314
|
+
}
|
|
315
|
+
column._getFacetedUniqueValues =
|
|
316
|
+
table.options.getFacetedUniqueValues &&
|
|
317
|
+
table.options.getFacetedUniqueValues(table, column.id)
|
|
318
|
+
column.getFacetedUniqueValues = () => {
|
|
319
|
+
if (!column._getFacetedUniqueValues) {
|
|
320
|
+
return new Map()
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return column._getFacetedUniqueValues()
|
|
324
|
+
}
|
|
325
|
+
column._getFacetedMinMaxValues =
|
|
326
|
+
table.options.getFacetedMinMaxValues &&
|
|
327
|
+
table.options.getFacetedMinMaxValues(table, column.id)
|
|
328
|
+
column.getFacetedMinMaxValues = () => {
|
|
329
|
+
if (!column._getFacetedMinMaxValues) {
|
|
330
|
+
return undefined
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return column._getFacetedMinMaxValues()
|
|
343
334
|
}
|
|
335
|
+
// () => [column.getFacetedRowModel()],
|
|
336
|
+
// facetedRowModel => getRowModelMinMaxValues(facetedRowModel, column.id),
|
|
344
337
|
},
|
|
345
338
|
|
|
346
339
|
createRow: <TData extends RowData>(
|
|
347
340
|
row: Row<TData>,
|
|
348
341
|
table: Table<TData>
|
|
349
|
-
):
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
columnFiltersMeta: {},
|
|
353
|
-
}
|
|
342
|
+
): void => {
|
|
343
|
+
row.columnFilters = {}
|
|
344
|
+
row.columnFiltersMeta = {}
|
|
354
345
|
},
|
|
355
346
|
|
|
356
|
-
createTable: <TData extends RowData>(
|
|
357
|
-
table
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
getGlobalAutoFilterFn: () => {
|
|
361
|
-
return filterFns.includesString
|
|
362
|
-
},
|
|
347
|
+
createTable: <TData extends RowData>(table: Table<TData>): void => {
|
|
348
|
+
table.getGlobalAutoFilterFn = () => {
|
|
349
|
+
return filterFns.includesString
|
|
350
|
+
}
|
|
363
351
|
|
|
364
|
-
|
|
365
|
-
|
|
352
|
+
table.getGlobalFilterFn = () => {
|
|
353
|
+
const { globalFilterFn: globalFilterFn } = table.options
|
|
366
354
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
355
|
+
return isFunction(globalFilterFn)
|
|
356
|
+
? globalFilterFn
|
|
357
|
+
: globalFilterFn === 'auto'
|
|
358
|
+
? table.getGlobalAutoFilterFn()
|
|
359
|
+
: // @ts-ignore
|
|
360
|
+
table.options.filterFns?.[globalFilterFn as string] ??
|
|
361
|
+
filterFns[globalFilterFn as BuiltInFilterFn]
|
|
362
|
+
}
|
|
375
363
|
|
|
376
|
-
|
|
377
|
-
|
|
364
|
+
table.setColumnFilters = (updater: Updater<ColumnFiltersState>) => {
|
|
365
|
+
const leafColumns = table.getAllLeafColumns()
|
|
378
366
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
367
|
+
const updateFn = (old: ColumnFiltersState) => {
|
|
368
|
+
return functionalUpdate(updater, old)?.filter(filter => {
|
|
369
|
+
const column = leafColumns.find(d => d.id === filter.id)
|
|
382
370
|
|
|
383
|
-
|
|
384
|
-
|
|
371
|
+
if (column) {
|
|
372
|
+
const filterFn = column.getFilterFn()
|
|
385
373
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
374
|
+
if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
|
|
375
|
+
return false
|
|
389
376
|
}
|
|
377
|
+
}
|
|
390
378
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
379
|
+
return true
|
|
380
|
+
})
|
|
381
|
+
}
|
|
394
382
|
|
|
395
|
-
|
|
396
|
-
|
|
383
|
+
table.options.onColumnFiltersChange?.(updateFn)
|
|
384
|
+
}
|
|
397
385
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
386
|
+
table.setGlobalFilter = updater => {
|
|
387
|
+
table.options.onGlobalFilterChange?.(updater)
|
|
388
|
+
}
|
|
401
389
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
390
|
+
table.resetGlobalFilter = defaultState => {
|
|
391
|
+
table.setGlobalFilter(
|
|
392
|
+
defaultState ? undefined : table.initialState.globalFilter
|
|
393
|
+
)
|
|
394
|
+
}
|
|
407
395
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
396
|
+
table.resetColumnFilters = defaultState => {
|
|
397
|
+
table.setColumnFilters(
|
|
398
|
+
defaultState ? [] : table.initialState?.columnFilters ?? []
|
|
399
|
+
)
|
|
400
|
+
}
|
|
413
401
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
402
|
+
table.getPreFilteredRowModel = () => table.getCoreRowModel()
|
|
403
|
+
table.getFilteredRowModel = () => {
|
|
404
|
+
if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
|
|
405
|
+
table._getFilteredRowModel = table.options.getFilteredRowModel(table)
|
|
406
|
+
}
|
|
419
407
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
408
|
+
if (table.options.manualFiltering || !table._getFilteredRowModel) {
|
|
409
|
+
return table.getPreFilteredRowModel()
|
|
410
|
+
}
|
|
423
411
|
|
|
424
|
-
|
|
425
|
-
|
|
412
|
+
return table._getFilteredRowModel()
|
|
413
|
+
}
|
|
426
414
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
415
|
+
table._getGlobalFacetedRowModel =
|
|
416
|
+
table.options.getFacetedRowModel &&
|
|
417
|
+
table.options.getFacetedRowModel(table, '__global__')
|
|
430
418
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
419
|
+
table.getGlobalFacetedRowModel = () => {
|
|
420
|
+
if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
|
|
421
|
+
return table.getPreFilteredRowModel()
|
|
422
|
+
}
|
|
435
423
|
|
|
436
|
-
|
|
437
|
-
|
|
424
|
+
return table._getGlobalFacetedRowModel()
|
|
425
|
+
}
|
|
438
426
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
427
|
+
table._getGlobalFacetedUniqueValues =
|
|
428
|
+
table.options.getFacetedUniqueValues &&
|
|
429
|
+
table.options.getFacetedUniqueValues(table, '__global__')
|
|
430
|
+
table.getGlobalFacetedUniqueValues = () => {
|
|
431
|
+
if (!table._getGlobalFacetedUniqueValues) {
|
|
432
|
+
return new Map()
|
|
433
|
+
}
|
|
446
434
|
|
|
447
|
-
|
|
448
|
-
|
|
435
|
+
return table._getGlobalFacetedUniqueValues()
|
|
436
|
+
}
|
|
449
437
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
438
|
+
table._getGlobalFacetedMinMaxValues =
|
|
439
|
+
table.options.getFacetedMinMaxValues &&
|
|
440
|
+
table.options.getFacetedMinMaxValues(table, '__global__')
|
|
441
|
+
table.getGlobalFacetedMinMaxValues = () => {
|
|
442
|
+
if (!table._getGlobalFacetedMinMaxValues) {
|
|
443
|
+
return
|
|
444
|
+
}
|
|
457
445
|
|
|
458
|
-
|
|
459
|
-
},
|
|
446
|
+
return table._getGlobalFacetedMinMaxValues()
|
|
460
447
|
}
|
|
461
448
|
},
|
|
462
449
|
}
|