@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.
Files changed (57) hide show
  1. package/build/lib/core/cell.js +1 -1
  2. package/build/lib/core/cell.js.map +1 -1
  3. package/build/lib/core/column.js +3 -3
  4. package/build/lib/core/column.js.map +1 -1
  5. package/build/lib/core/headers.js +182 -181
  6. package/build/lib/core/headers.js.map +1 -1
  7. package/build/lib/core/row.js +1 -1
  8. package/build/lib/core/row.js.map +1 -1
  9. package/build/lib/core/table.js +4 -3
  10. package/build/lib/core/table.js.map +1 -1
  11. package/build/lib/features/ColumnSizing.js +173 -179
  12. package/build/lib/features/ColumnSizing.js.map +1 -1
  13. package/build/lib/features/Expanding.js +119 -123
  14. package/build/lib/features/Expanding.js.map +1 -1
  15. package/build/lib/features/Filters.js +157 -165
  16. package/build/lib/features/Filters.js.map +1 -1
  17. package/build/lib/features/Grouping.js +71 -79
  18. package/build/lib/features/Grouping.js.map +1 -1
  19. package/build/lib/features/Ordering.js +32 -34
  20. package/build/lib/features/Ordering.js.map +1 -1
  21. package/build/lib/features/Pagination.js +112 -114
  22. package/build/lib/features/Pagination.js.map +1 -1
  23. package/build/lib/features/Pinning.js +120 -126
  24. package/build/lib/features/Pinning.js.map +1 -1
  25. package/build/lib/features/RowSelection.js +245 -247
  26. package/build/lib/features/RowSelection.js.map +1 -1
  27. package/build/lib/features/Sorting.js +163 -167
  28. package/build/lib/features/Sorting.js.map +1 -1
  29. package/build/lib/features/Visibility.js +60 -66
  30. package/build/lib/features/Visibility.js.map +1 -1
  31. package/build/lib/index.esm.js +1469 -1515
  32. package/build/lib/index.esm.js.map +1 -1
  33. package/build/lib/index.mjs +1469 -1515
  34. package/build/lib/index.mjs.map +1 -1
  35. package/build/lib/utils.d.ts +2 -2
  36. package/build/lib/utils.js.map +1 -1
  37. package/build/umd/index.development.js +1469 -1515
  38. package/build/umd/index.development.js.map +1 -1
  39. package/build/umd/index.production.js +1 -1
  40. package/build/umd/index.production.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/core/cell.ts +5 -8
  43. package/src/core/column.ts +3 -3
  44. package/src/core/headers.ts +264 -280
  45. package/src/core/row.ts +1 -1
  46. package/src/core/table.ts +4 -3
  47. package/src/features/ColumnSizing.ts +220 -231
  48. package/src/features/Expanding.ts +132 -140
  49. package/src/features/Filters.ts +193 -206
  50. package/src/features/Grouping.ts +94 -110
  51. package/src/features/Ordering.ts +48 -51
  52. package/src/features/Pagination.ts +150 -154
  53. package/src/features/Pinning.ts +158 -178
  54. package/src/features/RowSelection.ts +280 -286
  55. package/src/features/Sorting.ts +196 -206
  56. package/src/features/Visibility.ts +98 -107
  57. package/src/utils.ts +11 -5
