@tanstack/table-core 8.8.0 → 8.8.2
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/row.d.ts +4 -2
- package/build/lib/core/row.js +14 -2
- package/build/lib/core/row.js.map +1 -1
- package/build/lib/features/RowSelection.js +3 -3
- package/build/lib/features/RowSelection.js.map +1 -1
- package/build/lib/index.esm.js +29 -17
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.mjs +29 -17
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/utils/filterRowsUtils.js +6 -6
- package/build/lib/utils/filterRowsUtils.js.map +1 -1
- package/build/lib/utils/getCoreRowModel.js +1 -1
- package/build/lib/utils/getCoreRowModel.js.map +1 -1
- package/build/lib/utils/getGroupedRowModel.js +5 -5
- package/build/lib/utils/getGroupedRowModel.js.map +1 -1
- package/build/umd/index.development.js +29 -17
- 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/row.ts +17 -3
- package/src/features/RowSelection.ts +3 -3
- package/src/utils/filterRowsUtils.ts +6 -14
- package/src/utils/getCoreRowModel.ts +1 -1
- package/src/utils/getGroupedRowModel.ts +4 -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.8.
|
|
4
|
+
"version": "8.8.2",
|
|
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",
|
package/src/core/row.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface CoreRow<TData extends RowData> {
|
|
|
7
7
|
index: number
|
|
8
8
|
original: TData
|
|
9
9
|
depth: number
|
|
10
|
+
parentId?: string
|
|
10
11
|
_valuesCache: Record<string, unknown>
|
|
11
12
|
_uniqueValuesCache: Record<string, unknown>
|
|
12
13
|
getValue: <TValue>(columnId: string) => TValue
|
|
@@ -17,7 +18,8 @@ export interface CoreRow<TData extends RowData> {
|
|
|
17
18
|
originalSubRows?: TData[]
|
|
18
19
|
getAllCells: () => Cell<TData, unknown>[]
|
|
19
20
|
_getAllCellsByColumnId: () => Record<string, Cell<TData, unknown>>
|
|
20
|
-
|
|
21
|
+
getParentRow: () => Row<TData> | undefined
|
|
22
|
+
getParentRows: () => Row<TData>[]
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export const createRow = <TData extends RowData>(
|
|
@@ -27,14 +29,14 @@ export const createRow = <TData extends RowData>(
|
|
|
27
29
|
rowIndex: number,
|
|
28
30
|
depth: number,
|
|
29
31
|
subRows?: Row<TData>[],
|
|
30
|
-
|
|
32
|
+
parentId?: string
|
|
31
33
|
): Row<TData> => {
|
|
32
34
|
let row: CoreRow<TData> = {
|
|
33
35
|
id,
|
|
34
36
|
index: rowIndex,
|
|
35
37
|
original,
|
|
36
38
|
depth,
|
|
37
|
-
|
|
39
|
+
parentId,
|
|
38
40
|
_valuesCache: {},
|
|
39
41
|
_uniqueValuesCache: {},
|
|
40
42
|
getValue: columnId => {
|
|
@@ -82,6 +84,18 @@ export const createRow = <TData extends RowData>(
|
|
|
82
84
|
row.getValue(columnId) ?? table.options.renderFallbackValue,
|
|
83
85
|
subRows: subRows ?? [],
|
|
84
86
|
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
87
|
+
getParentRow: () => (row.parentId ? table.getRow(row.parentId) : undefined),
|
|
88
|
+
getParentRows: () => {
|
|
89
|
+
let parentRows: Row<TData>[] = []
|
|
90
|
+
let currentRow = row
|
|
91
|
+
while (true) {
|
|
92
|
+
const parentRow = currentRow.getParentRow()
|
|
93
|
+
if (!parentRow) break
|
|
94
|
+
parentRows.push(parentRow)
|
|
95
|
+
currentRow = parentRow
|
|
96
|
+
}
|
|
97
|
+
return parentRows.reverse()
|
|
98
|
+
},
|
|
85
99
|
getAllCells: memo(
|
|
86
100
|
() => [table.getAllLeafColumns()],
|
|
87
101
|
leafColumns => {
|
|
@@ -288,7 +288,7 @@ export const RowSelection: TableFeature = {
|
|
|
288
288
|
},
|
|
289
289
|
|
|
290
290
|
getIsAllPageRowsSelected: () => {
|
|
291
|
-
const paginationFlatRows = table.getPaginationRowModel().flatRows
|
|
291
|
+
const paginationFlatRows = table.getPaginationRowModel().flatRows.filter(row => row.getCanSelect())
|
|
292
292
|
const { rowSelection } = table.getState()
|
|
293
293
|
|
|
294
294
|
let isAllPageRowsSelected = !!paginationFlatRows.length
|
|
@@ -296,7 +296,7 @@ export const RowSelection: TableFeature = {
|
|
|
296
296
|
if (
|
|
297
297
|
isAllPageRowsSelected &&
|
|
298
298
|
paginationFlatRows.some(
|
|
299
|
-
|
|
299
|
+
row => !rowSelection[row.id]
|
|
300
300
|
)
|
|
301
301
|
) {
|
|
302
302
|
isAllPageRowsSelected = false
|
|
@@ -319,7 +319,7 @@ export const RowSelection: TableFeature = {
|
|
|
319
319
|
const paginationFlatRows = table.getPaginationRowModel().flatRows
|
|
320
320
|
return table.getIsAllPageRowsSelected()
|
|
321
321
|
? false
|
|
322
|
-
: paginationFlatRows.some(
|
|
322
|
+
: paginationFlatRows.filter(row => row.getCanSelect()).some(
|
|
323
323
|
d => d.getIsSelected() || d.getIsSomeSelected()
|
|
324
324
|
)
|
|
325
325
|
},
|
|
@@ -22,11 +22,7 @@ export function filterRowModelFromLeafs<TData extends RowData>(
|
|
|
22
22
|
const newFilteredRowsById: Record<string, Row<TData>> = {}
|
|
23
23
|
const maxDepth = table.options.maxLeafRowFilterDepth ?? 100
|
|
24
24
|
|
|
25
|
-
const recurseFilterRows = (
|
|
26
|
-
rowsToFilter: Row<TData>[],
|
|
27
|
-
depth = 0,
|
|
28
|
-
parentRow?: Row<TData>
|
|
29
|
-
) => {
|
|
25
|
+
const recurseFilterRows = (rowsToFilter: Row<TData>[], depth = 0) => {
|
|
30
26
|
const rows: Row<TData>[] = []
|
|
31
27
|
|
|
32
28
|
// Filter from children up first
|
|
@@ -40,12 +36,12 @@ export function filterRowModelFromLeafs<TData extends RowData>(
|
|
|
40
36
|
row.index,
|
|
41
37
|
row.depth,
|
|
42
38
|
undefined,
|
|
43
|
-
|
|
39
|
+
row.parentId
|
|
44
40
|
)
|
|
45
41
|
newRow.columnFilters = row.columnFilters
|
|
46
42
|
|
|
47
43
|
if (row.subRows?.length && depth < maxDepth) {
|
|
48
|
-
newRow.subRows = recurseFilterRows(row.subRows, depth + 1
|
|
44
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
49
45
|
row = newRow
|
|
50
46
|
|
|
51
47
|
if (filterRow(row) && !newRow.subRows.length) {
|
|
@@ -91,11 +87,7 @@ export function filterRowModelFromRoot<TData extends RowData>(
|
|
|
91
87
|
const maxDepth = table.options.maxLeafRowFilterDepth ?? 100
|
|
92
88
|
|
|
93
89
|
// Filters top level and nested rows
|
|
94
|
-
const recurseFilterRows = (
|
|
95
|
-
rowsToFilter: Row<TData>[],
|
|
96
|
-
depth = 0,
|
|
97
|
-
parentRow?: Row<TData>
|
|
98
|
-
) => {
|
|
90
|
+
const recurseFilterRows = (rowsToFilter: Row<TData>[], depth = 0) => {
|
|
99
91
|
// Filter from parents downward first
|
|
100
92
|
|
|
101
93
|
const rows: Row<TData>[] = []
|
|
@@ -115,9 +107,9 @@ export function filterRowModelFromRoot<TData extends RowData>(
|
|
|
115
107
|
row.index,
|
|
116
108
|
row.depth,
|
|
117
109
|
undefined,
|
|
118
|
-
|
|
110
|
+
row.parentId
|
|
119
111
|
)
|
|
120
|
-
newRow.subRows = recurseFilterRows(row.subRows, depth + 1
|
|
112
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
121
113
|
row = newRow
|
|
122
114
|
}
|
|
123
115
|
|
|
@@ -29,7 +29,6 @@ export function getGroupedRowModel<TData extends RowData>(): (
|
|
|
29
29
|
const groupUpRecursively = (
|
|
30
30
|
rows: Row<TData>[],
|
|
31
31
|
depth = 0,
|
|
32
|
-
parentRow?: Row<TData>,
|
|
33
32
|
parentId?: string
|
|
34
33
|
) => {
|
|
35
34
|
// Grouping depth has been been met
|
|
@@ -42,7 +41,7 @@ export function getGroupedRowModel<TData extends RowData>(): (
|
|
|
42
41
|
groupedRowsById[row.id] = row
|
|
43
42
|
|
|
44
43
|
if (row.subRows) {
|
|
45
|
-
row.subRows = groupUpRecursively(row.subRows, depth + 1, row)
|
|
44
|
+
row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id)
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
return row
|
|
@@ -61,12 +60,7 @@ export function getGroupedRowModel<TData extends RowData>(): (
|
|
|
61
60
|
id = parentId ? `${parentId}>${id}` : id
|
|
62
61
|
|
|
63
62
|
// First, Recurse to group sub rows before aggregation
|
|
64
|
-
const subRows = groupUpRecursively(
|
|
65
|
-
groupedRows,
|
|
66
|
-
depth + 1,
|
|
67
|
-
parentRow,
|
|
68
|
-
id
|
|
69
|
-
)
|
|
63
|
+
const subRows = groupUpRecursively(groupedRows, depth + 1, id)
|
|
70
64
|
|
|
71
65
|
// Flatten the leaf rows of the rows in this group
|
|
72
66
|
const leafRows = depth
|
|
@@ -80,7 +74,7 @@ export function getGroupedRowModel<TData extends RowData>(): (
|
|
|
80
74
|
index,
|
|
81
75
|
depth,
|
|
82
76
|
undefined,
|
|
83
|
-
|
|
77
|
+
parentId
|
|
84
78
|
)
|
|
85
79
|
|
|
86
80
|
Object.assign(row, {
|
|
@@ -142,7 +136,7 @@ export function getGroupedRowModel<TData extends RowData>(): (
|
|
|
142
136
|
return aggregatedGroupedRows
|
|
143
137
|
}
|
|
144
138
|
|
|
145
|
-
const groupedRows = groupUpRecursively(rowModel.rows, 0
|
|
139
|
+
const groupedRows = groupUpRecursively(rowModel.rows, 0)
|
|
146
140
|
|
|
147
141
|
groupedRows.forEach(subRow => {
|
|
148
142
|
groupedFlatRows.push(subRow)
|