@tanstack/react-table 0.0.1-alpha.9 → 8.0.0-alpha.3
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/cjs/_virtual/_rollupPluginBabelHelpers.js +112 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/build/cjs/aggregationTypes.js +130 -0
- package/build/cjs/aggregationTypes.js.map +1 -0
- package/build/cjs/core.js +552 -0
- package/build/cjs/core.js.map +1 -0
- package/build/cjs/createTable.js +108 -0
- package/build/cjs/createTable.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +317 -0
- package/build/cjs/features/ColumnSizing.js.map +1 -0
- package/build/cjs/features/Expanding.js +255 -0
- package/build/cjs/features/Expanding.js.map +1 -0
- package/build/cjs/features/Filters.js +445 -0
- package/build/cjs/features/Filters.js.map +1 -0
- package/build/cjs/features/Grouping.js +249 -0
- package/build/cjs/features/Grouping.js.map +1 -0
- package/build/cjs/features/Headers.js +549 -0
- package/build/cjs/features/Headers.js.map +1 -0
- package/build/cjs/features/Ordering.js +86 -0
- package/build/cjs/features/Ordering.js.map +1 -0
- package/build/cjs/features/Pagination.js +194 -0
- package/build/cjs/features/Pagination.js.map +1 -0
- package/build/cjs/features/Pinning.js +149 -0
- package/build/cjs/features/Pinning.js.map +1 -0
- package/build/cjs/features/RowSelection.js +541 -0
- package/build/cjs/features/RowSelection.js.map +1 -0
- package/build/cjs/features/Sorting.js +327 -0
- package/build/cjs/features/Sorting.js.map +1 -0
- package/build/cjs/features/Visibility.js +166 -0
- package/build/cjs/features/Visibility.js.map +1 -0
- package/build/cjs/filterTypes.js +172 -0
- package/build/cjs/filterTypes.js.map +1 -0
- package/build/cjs/index.js +30 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/sortTypes.js +122 -0
- package/build/cjs/sortTypes.js.map +1 -0
- package/build/cjs/utils/columnFilterRowsFn.js +131 -0
- package/build/cjs/utils/columnFilterRowsFn.js.map +1 -0
- package/build/cjs/utils/expandRowsFn.js +38 -0
- package/build/cjs/utils/expandRowsFn.js.map +1 -0
- package/build/cjs/utils/globalFilterRowsFn.js +101 -0
- package/build/cjs/utils/globalFilterRowsFn.js.map +1 -0
- package/build/cjs/utils/groupRowsFn.js +155 -0
- package/build/cjs/utils/groupRowsFn.js.map +1 -0
- package/build/cjs/utils/sortRowsFn.js +94 -0
- package/build/cjs/utils/sortRowsFn.js.map +1 -0
- package/build/cjs/utils.js +146 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +4747 -0
- package/build/esm/index.js.map +1 -0
- package/build/stats-html.html +2689 -0
- package/build/stats-react.json +817 -0
- package/build/types/aggregationTypes.d.ts +22 -0
- package/build/types/core.d.ts +111 -0
- package/build/types/createTable.d.ts +53 -0
- package/build/types/features/ColumnSizing.d.ts +67 -0
- package/build/types/features/Expanding.d.ts +53 -0
- package/build/types/features/Filters.d.ts +98 -0
- package/build/types/features/Grouping.d.ts +82 -0
- package/build/types/features/Headers.d.ts +41 -0
- package/build/types/features/Ordering.d.ts +19 -0
- package/build/types/features/Pagination.d.ts +43 -0
- package/build/types/features/Pinning.d.ts +39 -0
- package/build/types/features/RowSelection.d.ts +66 -0
- package/build/types/features/Sorting.d.ts +78 -0
- package/build/types/features/Visibility.d.ts +47 -0
- package/build/types/filterTypes.d.ts +50 -0
- package/build/types/index.d.ts +7 -0
- package/build/types/sortTypes.d.ts +18 -0
- package/build/types/types.d.ts +127 -0
- package/build/types/utils/columnFilterRowsFn.d.ts +2 -0
- package/build/types/utils/expandRowsFn.d.ts +2 -0
- package/build/types/utils/globalFilterRowsFn.d.ts +2 -0
- package/build/types/utils/groupRowsFn.d.ts +2 -0
- package/build/types/utils/paginateRowsFn.d.ts +2 -0
- package/build/types/utils/sortRowsFn.d.ts +2 -0
- package/build/types/utils.d.ts +28 -0
- package/{dist/react-table.development.js → build/umd/index.development.js} +1617 -249
- package/build/umd/index.development.js.map +1 -0
- package/build/umd/index.production.js +12 -0
- package/build/umd/index.production.js.map +1 -0
- package/package.json +9 -94
- package/src/core.tsx +252 -264
- package/src/createTable.tsx +69 -9
- package/src/features/ColumnSizing.ts +453 -0
- package/src/features/Expanding.ts +27 -11
- package/src/features/Filters.ts +75 -20
- package/src/features/Grouping.ts +27 -12
- package/src/features/Headers.ts +55 -50
- package/src/features/Ordering.ts +2 -3
- package/src/features/Pagination.ts +314 -0
- package/src/features/Pinning.ts +3 -16
- package/src/features/RowSelection.ts +831 -0
- package/src/features/Sorting.ts +82 -22
- package/src/features/Visibility.ts +2 -4
- package/src/sortTypes.ts +1 -1
- package/src/types.ts +55 -9
- package/src/utils/columnFilterRowsFn.ts +5 -12
- package/src/utils/expandRowsFn.ts +2 -5
- package/src/utils/globalFilterRowsFn.ts +3 -10
- package/src/utils/groupRowsFn.ts +3 -5
- package/src/utils/paginateRowsFn.ts +34 -0
- package/src/utils/sortRowsFn.ts +5 -5
- package/src/utils.tsx +20 -6
- package/dist/react-table.development.js.map +0 -1
- package/dist/react-table.production.min.js +0 -2
- package/dist/react-table.production.min.js.map +0 -1
- package/lib/index.js +0 -65
- package/src/features/notest/useAbsoluteLayout.test.js +0 -152
- package/src/features/notest/useBlockLayout.test.js +0 -158
- package/src/features/notest/useColumnOrder.test.js +0 -186
- package/src/features/notest/useExpanded.test.js +0 -125
- package/src/features/notest/useFilters.test.js +0 -393
- package/src/features/notest/useFiltersAndRowSelect.test.js +0 -256
- package/src/features/notest/useFlexLayout.test.js +0 -152
- package/src/features/notest/useGroupBy.test.js +0 -259
- package/src/features/notest/usePagination.test.js +0 -231
- package/src/features/notest/useResizeColumns.test.js +0 -229
- package/src/features/notest/useRowSelect.test.js +0 -250
- package/src/features/notest/useRowState.test.js +0 -178
- package/src/features/tests/Visibility.test.tsx +0 -225
- package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +0 -390
- package/src/features/tests/withSorting.notest.tsx +0 -341
- package/src/features/withColumnResizing.ts +0 -281
- package/src/features/withPagination.ts +0 -208
- package/src/features/withRowSelection.ts +0 -467
- package/src/test-utils/makeTestData.ts +0 -41
- package/src/tests/__snapshots__/core.test.tsx.snap +0 -148
- package/src/tests/core.test.tsx +0 -241
package/src/core.tsx
CHANGED
|
@@ -38,11 +38,24 @@ import * as Filters from './features/Filters'
|
|
|
38
38
|
import * as Sorting from './features/Sorting'
|
|
39
39
|
import * as Grouping from './features/Grouping'
|
|
40
40
|
import * as Expanding from './features/Expanding'
|
|
41
|
+
import * as ColumnSizing from './features/ColumnSizing'
|
|
42
|
+
import * as Pagination from './features/Pagination'
|
|
43
|
+
import * as RowSelection from './features/RowSelection'
|
|
41
44
|
import { RowModel } from '.'
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
const features = [
|
|
47
|
+
Visibility,
|
|
48
|
+
Ordering,
|
|
49
|
+
Pinning,
|
|
50
|
+
Headers,
|
|
51
|
+
Filters,
|
|
52
|
+
Sorting,
|
|
53
|
+
Grouping,
|
|
54
|
+
Expanding,
|
|
55
|
+
ColumnSizing,
|
|
56
|
+
Pagination,
|
|
57
|
+
RowSelection,
|
|
58
|
+
]
|
|
46
59
|
|
|
47
60
|
export type CoreOptions<
|
|
48
61
|
TData,
|
|
@@ -66,6 +79,7 @@ export type CoreOptions<
|
|
|
66
79
|
parent?: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
67
80
|
) => string
|
|
68
81
|
onStateChange?: (newState: TableState) => void
|
|
82
|
+
autoResetAll?: boolean
|
|
69
83
|
}
|
|
70
84
|
|
|
71
85
|
export type TableCore<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
@@ -225,6 +239,10 @@ export type TableCore<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
|
225
239
|
columnId: string,
|
|
226
240
|
userProps?: TGetter
|
|
227
241
|
) => undefined | PropGetterValue<CellProps, TGetter>
|
|
242
|
+
getTableWidth: () => number
|
|
243
|
+
getLeftTableWidth: () => number
|
|
244
|
+
getCenterTableWidth: () => number
|
|
245
|
+
getRightTableWidth: () => number
|
|
228
246
|
}
|
|
229
247
|
|
|
230
248
|
export type CoreRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> = {
|
|
@@ -256,93 +274,139 @@ export type CoreColumnDef<
|
|
|
256
274
|
TFilterFns,
|
|
257
275
|
TSortingFns,
|
|
258
276
|
TAggregationFns
|
|
259
|
-
> =
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
277
|
+
> = {
|
|
278
|
+
id: string
|
|
279
|
+
accessorKey?: string & keyof TData
|
|
280
|
+
accessorFn?: AccessorFn<TData>
|
|
281
|
+
header?:
|
|
282
|
+
| string
|
|
283
|
+
| Renderable<{
|
|
284
|
+
instance: ReactTable<
|
|
285
|
+
TData,
|
|
286
|
+
TValue,
|
|
287
|
+
TFilterFns,
|
|
288
|
+
TSortingFns,
|
|
289
|
+
TAggregationFns
|
|
290
|
+
>
|
|
291
|
+
header: Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
292
|
+
column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
293
|
+
}>
|
|
294
|
+
} & // | Renderable<{ // | string // header?: // accessorKey?: never // id: string // accessorFn: AccessorFn<TData> // | {
|
|
295
|
+
// instance: ReactTable<
|
|
296
|
+
// TData,
|
|
297
|
+
// TValue,
|
|
298
|
+
// TFilterFns,
|
|
299
|
+
// TSortingFns,
|
|
300
|
+
// TAggregationFns
|
|
301
|
+
// >
|
|
302
|
+
// header: Header<
|
|
303
|
+
// TData,
|
|
304
|
+
// TValue,
|
|
305
|
+
// TFilterFns,
|
|
306
|
+
// TSortingFns,
|
|
307
|
+
// TAggregationFns
|
|
308
|
+
// >
|
|
309
|
+
// column: Column<
|
|
310
|
+
// TData,
|
|
311
|
+
// TValue,
|
|
312
|
+
// TFilterFns,
|
|
313
|
+
// TSortingFns,
|
|
314
|
+
// TAggregationFns
|
|
315
|
+
// >
|
|
316
|
+
// }>
|
|
317
|
+
// }
|
|
318
|
+
// | {
|
|
319
|
+
// accessorKey: string & keyof TData
|
|
320
|
+
// id?: string
|
|
321
|
+
// accessorFn?: never
|
|
322
|
+
// header?:
|
|
323
|
+
// | string
|
|
324
|
+
// | Renderable<{
|
|
325
|
+
// instance: ReactTable<
|
|
326
|
+
// TData,
|
|
327
|
+
// TValue,
|
|
328
|
+
// TFilterFns,
|
|
329
|
+
// TSortingFns,
|
|
330
|
+
// TAggregationFns
|
|
331
|
+
// >
|
|
332
|
+
// header: Header<
|
|
333
|
+
// TData,
|
|
334
|
+
// TValue,
|
|
335
|
+
// TFilterFns,
|
|
336
|
+
// TSortingFns,
|
|
337
|
+
// TAggregationFns
|
|
338
|
+
// >
|
|
339
|
+
// column: Column<
|
|
340
|
+
// TData,
|
|
341
|
+
// TValue,
|
|
342
|
+
// TFilterFns,
|
|
343
|
+
// TSortingFns,
|
|
344
|
+
// TAggregationFns
|
|
345
|
+
// >
|
|
346
|
+
// }>
|
|
347
|
+
// }
|
|
348
|
+
// | {
|
|
349
|
+
// id: string
|
|
350
|
+
// accessorKey?: never
|
|
351
|
+
// accessorFn?: never
|
|
352
|
+
// header?:
|
|
353
|
+
// | string
|
|
354
|
+
// | Renderable<{
|
|
355
|
+
// instance: ReactTable<
|
|
356
|
+
// TData,
|
|
357
|
+
// TValue,
|
|
358
|
+
// TFilterFns,
|
|
359
|
+
// TSortingFns,
|
|
360
|
+
// TAggregationFns
|
|
361
|
+
// >
|
|
362
|
+
// header: Header<
|
|
363
|
+
// TData,
|
|
364
|
+
// TValue,
|
|
365
|
+
// TFilterFns,
|
|
366
|
+
// TSortingFns,
|
|
367
|
+
// TAggregationFns
|
|
368
|
+
// >
|
|
369
|
+
// column: Column<
|
|
370
|
+
// TData,
|
|
371
|
+
// TValue,
|
|
372
|
+
// TFilterFns,
|
|
373
|
+
// TSortingFns,
|
|
374
|
+
// TAggregationFns
|
|
375
|
+
// >
|
|
376
|
+
// }>
|
|
377
|
+
// }
|
|
378
|
+
// | {
|
|
379
|
+
// header: string
|
|
380
|
+
// id?: string
|
|
381
|
+
// accessorKey?: never
|
|
382
|
+
// accessorFn?: never
|
|
383
|
+
// }
|
|
384
|
+
{
|
|
336
385
|
__generated: true
|
|
337
386
|
width?: number
|
|
338
387
|
minWidth?: number
|
|
339
388
|
maxWidth?: number
|
|
340
389
|
columns?: ColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[]
|
|
341
390
|
footer?: Renderable<{
|
|
391
|
+
instance: ReactTable<
|
|
392
|
+
TData,
|
|
393
|
+
TValue,
|
|
394
|
+
TFilterFns,
|
|
395
|
+
TSortingFns,
|
|
396
|
+
TAggregationFns
|
|
397
|
+
>
|
|
342
398
|
header: Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
343
399
|
column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
344
400
|
}>
|
|
345
401
|
cell?: Renderable<{
|
|
402
|
+
instance: ReactTable<
|
|
403
|
+
TData,
|
|
404
|
+
TValue,
|
|
405
|
+
TFilterFns,
|
|
406
|
+
TSortingFns,
|
|
407
|
+
TAggregationFns
|
|
408
|
+
>
|
|
409
|
+
row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
346
410
|
column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
347
411
|
cell: Cell<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
348
412
|
value: TValue
|
|
@@ -402,15 +466,9 @@ export function createTableInstance<
|
|
|
402
466
|
TAggregationFns
|
|
403
467
|
>
|
|
404
468
|
|
|
405
|
-
const defaultOptions = {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
...Pinning.getDefaultOptions(instance),
|
|
409
|
-
...Filters.getDefaultOptions(instance),
|
|
410
|
-
...Sorting.getDefaultOptions(instance),
|
|
411
|
-
...Grouping.getDefaultOptions(instance),
|
|
412
|
-
...Expanding.getDefaultOptions(instance),
|
|
413
|
-
}
|
|
469
|
+
const defaultOptions = features.reduce((obj, feature) => {
|
|
470
|
+
return Object.assign(obj, (feature as any).getDefaultOptions?.(instance))
|
|
471
|
+
}, {})
|
|
414
472
|
|
|
415
473
|
const defaultState = {}
|
|
416
474
|
|
|
@@ -425,15 +483,11 @@ export function createTableInstance<
|
|
|
425
483
|
instance.options = buildOptions(options)
|
|
426
484
|
|
|
427
485
|
const initialState = {
|
|
428
|
-
...
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
...Filters.getInitialState(),
|
|
432
|
-
...Sorting.getInitialState(),
|
|
433
|
-
...Grouping.getInitialState(),
|
|
434
|
-
...Expanding.getInitialState(),
|
|
486
|
+
...features.reduce((obj, feature) => {
|
|
487
|
+
return Object.assign(obj, (feature as any).getInitialState?.())
|
|
488
|
+
}, {}),
|
|
435
489
|
...(options.initialState ?? {}),
|
|
436
|
-
}
|
|
490
|
+
} as TableState
|
|
437
491
|
|
|
438
492
|
const finalInstance: ReactTable<
|
|
439
493
|
TData,
|
|
@@ -443,14 +497,9 @@ export function createTableInstance<
|
|
|
443
497
|
TAggregationFns
|
|
444
498
|
> = {
|
|
445
499
|
...instance,
|
|
446
|
-
...
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
...Headers.getInstance(instance),
|
|
450
|
-
...Filters.getInstance(instance),
|
|
451
|
-
...Sorting.getInstance(instance),
|
|
452
|
-
...Grouping.getInstance(instance),
|
|
453
|
-
...Expanding.getInstance(instance),
|
|
500
|
+
...features.reduce((obj, feature) => {
|
|
501
|
+
return Object.assign(obj, (feature as any).getInstance?.(instance))
|
|
502
|
+
}, {}),
|
|
454
503
|
rerender,
|
|
455
504
|
initialState,
|
|
456
505
|
internalState: initialState,
|
|
@@ -468,19 +517,23 @@ export function createTableInstance<
|
|
|
468
517
|
) => `${parent ? [parent.id, index].join('.') : index}`,
|
|
469
518
|
|
|
470
519
|
getState: () => {
|
|
471
|
-
|
|
520
|
+
let state = {
|
|
472
521
|
...instance.internalState,
|
|
473
522
|
...instance.options.state,
|
|
474
523
|
}
|
|
524
|
+
|
|
525
|
+
return state
|
|
475
526
|
},
|
|
476
527
|
|
|
477
528
|
setState: (
|
|
478
529
|
updater: Updater<TableState>,
|
|
479
530
|
shouldRerender: boolean = true
|
|
480
531
|
) => {
|
|
481
|
-
const newState = functionalUpdate(updater, instance.internalState)
|
|
482
532
|
const onStateChange = instance.options.onStateChange
|
|
483
533
|
|
|
534
|
+
let internalState = instance.internalState
|
|
535
|
+
let newState = functionalUpdate(updater, internalState)
|
|
536
|
+
|
|
484
537
|
instance.internalState = newState
|
|
485
538
|
|
|
486
539
|
if (onStateChange) {
|
|
@@ -513,17 +566,15 @@ export function createTableInstance<
|
|
|
513
566
|
) => props.header.column.id,
|
|
514
567
|
cell: ({ value = '' }: { value: any }): JSX.Element =>
|
|
515
568
|
typeof value === 'boolean' ? value.toString() : value,
|
|
516
|
-
...
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
...Grouping.getDefaultColumn(),
|
|
569
|
+
...features.reduce((obj, feature) => {
|
|
570
|
+
return Object.assign(obj, (feature as any).getDefaultColumn?.())
|
|
571
|
+
}, {}),
|
|
520
572
|
...defaultColumn,
|
|
521
573
|
} as Partial<
|
|
522
574
|
ColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
523
575
|
>
|
|
524
576
|
},
|
|
525
|
-
'getDefaultColumn'
|
|
526
|
-
instance.options.debug
|
|
577
|
+
{ debug: instance.options.debug, key: 'getDefaultColumn' }
|
|
527
578
|
),
|
|
528
579
|
|
|
529
580
|
getColumnDefs: () => instance.options.columns,
|
|
@@ -563,9 +614,7 @@ export function createTableInstance<
|
|
|
563
614
|
TSortingFns,
|
|
564
615
|
TAggregationFns
|
|
565
616
|
> = {
|
|
566
|
-
|
|
567
|
-
minWidth: 20,
|
|
568
|
-
maxWidth: Number.MAX_SAFE_INTEGER,
|
|
617
|
+
...ColumnSizing.defaultColumnSizing,
|
|
569
618
|
...defaultColumn,
|
|
570
619
|
...columnDef,
|
|
571
620
|
id: `${id}`,
|
|
@@ -589,8 +638,10 @@ export function createTableInstance<
|
|
|
589
638
|
...column.columns?.flatMap(d => d.getFlatColumns()),
|
|
590
639
|
]
|
|
591
640
|
},
|
|
592
|
-
|
|
593
|
-
|
|
641
|
+
{
|
|
642
|
+
key: 'column.getFlatColumns',
|
|
643
|
+
debug: instance.options.debug,
|
|
644
|
+
}
|
|
594
645
|
),
|
|
595
646
|
getLeafColumns: memo(
|
|
596
647
|
() => [instance.getOrderColumnsFn()],
|
|
@@ -613,64 +664,19 @@ export function createTableInstance<
|
|
|
613
664
|
>,
|
|
614
665
|
]
|
|
615
666
|
},
|
|
616
|
-
|
|
617
|
-
|
|
667
|
+
{
|
|
668
|
+
key: 'column.getLeafColumns',
|
|
669
|
+
debug: instance.options.debug,
|
|
670
|
+
}
|
|
618
671
|
),
|
|
619
672
|
}
|
|
620
673
|
|
|
621
|
-
column =
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
TData,
|
|
626
|
-
TValue,
|
|
627
|
-
TFilterFns,
|
|
628
|
-
TSortingFns,
|
|
629
|
-
TAggregationFns
|
|
630
|
-
>,
|
|
631
|
-
instance
|
|
632
|
-
),
|
|
633
|
-
Pinning.createColumn(
|
|
634
|
-
column as Column<
|
|
635
|
-
TData,
|
|
636
|
-
TValue,
|
|
637
|
-
TFilterFns,
|
|
638
|
-
TSortingFns,
|
|
639
|
-
TAggregationFns
|
|
640
|
-
>,
|
|
641
|
-
instance
|
|
642
|
-
),
|
|
643
|
-
Filters.createColumn(
|
|
644
|
-
column as Column<
|
|
645
|
-
TData,
|
|
646
|
-
TValue,
|
|
647
|
-
TFilterFns,
|
|
648
|
-
TSortingFns,
|
|
649
|
-
TAggregationFns
|
|
650
|
-
>,
|
|
651
|
-
instance
|
|
652
|
-
),
|
|
653
|
-
Sorting.createColumn(
|
|
654
|
-
column as Column<
|
|
655
|
-
TData,
|
|
656
|
-
TValue,
|
|
657
|
-
TFilterFns,
|
|
658
|
-
TSortingFns,
|
|
659
|
-
TAggregationFns
|
|
660
|
-
>,
|
|
661
|
-
instance
|
|
662
|
-
),
|
|
663
|
-
Grouping.createColumn(
|
|
664
|
-
column as Column<
|
|
665
|
-
TData,
|
|
666
|
-
TValue,
|
|
667
|
-
TFilterFns,
|
|
668
|
-
TSortingFns,
|
|
669
|
-
TAggregationFns
|
|
670
|
-
>,
|
|
671
|
-
instance
|
|
674
|
+
column = features.reduce((obj, feature) => {
|
|
675
|
+
return Object.assign(
|
|
676
|
+
obj,
|
|
677
|
+
(feature as any).createColumn?.(column, instance)
|
|
672
678
|
)
|
|
673
|
-
)
|
|
679
|
+
}, column)
|
|
674
680
|
|
|
675
681
|
// Yes, we have to convert instance to uknown, because we know more than the compiler here.
|
|
676
682
|
return column as Column<
|
|
@@ -724,8 +730,7 @@ export function createTableInstance<
|
|
|
724
730
|
|
|
725
731
|
return recurseColumns(columnDefs)
|
|
726
732
|
},
|
|
727
|
-
'getAllColumns',
|
|
728
|
-
instance.options.debug
|
|
733
|
+
{ key: 'getAllColumns', debug: instance.options.debug }
|
|
729
734
|
),
|
|
730
735
|
|
|
731
736
|
getAllFlatColumns: memo(
|
|
@@ -735,8 +740,7 @@ export function createTableInstance<
|
|
|
735
740
|
return column.getFlatColumns()
|
|
736
741
|
})
|
|
737
742
|
},
|
|
738
|
-
'getAllFlatColumns',
|
|
739
|
-
instance.options.debug
|
|
743
|
+
{ key: 'getAllFlatColumns', debug: instance.options.debug }
|
|
740
744
|
),
|
|
741
745
|
|
|
742
746
|
getAllFlatColumnsById: memo(
|
|
@@ -747,8 +751,7 @@ export function createTableInstance<
|
|
|
747
751
|
return acc
|
|
748
752
|
}, {} as Record<string, Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>>)
|
|
749
753
|
},
|
|
750
|
-
'getAllFlatColumnsById',
|
|
751
|
-
instance.options.debug
|
|
754
|
+
{ key: 'getAllFlatColumnsById', debug: instance.options.debug }
|
|
752
755
|
),
|
|
753
756
|
|
|
754
757
|
getAllLeafColumns: memo(
|
|
@@ -757,8 +760,7 @@ export function createTableInstance<
|
|
|
757
760
|
let leafColumns = allColumns.flatMap(column => column.getLeafColumns())
|
|
758
761
|
return orderColumns(leafColumns)
|
|
759
762
|
},
|
|
760
|
-
'getAllLeafColumns',
|
|
761
|
-
instance.options.debug
|
|
763
|
+
{ key: 'getAllLeafColumns', debug: instance.options.debug }
|
|
762
764
|
),
|
|
763
765
|
|
|
764
766
|
getColumn: columnId => {
|
|
@@ -783,9 +785,14 @@ export function createTableInstance<
|
|
|
783
785
|
throw new Error()
|
|
784
786
|
}
|
|
785
787
|
|
|
788
|
+
const columnSize = instance.getState().columnSizing[column.id]
|
|
789
|
+
|
|
786
790
|
return Math.min(
|
|
787
|
-
Math.max(
|
|
788
|
-
|
|
791
|
+
Math.max(
|
|
792
|
+
column.minWidth ?? ColumnSizing.defaultColumnSizing.minWidth,
|
|
793
|
+
columnSize ?? column.width ?? ColumnSizing.defaultColumnSizing.width
|
|
794
|
+
),
|
|
795
|
+
column.maxWidth ?? ColumnSizing.defaultColumnSizing.maxWidth
|
|
789
796
|
)
|
|
790
797
|
},
|
|
791
798
|
|
|
@@ -805,24 +812,28 @@ export function createTableInstance<
|
|
|
805
812
|
value,
|
|
806
813
|
getCellProps: userProps =>
|
|
807
814
|
instance.getCellProps(row.id, column.id, userProps)!,
|
|
808
|
-
renderCell: () =>
|
|
815
|
+
renderCell: () =>
|
|
816
|
+
flexRender(column.cell, { instance, column, row, cell, value }),
|
|
809
817
|
}
|
|
810
818
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
cell
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
819
|
+
features.forEach(feature => {
|
|
820
|
+
Object.assign(
|
|
821
|
+
cell,
|
|
822
|
+
(feature as any).createCell?.(
|
|
823
|
+
cell as Cell<
|
|
824
|
+
TData,
|
|
825
|
+
TValue,
|
|
826
|
+
TFilterFns,
|
|
827
|
+
TSortingFns,
|
|
828
|
+
TAggregationFns
|
|
829
|
+
> &
|
|
830
|
+
Grouping.GroupingCell,
|
|
831
|
+
column,
|
|
832
|
+
row as Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
833
|
+
instance
|
|
834
|
+
)
|
|
835
|
+
)
|
|
836
|
+
}, {})
|
|
826
837
|
|
|
827
838
|
return cell
|
|
828
839
|
},
|
|
@@ -864,8 +875,10 @@ export function createTableInstance<
|
|
|
864
875
|
)
|
|
865
876
|
})
|
|
866
877
|
},
|
|
867
|
-
|
|
868
|
-
|
|
878
|
+
{
|
|
879
|
+
key: process.env.NODE_ENV !== 'production' ? 'row.getAllCells' : '',
|
|
880
|
+
debug: instance.options.debug,
|
|
881
|
+
}
|
|
869
882
|
)
|
|
870
883
|
|
|
871
884
|
row.getAllCellsByColumnId = memo(
|
|
@@ -876,25 +889,15 @@ export function createTableInstance<
|
|
|
876
889
|
return acc
|
|
877
890
|
}, {} as Record<string, Cell<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>>)
|
|
878
891
|
},
|
|
879
|
-
|
|
880
|
-
|
|
892
|
+
{
|
|
893
|
+
key: 'row.getAllCellsByColumnId',
|
|
894
|
+
debug: instance.options.debug,
|
|
895
|
+
}
|
|
881
896
|
)
|
|
882
897
|
|
|
883
|
-
|
|
884
|
-
row,
|
|
885
|
-
|
|
886
|
-
row as Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
887
|
-
instance
|
|
888
|
-
),
|
|
889
|
-
Grouping.createRow(
|
|
890
|
-
row as Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
891
|
-
instance
|
|
892
|
-
),
|
|
893
|
-
Expanding.createRow(
|
|
894
|
-
row as Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
895
|
-
instance
|
|
896
|
-
)
|
|
897
|
-
)
|
|
898
|
+
features.forEach(feature => {
|
|
899
|
+
Object.assign(row, (feature as any).createRow?.(row, instance))
|
|
900
|
+
})
|
|
898
901
|
|
|
899
902
|
return row as Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
900
903
|
},
|
|
@@ -914,50 +917,6 @@ export function createTableInstance<
|
|
|
914
917
|
if (process.env.NODE_ENV !== 'production' && instance.options.debug)
|
|
915
918
|
console.info('Accessing...')
|
|
916
919
|
|
|
917
|
-
// Auto-reset data-dependent states if configured
|
|
918
|
-
if (
|
|
919
|
-
instance.options.autoResetColumnFilters &&
|
|
920
|
-
// @ts-ignore
|
|
921
|
-
instance.getRowModelNonFirst
|
|
922
|
-
) {
|
|
923
|
-
instance.resetColumnFilters()
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
if (
|
|
927
|
-
instance.options.autoResetGlobalFilter &&
|
|
928
|
-
// @ts-ignore
|
|
929
|
-
instance.getRowModelNonFirst
|
|
930
|
-
) {
|
|
931
|
-
instance.resetGlobalFilter()
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
if (
|
|
935
|
-
instance.options.autoResetSorting &&
|
|
936
|
-
// @ts-ignore
|
|
937
|
-
instance.getRowModelNonFirst
|
|
938
|
-
) {
|
|
939
|
-
instance.resetSorting()
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
if (
|
|
943
|
-
instance.options.autoResetGrouping &&
|
|
944
|
-
// @ts-ignore
|
|
945
|
-
instance.getRowModelNonFirst
|
|
946
|
-
) {
|
|
947
|
-
instance.resetGrouping()
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
if (
|
|
951
|
-
instance.options.autoResetExpanded &&
|
|
952
|
-
// @ts-ignore
|
|
953
|
-
instance.getRowModelNonFirst
|
|
954
|
-
) {
|
|
955
|
-
instance.resetExpanded()
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
// @ts-ignore
|
|
959
|
-
instance.getRowModelNonFirst = true
|
|
960
|
-
|
|
961
920
|
// Access the row model using initial columns
|
|
962
921
|
const rows: Row<
|
|
963
922
|
TData,
|
|
@@ -1066,8 +1025,14 @@ export function createTableInstance<
|
|
|
1066
1025
|
|
|
1067
1026
|
return { rows, flatRows, rowsById }
|
|
1068
1027
|
},
|
|
1069
|
-
|
|
1070
|
-
|
|
1028
|
+
{
|
|
1029
|
+
key: 'getRowModel',
|
|
1030
|
+
debug: instance.options.debug,
|
|
1031
|
+
onChange: () => {
|
|
1032
|
+
instance._notifyRowSelectionReset()
|
|
1033
|
+
instance._notifyFiltersReset()
|
|
1034
|
+
},
|
|
1035
|
+
}
|
|
1071
1036
|
),
|
|
1072
1037
|
|
|
1073
1038
|
// The standard
|
|
@@ -1188,7 +1153,30 @@ export function createTableInstance<
|
|
|
1188
1153
|
userProps
|
|
1189
1154
|
)
|
|
1190
1155
|
},
|
|
1156
|
+
|
|
1157
|
+
getTableWidth: () =>
|
|
1158
|
+
instance.getHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
1159
|
+
return sum + header.getWidth()
|
|
1160
|
+
}, 0) ?? 0,
|
|
1161
|
+
getLeftTableWidth: () =>
|
|
1162
|
+
instance.getLeftHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
1163
|
+
return sum + header.getWidth()
|
|
1164
|
+
}, 0) ?? 0,
|
|
1165
|
+
getCenterTableWidth: () =>
|
|
1166
|
+
instance.getCenterHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
1167
|
+
return sum + header.getWidth()
|
|
1168
|
+
}, 0) ?? 0,
|
|
1169
|
+
getRightTableWidth: () =>
|
|
1170
|
+
instance.getRightHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
1171
|
+
return sum + header.getWidth()
|
|
1172
|
+
}, 0) ?? 0,
|
|
1191
1173
|
}
|
|
1192
1174
|
|
|
1193
|
-
|
|
1175
|
+
instance = Object.assign(instance, finalInstance)
|
|
1176
|
+
|
|
1177
|
+
// This won't trigger a rerender yet, but it will force
|
|
1178
|
+
// pagination derivation to run (particularly pageSize detection)
|
|
1179
|
+
instance.setPagination(d => d)
|
|
1180
|
+
|
|
1181
|
+
return instance
|
|
1194
1182
|
}
|