@@ -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
- ): FiltersColumn<TData> => {
205
- return {
206
- getAutoFilterFn: () => {
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
- if (typeof value === 'string') {
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
- if (typeof value === 'boolean') {
220
- return filterFns.equals
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
- if (Array.isArray(value)) {
228
- return filterFns.arrIncludes
229
- }
214
+ if (typeof value === 'number') {
215
+ return filterFns.inNumberRange
216
+ }
230
217
 
231
- return filterFns.weakEquals
232
- },
233
- getFilterFn: () => {
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
- getCanGlobalFilter: () => {
252
- return (
253
- (column.columnDef.enableGlobalFilter ?? true) &&
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
- getIsFiltered: () => column.getFilterIndex() > -1,
226
+ if (Array.isArray(value)) {
227
+ return filterFns.arrIncludes
228
+ }
262
229
 
263
- getFilterValue: () =>
264
- table.getState().columnFilters?.find(d => d.id === column.id)?.value,
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
- getFilterIndex: () =>
267
- table.getState().columnFilters?.findIndex(d => d.id === column.id) ??
268
- -1,
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
- setFilterValue: value => {
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
- const newFilter = functionalUpdate(
276
- value,
277
- previousfilter ? previousfilter.value : undefined
278
- )
262
+ column.getFilterValue = () =>
263
+ table.getState().columnFilters?.find(d => d.id === column.id)?.value
279
264
 
280
- //
281
- if (
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
- const newFilterObj = { id: column.id, value: newFilter }
292
-
293
- if (previousfilter) {
294
- return (
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
- if (old?.length) {
305
- return [...old, newFilterObj]
306
- }
273
+ const newFilter = functionalUpdate(
274
+ value,
275
+ previousfilter ? previousfilter.value : undefined
276
+ )
307
277
 
308
- return [newFilterObj]
309
- })
310
- },
311
- _getFacetedRowModel:
312
- table.options.getFacetedRowModel &&
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
- return column._getFacetedRowModel()
320
- },
321
- _getFacetedUniqueValues:
322
- table.options.getFacetedUniqueValues &&
323
- table.options.getFacetedUniqueValues(table, column.id),
324
- getFacetedUniqueValues: () => {
325
- if (!column._getFacetedUniqueValues) {
326
- return new Map()
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
- return column._getFacetedUniqueValues()
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 column._getFacetedMinMaxValues()
340
- },
341
- // () => [column.getFacetedRowModel()],
342
- // facetedRowModel => getRowModelMinMaxValues(facetedRowModel, column.id),
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
- ): FiltersRow<TData> => {
350
- return {
351
- columnFilters: {},
352
- columnFiltersMeta: {},
353
- }
342
+ ): void => {
343
+ row.columnFilters = {}
344
+ row.columnFiltersMeta = {}
354
345
  },
355
346
 
356
- createTable: <TData extends RowData>(
357
- table: Table<TData>
358
- ): FiltersInstance<TData> => {
359
- return {
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
- getGlobalFilterFn: () => {
365
- const { globalFilterFn: globalFilterFn } = table.options
352
+ table.getGlobalFilterFn = () => {
353
+ const { globalFilterFn: globalFilterFn } = table.options
366
354
 
367
- return isFunction(globalFilterFn)
368
- ? globalFilterFn
369
- : globalFilterFn === 'auto'
370
- ? table.getGlobalAutoFilterFn()
371
- // @ts-ignore
372
- : table.options.filterFns?.[globalFilterFn as string] ??
373
- filterFns[globalFilterFn as BuiltInFilterFn]
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
- setColumnFilters: (updater: Updater<ColumnFiltersState>) => {
377
- const leafColumns = table.getAllLeafColumns()
364
+ table.setColumnFilters = (updater: Updater<ColumnFiltersState>) => {
365
+ const leafColumns = table.getAllLeafColumns()
378
366
 
379
- const updateFn = (old: ColumnFiltersState) => {
380
- return functionalUpdate(updater, old)?.filter(filter => {
381
- const column = leafColumns.find(d => d.id === filter.id)
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
- if (column) {
384
- const filterFn = column.getFilterFn()
371
+ if (column) {
372
+ const filterFn = column.getFilterFn()
385
373
 
386
- if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
387
- return false
388
- }
374
+ if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
375
+ return false
389
376
  }
377
+ }
390
378
 
391
- return true
392
- })
393
- }
379
+ return true
380
+ })
381
+ }
394
382
 
395
- table.options.onColumnFiltersChange?.(updateFn)
396
- },
383
+ table.options.onColumnFiltersChange?.(updateFn)
384
+ }
397
385
 
398
- setGlobalFilter: updater => {
399
- table.options.onGlobalFilterChange?.(updater)
400
- },
386
+ table.setGlobalFilter = updater => {
387
+ table.options.onGlobalFilterChange?.(updater)
388
+ }
401
389
 
402
- resetGlobalFilter: defaultState => {
403
- table.setGlobalFilter(
404
- defaultState ? undefined : table.initialState.globalFilter
405
- )
406
- },
390
+ table.resetGlobalFilter = defaultState => {
391
+ table.setGlobalFilter(
392
+ defaultState ? undefined : table.initialState.globalFilter
393
+ )
394
+ }
407
395
 
408
- resetColumnFilters: defaultState => {
409
- table.setColumnFilters(
410
- defaultState ? [] : table.initialState?.columnFilters ?? []
411
- )
412
- },
396
+ table.resetColumnFilters = defaultState => {
397
+ table.setColumnFilters(
398
+ defaultState ? [] : table.initialState?.columnFilters ?? []
399
+ )
400
+ }
413
401
 
414
- getPreFilteredRowModel: () => table.getCoreRowModel(),
415
- getFilteredRowModel: () => {
416
- if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
417
- table._getFilteredRowModel = table.options.getFilteredRowModel(table)
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
- if (table.options.manualFiltering || !table._getFilteredRowModel) {
421
- return table.getPreFilteredRowModel()
422
- }
408
+ if (table.options.manualFiltering || !table._getFilteredRowModel) {
409
+ return table.getPreFilteredRowModel()
410
+ }
423
411
 
424
- return table._getFilteredRowModel()
425
- },
412
+ return table._getFilteredRowModel()
413
+ }
426
414
 
427
- _getGlobalFacetedRowModel:
428
- table.options.getFacetedRowModel &&
429
- table.options.getFacetedRowModel(table, '__global__'),
415
+ table._getGlobalFacetedRowModel =
416
+ table.options.getFacetedRowModel &&
417
+ table.options.getFacetedRowModel(table, '__global__')
430
418
 
431
- getGlobalFacetedRowModel: () => {
432
- if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
433
- return table.getPreFilteredRowModel()
434
- }
419
+ table.getGlobalFacetedRowModel = () => {
420
+ if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
421
+ return table.getPreFilteredRowModel()
422
+ }
435
423
 
436
- return table._getGlobalFacetedRowModel()
437
- },
424
+ return table._getGlobalFacetedRowModel()
425
+ }
438
426
 
439
- _getGlobalFacetedUniqueValues:
440
- table.options.getFacetedUniqueValues &&
441
- table.options.getFacetedUniqueValues(table, '__global__'),
442
- getGlobalFacetedUniqueValues: () => {
443
- if (!table._getGlobalFacetedUniqueValues) {
444
- return new Map()
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
- return table._getGlobalFacetedUniqueValues()
448
- },
435
+ return table._getGlobalFacetedUniqueValues()
436
+ }
449
437
 
450
- _getGlobalFacetedMinMaxValues:
451
- table.options.getFacetedMinMaxValues &&
452
- table.options.getFacetedMinMaxValues(table, '__global__'),
453
- getGlobalFacetedMinMaxValues: () => {
454
- if (!table._getGlobalFacetedMinMaxValues) {
455
- return
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
- return table._getGlobalFacetedMinMaxValues()
459
- },
446
+ return table._getGlobalFacetedMinMaxValues()
460
447
  }
461
448
  },
462
449
  }