@tanstack/table-core 8.11.8 → 8.12.0
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 -4
- package/build/lib/core/cell.js.map +1 -1
- package/build/lib/core/column.js +2 -14
- package/build/lib/core/column.js.map +1 -1
- package/build/lib/core/headers.js +17 -112
- package/build/lib/core/headers.js.map +1 -1
- package/build/lib/core/row.js +2 -14
- package/build/lib/core/row.js.map +1 -1
- package/build/lib/core/table.d.ts +6 -0
- package/build/lib/core/table.js +5 -35
- package/build/lib/core/table.js.map +1 -1
- package/build/lib/features/ColumnSizing.d.ts +6 -2
- package/build/lib/features/ColumnSizing.js +3 -9
- package/build/lib/features/ColumnSizing.js.map +1 -1
- package/build/lib/features/Ordering.d.ts +21 -0
- package/build/lib/features/Ordering.js +15 -4
- package/build/lib/features/Ordering.js.map +1 -1
- package/build/lib/features/Pagination.js +1 -7
- package/build/lib/features/Pagination.js.map +1 -1
- package/build/lib/features/Pinning.js +9 -57
- package/build/lib/features/Pinning.js.map +1 -1
- package/build/lib/features/RowSelection.js +3 -21
- package/build/lib/features/RowSelection.js.map +1 -1
- package/build/lib/features/Visibility.d.ts +3 -1
- package/build/lib/features/Visibility.js +7 -21
- package/build/lib/features/Visibility.js.map +1 -1
- package/build/lib/index.esm.js +89 -382
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +2 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +89 -382
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/types.d.ts +2 -2
- package/build/lib/utils/getCoreRowModel.js +1 -10
- package/build/lib/utils/getCoreRowModel.js.map +1 -1
- package/build/lib/utils/getExpandedRowModel.js +1 -7
- package/build/lib/utils/getExpandedRowModel.js.map +1 -1
- package/build/lib/utils/getFacetedMinMaxValues.js +1 -8
- package/build/lib/utils/getFacetedMinMaxValues.js.map +1 -1
- package/build/lib/utils/getFacetedRowModel.js +1 -8
- package/build/lib/utils/getFacetedRowModel.js.map +1 -1
- package/build/lib/utils/getFacetedUniqueValues.js +1 -8
- package/build/lib/utils/getFacetedUniqueValues.js.map +1 -1
- package/build/lib/utils/getFilteredRowModel.js +1 -10
- package/build/lib/utils/getFilteredRowModel.js.map +1 -1
- package/build/lib/utils/getGroupedRowModel.js +6 -13
- package/build/lib/utils/getGroupedRowModel.js.map +1 -1
- package/build/lib/utils/getPaginationRowModel.js +1 -7
- package/build/lib/utils/getPaginationRowModel.js.map +1 -1
- package/build/lib/utils/getSortedRowModel.js +1 -10
- package/build/lib/utils/getSortedRowModel.js.map +1 -1
- package/build/lib/utils.d.ts +8 -3
- package/build/lib/utils.js +13 -2
- package/build/lib/utils.js.map +1 -1
- package/build/umd/index.development.js +90 -381
- 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 +2 -5
- package/src/core/column.ts +3 -9
- package/src/core/headers.ts +19 -65
- package/src/core/row.ts +3 -10
- package/src/core/table.ts +12 -21
- package/src/features/ColumnSizing.ts +33 -20
- package/src/features/Ordering.ts +74 -35
- package/src/features/Pagination.ts +7 -5
- package/src/features/Pinning.ts +34 -60
- package/src/features/RowSelection.ts +4 -16
- package/src/features/Visibility.ts +18 -13
- package/src/types.ts +3 -1
- package/src/utils/getCoreRowModel.ts +4 -8
- package/src/utils/getExpandedRowModel.ts +2 -5
- package/src/utils/getFacetedMinMaxValues.ts +2 -8
- package/src/utils/getFacetedRowModel.ts +2 -8
- package/src/utils/getFacetedUniqueValues.ts +6 -8
- package/src/utils/getFilteredRowModel.ts +4 -8
- package/src/utils/getGroupedRowModel.ts +7 -11
- package/src/utils/getPaginationRowModel.ts +2 -5
- package/src/utils/getSortedRowModel.ts +4 -8
- package/src/utils.ts +25 -6
package/package.json
CHANGED
package/src/core/cell.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RowData, Cell, Column, Row, Table } from '../types'
|
|
2
|
-
import { Getter, memo } from '../utils'
|
|
2
|
+
import { Getter, getMemoOptions, memo } from '../utils'
|
|
3
3
|
|
|
4
4
|
export interface CellContext<TData extends RowData, TValue> {
|
|
5
5
|
cell: Cell<TData, TValue>
|
|
@@ -74,10 +74,7 @@ export function createCell<TData extends RowData, TValue>(
|
|
|
74
74
|
getValue: cell.getValue,
|
|
75
75
|
renderValue: cell.renderValue,
|
|
76
76
|
}),
|
|
77
|
-
|
|
78
|
-
key: process.env.NODE_ENV === 'development' && 'cell.getContext',
|
|
79
|
-
debug: () => table.options.debugAll,
|
|
80
|
-
}
|
|
77
|
+
getMemoOptions(table.options, 'debugCells', 'cell.getContext')
|
|
81
78
|
),
|
|
82
79
|
}
|
|
83
80
|
|
package/src/core/column.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
RowData,
|
|
7
7
|
ColumnDefResolved,
|
|
8
8
|
} from '../types'
|
|
9
|
-
import { memo } from '../utils'
|
|
9
|
+
import { getMemoOptions, memo } from '../utils'
|
|
10
10
|
|
|
11
11
|
export interface CoreColumn<TData extends RowData, TValue> {
|
|
12
12
|
/**
|
|
@@ -137,10 +137,7 @@ export function createColumn<TData extends RowData, TValue>(
|
|
|
137
137
|
...column.columns?.flatMap(d => d.getFlatColumns()),
|
|
138
138
|
]
|
|
139
139
|
},
|
|
140
|
-
|
|
141
|
-
key: process.env.NODE_ENV === 'production' && 'column.getFlatColumns',
|
|
142
|
-
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
143
|
-
}
|
|
140
|
+
getMemoOptions(table.options, 'debugColumns', 'column.getFlatColumns')
|
|
144
141
|
),
|
|
145
142
|
getLeafColumns: memo(
|
|
146
143
|
() => [table._getOrderColumnsFn()],
|
|
@@ -155,10 +152,7 @@ export function createColumn<TData extends RowData, TValue>(
|
|
|
155
152
|
|
|
156
153
|
return [column as Column<TData, TValue>]
|
|
157
154
|
},
|
|
158
|
-
|
|
159
|
-
key: process.env.NODE_ENV === 'production' && 'column.getLeafColumns',
|
|
160
|
-
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
161
|
-
}
|
|
155
|
+
getMemoOptions(table.options, 'debugColumns', 'column.getLeafColumns')
|
|
162
156
|
),
|
|
163
157
|
}
|
|
164
158
|
|
package/src/core/headers.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { RowData, Column, Header, HeaderGroup, Table } from '../types'
|
|
2
|
-
import { memo } from '../utils'
|
|
2
|
+
import { getMemoOptions, memo } from '../utils'
|
|
3
3
|
import { TableFeature } from './table'
|
|
4
4
|
|
|
5
|
+
const debug = 'debugHeaders'
|
|
6
|
+
|
|
5
7
|
export interface CoreHeaderGroup<TData extends RowData> {
|
|
6
8
|
depth: number
|
|
7
9
|
headers: Header<TData, unknown>[]
|
|
@@ -288,10 +290,7 @@ export const Headers: TableFeature = {
|
|
|
288
290
|
|
|
289
291
|
return headerGroups
|
|
290
292
|
},
|
|
291
|
-
|
|
292
|
-
key: process.env.NODE_ENV === 'development' && 'getHeaderGroups',
|
|
293
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
294
|
-
}
|
|
293
|
+
getMemoOptions(table.options, debug, 'getHeaderGroups')
|
|
295
294
|
)
|
|
296
295
|
|
|
297
296
|
table.getCenterHeaderGroups = memo(
|
|
@@ -307,10 +306,7 @@ export const Headers: TableFeature = {
|
|
|
307
306
|
)
|
|
308
307
|
return buildHeaderGroups(allColumns, leafColumns, table, 'center')
|
|
309
308
|
},
|
|
310
|
-
|
|
311
|
-
key: process.env.NODE_ENV === 'development' && 'getCenterHeaderGroups',
|
|
312
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
313
|
-
}
|
|
309
|
+
getMemoOptions(table.options, debug, 'getCenterHeaderGroups')
|
|
314
310
|
)
|
|
315
311
|
|
|
316
312
|
table.getLeftHeaderGroups = memo(
|
|
@@ -327,10 +323,7 @@ export const Headers: TableFeature = {
|
|
|
327
323
|
|
|
328
324
|
return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'left')
|
|
329
325
|
},
|
|
330
|
-
|
|
331
|
-
key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
|
|
332
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
333
|
-
}
|
|
326
|
+
getMemoOptions(table.options, debug, 'getLeftHeaderGroups')
|
|
334
327
|
)
|
|
335
328
|
|
|
336
329
|
table.getRightHeaderGroups = memo(
|
|
@@ -347,10 +340,7 @@ export const Headers: TableFeature = {
|
|
|
347
340
|
|
|
348
341
|
return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'right')
|
|
349
342
|
},
|
|
350
|
-
|
|
351
|
-
key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
|
|
352
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
353
|
-
}
|
|
343
|
+
getMemoOptions(table.options, debug, 'getRightHeaderGroups')
|
|
354
344
|
)
|
|
355
345
|
|
|
356
346
|
// Footer Groups
|
|
@@ -360,10 +350,7 @@ export const Headers: TableFeature = {
|
|
|
360
350
|
headerGroups => {
|
|
361
351
|
return [...headerGroups].reverse()
|
|
362
352
|
},
|
|
363
|
-
|
|
364
|
-
key: process.env.NODE_ENV === 'development' && 'getFooterGroups',
|
|
365
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
366
|
-
}
|
|
353
|
+
getMemoOptions(table.options, debug, 'getFooterGroups')
|
|
367
354
|
)
|
|
368
355
|
|
|
369
356
|
table.getLeftFooterGroups = memo(
|
|
@@ -371,10 +358,7 @@ export const Headers: TableFeature = {
|
|
|
371
358
|
headerGroups => {
|
|
372
359
|
return [...headerGroups].reverse()
|
|
373
360
|
},
|
|
374
|
-
|
|
375
|
-
key: process.env.NODE_ENV === 'development' && 'getLeftFooterGroups',
|
|
376
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
377
|
-
}
|
|
361
|
+
getMemoOptions(table.options, debug, 'getLeftFooterGroups')
|
|
378
362
|
)
|
|
379
363
|
|
|
380
364
|
table.getCenterFooterGroups = memo(
|
|
@@ -382,10 +366,7 @@ export const Headers: TableFeature = {
|
|
|
382
366
|
headerGroups => {
|
|
383
367
|
return [...headerGroups].reverse()
|
|
384
368
|
},
|
|
385
|
-
|
|
386
|
-
key: process.env.NODE_ENV === 'development' && 'getCenterFooterGroups',
|
|
387
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
388
|
-
}
|
|
369
|
+
getMemoOptions(table.options, debug, 'getCenterFooterGroups')
|
|
389
370
|
)
|
|
390
371
|
|
|
391
372
|
table.getRightFooterGroups = memo(
|
|
@@ -393,10 +374,7 @@ export const Headers: TableFeature = {
|
|
|
393
374
|
headerGroups => {
|
|
394
375
|
return [...headerGroups].reverse()
|
|
395
376
|
},
|
|
396
|
-
|
|
397
|
-
key: process.env.NODE_ENV === 'development' && 'getRightFooterGroups',
|
|
398
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
399
|
-
}
|
|
377
|
+
getMemoOptions(table.options, debug, 'getRightFooterGroups')
|
|
400
378
|
)
|
|
401
379
|
|
|
402
380
|
// Flat Headers
|
|
@@ -410,10 +388,7 @@ export const Headers: TableFeature = {
|
|
|
410
388
|
})
|
|
411
389
|
.flat()
|
|
412
390
|
},
|
|
413
|
-
|
|
414
|
-
key: process.env.NODE_ENV === 'development' && 'getFlatHeaders',
|
|
415
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
416
|
-
}
|
|
391
|
+
getMemoOptions(table.options, debug, 'getFlatHeaders')
|
|
417
392
|
)
|
|
418
393
|
|
|
419
394
|
table.getLeftFlatHeaders = memo(
|
|
@@ -425,10 +400,7 @@ export const Headers: TableFeature = {
|
|
|
425
400
|
})
|
|
426
401
|
.flat()
|
|
427
402
|
},
|
|
428
|
-
|
|
429
|
-
key: process.env.NODE_ENV === 'development' && 'getLeftFlatHeaders',
|
|
430
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
431
|
-
}
|
|
403
|
+
getMemoOptions(table.options, debug, 'getLeftFlatHeaders')
|
|
432
404
|
)
|
|
433
405
|
|
|
434
406
|
table.getCenterFlatHeaders = memo(
|
|
@@ -440,10 +412,7 @@ export const Headers: TableFeature = {
|
|
|
440
412
|
})
|
|
441
413
|
.flat()
|
|
442
414
|
},
|
|
443
|
-
|
|
444
|
-
key: process.env.NODE_ENV === 'development' && 'getCenterFlatHeaders',
|
|
445
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
446
|
-
}
|
|
415
|
+
getMemoOptions(table.options, debug, 'getCenterFlatHeaders')
|
|
447
416
|
)
|
|
448
417
|
|
|
449
418
|
table.getRightFlatHeaders = memo(
|
|
@@ -455,10 +424,7 @@ export const Headers: TableFeature = {
|
|
|
455
424
|
})
|
|
456
425
|
.flat()
|
|
457
426
|
},
|
|
458
|
-
|
|
459
|
-
key: process.env.NODE_ENV === 'development' && 'getRightFlatHeaders',
|
|
460
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
461
|
-
}
|
|
427
|
+
getMemoOptions(table.options, debug, 'getRightFlatHeaders')
|
|
462
428
|
)
|
|
463
429
|
|
|
464
430
|
// Leaf Headers
|
|
@@ -468,10 +434,7 @@ export const Headers: TableFeature = {
|
|
|
468
434
|
flatHeaders => {
|
|
469
435
|
return flatHeaders.filter(header => !header.subHeaders?.length)
|
|
470
436
|
},
|
|
471
|
-
|
|
472
|
-
key: process.env.NODE_ENV === 'development' && 'getCenterLeafHeaders',
|
|
473
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
474
|
-
}
|
|
437
|
+
getMemoOptions(table.options, debug, 'getCenterLeafHeaders')
|
|
475
438
|
)
|
|
476
439
|
|
|
477
440
|
table.getLeftLeafHeaders = memo(
|
|
@@ -479,10 +442,7 @@ export const Headers: TableFeature = {
|
|
|
479
442
|
flatHeaders => {
|
|
480
443
|
return flatHeaders.filter(header => !header.subHeaders?.length)
|
|
481
444
|
},
|
|
482
|
-
|
|
483
|
-
key: process.env.NODE_ENV === 'development' && 'getLeftLeafHeaders',
|
|
484
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
485
|
-
}
|
|
445
|
+
getMemoOptions(table.options, debug, 'getLeftLeafHeaders')
|
|
486
446
|
)
|
|
487
447
|
|
|
488
448
|
table.getRightLeafHeaders = memo(
|
|
@@ -490,10 +450,7 @@ export const Headers: TableFeature = {
|
|
|
490
450
|
flatHeaders => {
|
|
491
451
|
return flatHeaders.filter(header => !header.subHeaders?.length)
|
|
492
452
|
},
|
|
493
|
-
|
|
494
|
-
key: process.env.NODE_ENV === 'development' && 'getRightLeafHeaders',
|
|
495
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
496
|
-
}
|
|
453
|
+
getMemoOptions(table.options, debug, 'getRightLeafHeaders')
|
|
497
454
|
)
|
|
498
455
|
|
|
499
456
|
table.getLeafHeaders = memo(
|
|
@@ -513,10 +470,7 @@ export const Headers: TableFeature = {
|
|
|
513
470
|
})
|
|
514
471
|
.flat()
|
|
515
472
|
},
|
|
516
|
-
|
|
517
|
-
key: process.env.NODE_ENV === 'development' && 'getLeafHeaders',
|
|
518
|
-
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
519
|
-
}
|
|
473
|
+
getMemoOptions(table.options, debug, 'getLeafHeaders')
|
|
520
474
|
)
|
|
521
475
|
},
|
|
522
476
|
}
|
package/src/core/row.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RowData, Cell, Row, Table } from '../types'
|
|
2
|
-
import { flattenBy, memo } from '../utils'
|
|
2
|
+
import { flattenBy, getMemoOptions, memo } from '../utils'
|
|
3
3
|
import { createCell } from './cell'
|
|
4
4
|
|
|
5
5
|
export interface CoreRow<TData extends RowData> {
|
|
@@ -174,10 +174,7 @@ export const createRow = <TData extends RowData>(
|
|
|
174
174
|
return createCell(table, row as Row<TData>, column, column.id)
|
|
175
175
|
})
|
|
176
176
|
},
|
|
177
|
-
|
|
178
|
-
key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
|
|
179
|
-
debug: () => table.options.debugAll ?? table.options.debugRows,
|
|
180
|
-
}
|
|
177
|
+
getMemoOptions(table.options, 'debugRows', 'getAllCells')
|
|
181
178
|
),
|
|
182
179
|
|
|
183
180
|
_getAllCellsByColumnId: memo(
|
|
@@ -191,11 +188,7 @@ export const createRow = <TData extends RowData>(
|
|
|
191
188
|
{} as Record<string, Cell<TData, unknown>>
|
|
192
189
|
)
|
|
193
190
|
},
|
|
194
|
-
|
|
195
|
-
key:
|
|
196
|
-
process.env.NODE_ENV === 'production' && 'row.getAllCellsByColumnId',
|
|
197
|
-
debug: () => table.options.debugAll ?? table.options.debugRows,
|
|
198
|
-
}
|
|
191
|
+
getMemoOptions(table.options, 'debugRows', 'getAllCellsByColumnId')
|
|
199
192
|
),
|
|
200
193
|
}
|
|
201
194
|
|
package/src/core/table.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { functionalUpdate, memo, RequiredKeys } from '../utils'
|
|
1
|
+
import { functionalUpdate, getMemoOptions, memo, RequiredKeys } from '../utils'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
Updater,
|
|
@@ -87,6 +87,12 @@ export interface CoreOptions<TData extends RowData> {
|
|
|
87
87
|
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
|
|
88
88
|
*/
|
|
89
89
|
debugAll?: boolean
|
|
90
|
+
/**
|
|
91
|
+
* Set this option to `true` to output cell debugging information to the console.
|
|
92
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#debugcells]
|
|
93
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
|
|
94
|
+
*/
|
|
95
|
+
debugCells?: boolean
|
|
90
96
|
/**
|
|
91
97
|
* Set this option to `true` to output column debugging information to the console.
|
|
92
98
|
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#debugcolumns)
|
|
@@ -422,10 +428,7 @@ export function createTable<TData extends RowData>(
|
|
|
422
428
|
...defaultColumn,
|
|
423
429
|
} as Partial<ColumnDef<TData, unknown>>
|
|
424
430
|
},
|
|
425
|
-
|
|
426
|
-
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
427
|
-
key: process.env.NODE_ENV === 'development' && 'getDefaultColumnDef',
|
|
428
|
-
}
|
|
431
|
+
getMemoOptions(options, 'debugColumns', '_getDefaultColumnDef')
|
|
429
432
|
),
|
|
430
433
|
|
|
431
434
|
_getColumnDefs: () => table.options.columns,
|
|
@@ -456,10 +459,7 @@ export function createTable<TData extends RowData>(
|
|
|
456
459
|
|
|
457
460
|
return recurseColumns(columnDefs)
|
|
458
461
|
},
|
|
459
|
-
|
|
460
|
-
key: process.env.NODE_ENV === 'development' && 'getAllColumns',
|
|
461
|
-
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
462
|
-
}
|
|
462
|
+
getMemoOptions(options, 'debugColumns', 'getAllColumns')
|
|
463
463
|
),
|
|
464
464
|
|
|
465
465
|
getAllFlatColumns: memo(
|
|
@@ -469,10 +469,7 @@ export function createTable<TData extends RowData>(
|
|
|
469
469
|
return column.getFlatColumns()
|
|
470
470
|
})
|
|
471
471
|
},
|
|
472
|
-
|
|
473
|
-
key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
|
|
474
|
-
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
475
|
-
}
|
|
472
|
+
getMemoOptions(options, 'debugColumns', 'getAllFlatColumns')
|
|
476
473
|
),
|
|
477
474
|
|
|
478
475
|
_getAllFlatColumnsById: memo(
|
|
@@ -486,10 +483,7 @@ export function createTable<TData extends RowData>(
|
|
|
486
483
|
{} as Record<string, Column<TData, unknown>>
|
|
487
484
|
)
|
|
488
485
|
},
|
|
489
|
-
|
|
490
|
-
key: process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
|
|
491
|
-
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
492
|
-
}
|
|
486
|
+
getMemoOptions(options, 'debugColumns', 'getAllFlatColumnsById')
|
|
493
487
|
),
|
|
494
488
|
|
|
495
489
|
getAllLeafColumns: memo(
|
|
@@ -498,10 +492,7 @@ export function createTable<TData extends RowData>(
|
|
|
498
492
|
let leafColumns = allColumns.flatMap(column => column.getLeafColumns())
|
|
499
493
|
return orderColumns(leafColumns)
|
|
500
494
|
},
|
|
501
|
-
|
|
502
|
-
key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
|
|
503
|
-
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
504
|
-
}
|
|
495
|
+
getMemoOptions(options, 'debugColumns', 'getAllLeafColumns')
|
|
505
496
|
),
|
|
506
497
|
|
|
507
498
|
getColumn: columnId => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { _getVisibleLeafColumns } from '..'
|
|
1
2
|
import { TableFeature } from '../core/table'
|
|
2
3
|
import { RowData, Column, Header, OnChangeFn, Table, Updater } from '../types'
|
|
3
|
-
import { makeStateUpdater } from '../utils'
|
|
4
|
+
import { getMemoOptions, makeStateUpdater, memo } from '../utils'
|
|
4
5
|
import { ColumnPinningPosition } from './Pinning'
|
|
5
6
|
|
|
6
7
|
//
|
|
@@ -164,11 +165,15 @@ export interface ColumnSizingColumn {
|
|
|
164
165
|
*/
|
|
165
166
|
getSize: () => number
|
|
166
167
|
/**
|
|
167
|
-
* Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the header. This is effectively a sum of the offset measurements of all preceding headers.
|
|
168
|
+
* Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the header. This is effectively a sum of the offset measurements of all preceding (left) headers in relation to the current column.
|
|
168
169
|
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#getstart)
|
|
169
170
|
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing)
|
|
170
171
|
*/
|
|
171
|
-
getStart: (position?: ColumnPinningPosition) => number
|
|
172
|
+
getStart: (position?: ColumnPinningPosition | 'center') => number
|
|
173
|
+
/**
|
|
174
|
+
* Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the header. This is effectively a sum of the offset measurements of all succeeding (right) headers in relation to the current column.
|
|
175
|
+
*/
|
|
176
|
+
getAfter: (position?: ColumnPinningPosition | 'center') => number
|
|
172
177
|
/**
|
|
173
178
|
* Resets the column to its initial size.
|
|
174
179
|
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#resetsize)
|
|
@@ -257,25 +262,33 @@ export const ColumnSizing: TableFeature = {
|
|
|
257
262
|
column.columnDef.maxSize ?? defaultColumnSizing.maxSize
|
|
258
263
|
)
|
|
259
264
|
}
|
|
260
|
-
column.getStart = position => {
|
|
261
|
-
const columns = !position
|
|
262
|
-
? table.getVisibleLeafColumns()
|
|
263
|
-
: position === 'left'
|
|
264
|
-
? table.getLeftVisibleLeafColumns()
|
|
265
|
-
: table.getRightVisibleLeafColumns()
|
|
266
|
-
|
|
267
|
-
const index = columns.findIndex(d => d.id === column.id)
|
|
268
265
|
|
|
269
|
-
|
|
270
|
-
|
|
266
|
+
column.getStart = memo(
|
|
267
|
+
position => [
|
|
268
|
+
position,
|
|
269
|
+
_getVisibleLeafColumns(table, position),
|
|
270
|
+
table.getState().columnSizing,
|
|
271
|
+
],
|
|
272
|
+
(position, columns) =>
|
|
273
|
+
columns
|
|
274
|
+
.slice(0, column.getIndex(position))
|
|
275
|
+
.reduce((sum, column) => sum + column.getSize(), 0),
|
|
276
|
+
getMemoOptions(table.options, 'debugColumns', 'getStart')
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
column.getAfter = memo(
|
|
280
|
+
position => [
|
|
281
|
+
position,
|
|
282
|
+
_getVisibleLeafColumns(table, position),
|
|
283
|
+
table.getState().columnSizing,
|
|
284
|
+
],
|
|
285
|
+
(position, columns) =>
|
|
286
|
+
columns
|
|
287
|
+
.slice(column.getIndex(position) + 1)
|
|
288
|
+
.reduce((sum, column) => sum + column.getSize(), 0),
|
|
289
|
+
getMemoOptions(table.options, 'debugColumns', 'getAfter')
|
|
290
|
+
)
|
|
271
291
|
|
|
272
|
-
return (
|
|
273
|
-
prevSiblingColumn.getStart(position) + prevSiblingColumn.getSize()
|
|
274
|
-
)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return 0
|
|
278
|
-
}
|
|
279
292
|
column.resetSize = () => {
|
|
280
293
|
table.setColumnSizing(({ [column.id]: _, ...rest }) => {
|
|
281
294
|
return rest
|
package/src/features/Ordering.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { makeStateUpdater, memo } from '../utils'
|
|
1
|
+
import { getMemoOptions, makeStateUpdater, memo } from '../utils'
|
|
2
2
|
|
|
3
3
|
import { Table, OnChangeFn, Updater, Column, RowData } from '../types'
|
|
4
4
|
|
|
5
5
|
import { orderColumns } from './Grouping'
|
|
6
6
|
import { TableFeature } from '../core/table'
|
|
7
|
+
import { ColumnPinningPosition, _getVisibleLeafColumns } from '..'
|
|
7
8
|
|
|
8
9
|
export interface ColumnOrderTableState {
|
|
9
10
|
columnOrder: ColumnOrderState
|
|
@@ -20,6 +21,27 @@ export interface ColumnOrderOptions {
|
|
|
20
21
|
onColumnOrderChange?: OnChangeFn<ColumnOrderState>
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
export interface ColumnOrderColumn {
|
|
25
|
+
/**
|
|
26
|
+
* Returns the index of the column in the order of the visible columns. Optionally pass a `position` parameter to get the index of the column in a sub-section of the table
|
|
27
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-ordering#getindex)
|
|
28
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-ordering)
|
|
29
|
+
*/
|
|
30
|
+
getIndex: (position?: ColumnPinningPosition | 'center') => number
|
|
31
|
+
/**
|
|
32
|
+
* Returns `true` if the column is the first column in the order of the visible columns. Optionally pass a `position` parameter to check if the column is the first in a sub-section of the table.
|
|
33
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-ordering#getisfirstcolumn)
|
|
34
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-ordering)
|
|
35
|
+
*/
|
|
36
|
+
getIsFirstColumn: (position?: ColumnPinningPosition | 'center') => boolean
|
|
37
|
+
/**
|
|
38
|
+
* Returns `true` if the column is the last column in the order of the visible columns. Optionally pass a `position` parameter to check if the column is the last in a sub-section of the table.
|
|
39
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-ordering#getislastcolumn)
|
|
40
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-ordering)
|
|
41
|
+
*/
|
|
42
|
+
getIsLastColumn: (position?: ColumnPinningPosition | 'center') => boolean
|
|
43
|
+
}
|
|
44
|
+
|
|
23
45
|
export interface ColumnOrderDefaultOptions {
|
|
24
46
|
onColumnOrderChange: OnChangeFn<ColumnOrderState>
|
|
25
47
|
}
|
|
@@ -60,6 +82,25 @@ export const Ordering: TableFeature = {
|
|
|
60
82
|
}
|
|
61
83
|
},
|
|
62
84
|
|
|
85
|
+
createColumn: <TData extends RowData>(
|
|
86
|
+
column: Column<TData, unknown>,
|
|
87
|
+
table: Table<TData>
|
|
88
|
+
): void => {
|
|
89
|
+
column.getIndex = memo(
|
|
90
|
+
position => [_getVisibleLeafColumns(table, position)],
|
|
91
|
+
columns => columns.findIndex(d => d.id === column.id),
|
|
92
|
+
getMemoOptions(table.options, 'debugColumns', 'getIndex')
|
|
93
|
+
)
|
|
94
|
+
column.getIsFirstColumn = position => {
|
|
95
|
+
const columns = _getVisibleLeafColumns(table, position)
|
|
96
|
+
return columns[0]?.id === column.id
|
|
97
|
+
}
|
|
98
|
+
column.getIsLastColumn = position => {
|
|
99
|
+
const columns = _getVisibleLeafColumns(table, position)
|
|
100
|
+
return columns[columns.length - 1]?.id === column.id
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
63
104
|
createTable: <TData extends RowData>(table: Table<TData>): void => {
|
|
64
105
|
table.setColumnOrder = updater =>
|
|
65
106
|
table.options.onColumnOrderChange?.(updater)
|
|
@@ -74,43 +115,41 @@ export const Ordering: TableFeature = {
|
|
|
74
115
|
table.getState().grouping,
|
|
75
116
|
table.options.groupedColumnMode,
|
|
76
117
|
],
|
|
77
|
-
(columnOrder, grouping, groupedColumnMode) =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
118
|
+
(columnOrder, grouping, groupedColumnMode) =>
|
|
119
|
+
(columns: Column<TData, unknown>[]) => {
|
|
120
|
+
// Sort grouped columns to the start of the column list
|
|
121
|
+
// before the headers are built
|
|
122
|
+
let orderedColumns: Column<TData, unknown>[] = []
|
|
123
|
+
|
|
124
|
+
// If there is no order, return the normal columns
|
|
125
|
+
if (!columnOrder?.length) {
|
|
126
|
+
orderedColumns = columns
|
|
127
|
+
} else {
|
|
128
|
+
const columnOrderCopy = [...columnOrder]
|
|
129
|
+
|
|
130
|
+
// If there is an order, make a copy of the columns
|
|
131
|
+
const columnsCopy = [...columns]
|
|
132
|
+
|
|
133
|
+
// And make a new ordered array of the columns
|
|
134
|
+
|
|
135
|
+
// Loop over the columns and place them in order into the new array
|
|
136
|
+
while (columnsCopy.length && columnOrderCopy.length) {
|
|
137
|
+
const targetColumnId = columnOrderCopy.shift()
|
|
138
|
+
const foundIndex = columnsCopy.findIndex(
|
|
139
|
+
d => d.id === targetColumnId
|
|
140
|
+
)
|
|
141
|
+
if (foundIndex > -1) {
|
|
142
|
+
orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]!)
|
|
143
|
+
}
|
|
101
144
|
}
|
|
102
|
-
}
|
|
103
145
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
146
|
+
// If there are any columns left, add them to the end
|
|
147
|
+
orderedColumns = [...orderedColumns, ...columnsCopy]
|
|
148
|
+
}
|
|
107
149
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn',
|
|
112
|
-
// debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
113
|
-
}
|
|
150
|
+
return orderColumns(orderedColumns, grouping, groupedColumnMode)
|
|
151
|
+
},
|
|
152
|
+
getMemoOptions(table.options, 'debugTable', '_getOrderColumnsFn')
|
|
114
153
|
)
|
|
115
154
|
},
|
|
116
155
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { TableFeature } from '../core/table'
|
|
2
2
|
import { OnChangeFn, Table, RowModel, Updater, RowData } from '../types'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
functionalUpdate,
|
|
5
|
+
getMemoOptions,
|
|
6
|
+
makeStateUpdater,
|
|
7
|
+
memo,
|
|
8
|
+
} from '../utils'
|
|
4
9
|
|
|
5
10
|
export interface PaginationState {
|
|
6
11
|
pageIndex: number
|
|
@@ -290,10 +295,7 @@ export const Pagination: TableFeature = {
|
|
|
290
295
|
}
|
|
291
296
|
return pageOptions
|
|
292
297
|
},
|
|
293
|
-
|
|
294
|
-
key: process.env.NODE_ENV === 'development' && 'getPageOptions',
|
|
295
|
-
debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
296
|
-
}
|
|
298
|
+
getMemoOptions(table.options, 'debugTable', 'getPageOptions')
|
|
297
299
|
)
|
|
298
300
|
|
|
299
301
|
table.getCanPreviousPage = () => table.getState().pagination.pageIndex > 0
|