@tanstack/table-core 8.0.14 → 8.1.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/cjs/features/RowSelection.js +20 -8
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +20 -9
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +301 -301
- package/build/types/index.d.ts +4 -2
- package/build/umd/index.development.js +20 -8
- 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/features/RowSelection.ts +22 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0
|
|
4
|
+
"version": "8.1.0",
|
|
5
5
|
"description": "Headless UI for building powerful tables & datagrids for TS/JS.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/table#readme",
|
|
@@ -37,6 +37,7 @@ export type RowSelectionOptions<TData extends RowData> = {
|
|
|
37
37
|
export type RowSelectionRow = {
|
|
38
38
|
getIsSelected: () => boolean
|
|
39
39
|
getIsSomeSelected: () => boolean
|
|
40
|
+
getIsAllSubRowsSelected: () => boolean
|
|
40
41
|
getCanSelect: () => boolean
|
|
41
42
|
getCanMultiSelect: () => boolean
|
|
42
43
|
getCanSelectSubRows: () => boolean
|
|
@@ -361,12 +362,17 @@ export const RowSelection: TableFeature = {
|
|
|
361
362
|
},
|
|
362
363
|
getIsSelected: () => {
|
|
363
364
|
const { rowSelection } = table.getState()
|
|
364
|
-
return isRowSelected(row, rowSelection
|
|
365
|
+
return isRowSelected(row, rowSelection)
|
|
365
366
|
},
|
|
366
367
|
|
|
367
368
|
getIsSomeSelected: () => {
|
|
368
369
|
const { rowSelection } = table.getState()
|
|
369
|
-
return
|
|
370
|
+
return isSubRowSelected(row, rowSelection, table) === 'some'
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
getIsAllSubRowsSelected: () => {
|
|
374
|
+
const { rowSelection } = table.getState()
|
|
375
|
+
return isSubRowSelected(row, rowSelection, table) === 'all'
|
|
370
376
|
},
|
|
371
377
|
|
|
372
378
|
getCanSelect: () => {
|
|
@@ -421,6 +427,9 @@ const mutateRowIsSelected = <TData extends RowData>(
|
|
|
421
427
|
// (isGrouped && table.options.enableGroupingRowSelection)
|
|
422
428
|
// ) {
|
|
423
429
|
if (value) {
|
|
430
|
+
if (!row.getCanMultiSelect()) {
|
|
431
|
+
Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key])
|
|
432
|
+
}
|
|
424
433
|
selectedRowIds[id] = true
|
|
425
434
|
} else {
|
|
426
435
|
delete selectedRowIds[id]
|
|
@@ -447,7 +456,7 @@ export function selectRowsFn<TData extends RowData>(
|
|
|
447
456
|
const recurseRows = (rows: Row<TData>[], depth = 0): Row<TData>[] => {
|
|
448
457
|
return rows
|
|
449
458
|
.map(row => {
|
|
450
|
-
const isSelected = isRowSelected(row, rowSelection
|
|
459
|
+
const isSelected = isRowSelected(row, rowSelection)
|
|
451
460
|
|
|
452
461
|
if (isSelected) {
|
|
453
462
|
newSelectedFlatRows.push(row)
|
|
@@ -476,14 +485,17 @@ export function selectRowsFn<TData extends RowData>(
|
|
|
476
485
|
}
|
|
477
486
|
|
|
478
487
|
export function isRowSelected<TData extends RowData>(
|
|
488
|
+
row: Row<TData>,
|
|
489
|
+
selection: Record<string, boolean>
|
|
490
|
+
): boolean {
|
|
491
|
+
return selection[row.id] ?? false
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export function isSubRowSelected<TData extends RowData>(
|
|
479
495
|
row: Row<TData>,
|
|
480
496
|
selection: Record<string, boolean>,
|
|
481
497
|
table: Table<TData>
|
|
482
|
-
): boolean | 'some' {
|
|
483
|
-
if (selection[row.id]) {
|
|
484
|
-
return true
|
|
485
|
-
}
|
|
486
|
-
|
|
498
|
+
): boolean | 'some' | 'all' {
|
|
487
499
|
if (row.subRows && row.subRows.length) {
|
|
488
500
|
let allChildrenSelected = true
|
|
489
501
|
let someSelected = false
|
|
@@ -494,14 +506,14 @@ export function isRowSelected<TData extends RowData>(
|
|
|
494
506
|
return
|
|
495
507
|
}
|
|
496
508
|
|
|
497
|
-
if (isRowSelected(subRow, selection
|
|
509
|
+
if (isRowSelected(subRow, selection)) {
|
|
498
510
|
someSelected = true
|
|
499
511
|
} else {
|
|
500
512
|
allChildrenSelected = false
|
|
501
513
|
}
|
|
502
514
|
})
|
|
503
515
|
|
|
504
|
-
return allChildrenSelected ?
|
|
516
|
+
return allChildrenSelected ? 'all' : someSelected ? 'some' : false
|
|
505
517
|
}
|
|
506
518
|
|
|
507
519
|
return false
|