@tanstack/table-core 8.0.0-alpha.22 → 8.0.0-alpha.23
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/aggregationTypes.js +21 -19
- package/build/cjs/aggregationTypes.js.map +1 -1
- package/build/cjs/core.js +8 -8
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/features/Expanding.js +1 -8
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +1 -1
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/RowSelection.js +3 -3
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/utils/columnFilterRowsFn.js +20 -78
- package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +100 -0
- package/build/cjs/utils/filterRowsUtils.js.map +1 -0
- package/build/cjs/utils/globalFilterRowsFn.js +10 -62
- package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
- package/build/cjs/utils/groupRowsFn.js +15 -15
- package/build/cjs/utils/groupRowsFn.js.map +1 -1
- package/build/cjs/utils/sortRowsFn.js +1 -1
- package/build/cjs/utils/sortRowsFn.js.map +1 -1
- package/build/esm/index.js +156 -192
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +301 -268
- package/build/types/aggregationTypes.d.ts +9 -9
- package/build/types/core.d.ts +1 -1
- package/build/types/features/Filters.d.ts +1 -1
- package/build/types/features/Grouping.d.ts +1 -1
- package/build/types/utils/filterRowsUtils.d.ts +3 -0
- package/build/types/utils/sortRowsQuicksortFn.d.ts +11 -0
- package/build/umd/index.development.js +156 -192
- 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/aggregationTypes.ts +23 -19
- package/src/core.tsx +3 -5
- package/src/features/Expanding.ts +2 -10
- package/src/features/Filters.ts +2 -2
- package/src/features/Grouping.ts +2 -2
- package/src/features/RowSelection.ts +1 -3
- package/src/utils/columnFilterRowsFn.ts +12 -73
- package/src/utils/filterRowsUtils.ts +107 -0
- package/src/utils/globalFilterRowsFn.ts +10 -66
- package/src/utils/groupRowsFn.ts +14 -16
- package/src/utils/sortRowsFn.ts +6 -8
- package/src/utils/sortRowsQuicksortFn.ts +174 -0
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.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.23",
|
|
5
5
|
"description": "Hooks for building lightweight, fast and extendable datagrids for React",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/react-table#readme",
|
package/src/aggregationTypes.ts
CHANGED
|
@@ -12,19 +12,19 @@ export const aggregationTypes = {
|
|
|
12
12
|
|
|
13
13
|
export type BuiltInAggregationType = keyof typeof aggregationTypes
|
|
14
14
|
|
|
15
|
-
function sum(
|
|
15
|
+
function sum(_getLeafValues: () => unknown[], getChildValues: () => unknown[]) {
|
|
16
16
|
// It's faster to just add the aggregations together instead of
|
|
17
17
|
// process leaf nodes individually
|
|
18
|
-
return
|
|
18
|
+
return getChildValues().reduce(
|
|
19
19
|
(sum: number, next: unknown) => sum + (typeof next === 'number' ? next : 0),
|
|
20
20
|
0
|
|
21
21
|
)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function min(
|
|
24
|
+
function min(_getLeafValues: () => unknown[], getChildValues: () => unknown[]) {
|
|
25
25
|
let min: number | undefined
|
|
26
26
|
|
|
27
|
-
for (const value of
|
|
27
|
+
for (const value of getChildValues() as number[]) {
|
|
28
28
|
if (
|
|
29
29
|
value != null &&
|
|
30
30
|
(min! > value || (min === undefined && value >= value))
|
|
@@ -36,10 +36,10 @@ function min(_leafValues: unknown[], childValues: unknown[]) {
|
|
|
36
36
|
return min
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function max(
|
|
39
|
+
function max(_getLeafValues: () => unknown[], getChildValues: () => unknown[]) {
|
|
40
40
|
let max: number | undefined
|
|
41
41
|
|
|
42
|
-
for (const value of
|
|
42
|
+
for (const value of getChildValues() as number[]) {
|
|
43
43
|
if (
|
|
44
44
|
value != null &&
|
|
45
45
|
(max! < value || (max === undefined && value >= value))
|
|
@@ -51,11 +51,14 @@ function max(_leafValues: unknown[], childValues: unknown[]) {
|
|
|
51
51
|
return max
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function extent(
|
|
54
|
+
function extent(
|
|
55
|
+
_getLeafValues: () => unknown[],
|
|
56
|
+
getChildValues: () => unknown[]
|
|
57
|
+
) {
|
|
55
58
|
let min: number | undefined
|
|
56
59
|
let max: number | undefined
|
|
57
60
|
|
|
58
|
-
for (const value of
|
|
61
|
+
for (const value of getChildValues() as number[]) {
|
|
59
62
|
if (value != null) {
|
|
60
63
|
if (min === undefined) {
|
|
61
64
|
if (value >= value) min = max = value
|
|
@@ -69,11 +72,11 @@ function extent(_leafValues: unknown[], childValues: unknown[]) {
|
|
|
69
72
|
return [min, max]
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
function mean(
|
|
75
|
+
function mean(getLeafValues: () => unknown[]) {
|
|
73
76
|
let count = 0
|
|
74
77
|
let sum = 0
|
|
75
78
|
|
|
76
|
-
for (let value of
|
|
79
|
+
for (let value of getLeafValues() as number[]) {
|
|
77
80
|
if (value != null && (value = +value) >= value) {
|
|
78
81
|
++count, (sum += value)
|
|
79
82
|
}
|
|
@@ -84,15 +87,16 @@ function mean(leafValues: unknown[]) {
|
|
|
84
87
|
return
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
function median(
|
|
88
|
-
|
|
90
|
+
function median(getLeafValues: () => unknown[]) {
|
|
91
|
+
const leafValues = getLeafValues()
|
|
92
|
+
if (!leafValues.length) {
|
|
89
93
|
return
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
let min = 0
|
|
93
97
|
let max = 0
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
leafValues.forEach(value => {
|
|
96
100
|
if (typeof value === 'number') {
|
|
97
101
|
min = Math.min(min, value)
|
|
98
102
|
max = Math.max(max, value)
|
|
@@ -102,14 +106,14 @@ function median(values: unknown[]) {
|
|
|
102
106
|
return (min + max) / 2
|
|
103
107
|
}
|
|
104
108
|
|
|
105
|
-
function unique<T>(
|
|
106
|
-
return Array.from(new Set(
|
|
109
|
+
function unique<T>(getLeafValues: () => T[]) {
|
|
110
|
+
return Array.from(new Set(getLeafValues()).values())
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
function uniqueCount(
|
|
110
|
-
return new Set(
|
|
113
|
+
function uniqueCount(getLeafValues: () => unknown[]) {
|
|
114
|
+
return new Set(getLeafValues()).size
|
|
111
115
|
}
|
|
112
116
|
|
|
113
|
-
function count(
|
|
114
|
-
return
|
|
117
|
+
function count(getLeafValues: () => unknown[]) {
|
|
118
|
+
return getLeafValues().length
|
|
115
119
|
}
|
package/src/core.tsx
CHANGED
|
@@ -153,8 +153,8 @@ export type CoreRow<TGenerics extends PartialGenerics> = {
|
|
|
153
153
|
original?: TGenerics['Row']
|
|
154
154
|
depth: number
|
|
155
155
|
values: RowValues
|
|
156
|
-
leafRows: Row<TGenerics>[]
|
|
157
156
|
subRows: Row<TGenerics>[]
|
|
157
|
+
getLeafRows: () => Row<TGenerics>[]
|
|
158
158
|
getRowProps: PropGetter<RowProps>
|
|
159
159
|
originalSubRows?: TGenerics['Row'][]
|
|
160
160
|
getAllCells: () => Cell<TGenerics>[]
|
|
@@ -528,7 +528,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
528
528
|
depth,
|
|
529
529
|
values,
|
|
530
530
|
subRows: [],
|
|
531
|
-
|
|
531
|
+
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
532
532
|
getRowProps: userProps => instance.getRowProps(row.id, userProps)!,
|
|
533
533
|
getAllCells: undefined!,
|
|
534
534
|
getAllCellsByColumnId: undefined!,
|
|
@@ -650,9 +650,7 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
650
650
|
row
|
|
651
651
|
)
|
|
652
652
|
}
|
|
653
|
-
// Keep the new subRows array on the row
|
|
654
653
|
row.subRows = subRows
|
|
655
|
-
row.leafRows = flattenBy(subRows, d => d.leafRows)
|
|
656
654
|
}
|
|
657
655
|
}
|
|
658
656
|
}
|
|
@@ -667,8 +665,8 @@ export function createTableInstance<TGenerics extends PartialGenerics>(
|
|
|
667
665
|
key: 'getRowModel',
|
|
668
666
|
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
669
667
|
onChange: () => {
|
|
670
|
-
instance._notifyRowSelectionReset()
|
|
671
668
|
instance._notifyFiltersReset()
|
|
669
|
+
instance._notifyRowSelectionReset()
|
|
672
670
|
},
|
|
673
671
|
}
|
|
674
672
|
),
|
|
@@ -307,16 +307,8 @@ export const Expanding = {
|
|
|
307
307
|
void instance.toggleRowExpanded(row.id, expanded),
|
|
308
308
|
getIsExpanded: () => instance.getIsRowExpanded(row.id),
|
|
309
309
|
getCanExpand: () => row.subRows && !!row.subRows.length,
|
|
310
|
-
getToggleExpandedProps: userProps =>
|
|
311
|
-
|
|
312
|
-
title: 'Toggle Row Expanded',
|
|
313
|
-
onClick: (e: MouseEvent | TouchEvent) => {
|
|
314
|
-
e.stopPropagation()
|
|
315
|
-
instance.toggleRowExpanded(row.id)
|
|
316
|
-
},
|
|
317
|
-
}
|
|
318
|
-
return propGetter(initialProps, userProps)
|
|
319
|
-
},
|
|
310
|
+
getToggleExpandedProps: userProps =>
|
|
311
|
+
instance.getToggleExpandedProps(row.id, userProps),
|
|
320
312
|
}
|
|
321
313
|
},
|
|
322
314
|
}
|
package/src/features/Filters.ts
CHANGED
|
@@ -74,7 +74,7 @@ export type FiltersColumn<TGenerics extends PartialGenerics> = {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
export type FiltersOptions<TGenerics extends PartialGenerics> = {
|
|
77
|
-
|
|
77
|
+
filterFromLeafRows?: boolean
|
|
78
78
|
filterTypes?: TGenerics['FilterFns']
|
|
79
79
|
enableFilters?: boolean
|
|
80
80
|
// Column
|
|
@@ -156,7 +156,7 @@ export const Filters = {
|
|
|
156
156
|
onColumnFiltersChange: makeStateUpdater('columnFilters', instance),
|
|
157
157
|
onGlobalFilterChange: makeStateUpdater('globalFilter', instance),
|
|
158
158
|
autoResetColumnFilters: true,
|
|
159
|
-
|
|
159
|
+
filterFromLeafRows: true,
|
|
160
160
|
autoResetGlobalFilter: true,
|
|
161
161
|
globalFilterType: 'auto',
|
|
162
162
|
getColumnCanGlobalFilterFn: column => {
|
package/src/features/Grouping.ts
CHANGED
|
@@ -26,8 +26,8 @@ import {
|
|
|
26
26
|
export type GroupingState = string[]
|
|
27
27
|
|
|
28
28
|
export type AggregationFn<TGenerics extends PartialGenerics> = (
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
getLeafValues: () => TGenerics['Row'][],
|
|
30
|
+
getChildValues: () => TGenerics['Row'][]
|
|
31
31
|
) => any
|
|
32
32
|
|
|
33
33
|
export type CustomAggregationTypes<TGenerics extends PartialGenerics> = Record<
|
|
@@ -160,9 +160,7 @@ export const RowSelection = {
|
|
|
160
160
|
? value
|
|
161
161
|
: !instance.getIsAllRowsSelected()
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
// Leave all the other rows that are selected alone.
|
|
165
|
-
const rowSelection = Object.assign({}, old)
|
|
163
|
+
const rowSelection = { ...old }
|
|
166
164
|
|
|
167
165
|
const preGroupedFlatRows = instance.getPreGroupedRowModel().flatRows
|
|
168
166
|
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
+
import { AnyGenerics, TableInstance, Row, RowModel } from '../types'
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
RowModel,
|
|
6
|
-
PartialGenerics,
|
|
7
|
-
} from '../types'
|
|
3
|
+
filterRowModelFromLeafs,
|
|
4
|
+
filterRowModelFromRoot,
|
|
5
|
+
} from './filterRowsUtils'
|
|
8
6
|
|
|
9
7
|
export function columnFilterRowsFn<TGenerics extends AnyGenerics>(
|
|
10
8
|
instance: TableInstance<TGenerics>,
|
|
11
9
|
rowModel: RowModel<TGenerics>
|
|
12
10
|
): RowModel<TGenerics> {
|
|
13
11
|
const columnFilters = instance.getState().columnFilters
|
|
14
|
-
|
|
15
|
-
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
16
|
-
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
17
|
-
|
|
18
|
-
const filterFromChildrenUp = instance.options.filterFromChildrenUp
|
|
12
|
+
const filterFromLeafRows = instance.options.filterFromLeafRows
|
|
19
13
|
|
|
20
14
|
const filterRows = (rowsToFilter: Row<TGenerics>[], depth: number) => {
|
|
21
|
-
|
|
15
|
+
for (let i = 0; i < columnFilters.length; i++) {
|
|
16
|
+
const { id: columnId, value: filterValue } = columnFilters[i]
|
|
22
17
|
// Find the columnFilters column
|
|
23
18
|
const column = instance.getColumn(columnId)
|
|
24
19
|
|
|
@@ -42,76 +37,20 @@ export function columnFilterRowsFn<TGenerics extends AnyGenerics>(
|
|
|
42
37
|
`Could not find a valid 'column.filterType' for column with the ID: ${column.id}.`
|
|
43
38
|
)
|
|
44
39
|
}
|
|
45
|
-
|
|
40
|
+
continue
|
|
46
41
|
}
|
|
47
42
|
|
|
48
43
|
// Pass the rows, id, filterValue and column to the filterFn
|
|
49
44
|
// to get the filtered rows back
|
|
50
45
|
rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
return rowsToFilter
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (filterFromChildrenUp) {
|
|
57
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
58
|
-
// Filter from children up
|
|
59
|
-
rowsToFilter = rowsToFilter.filter(row => {
|
|
60
|
-
if (!row.subRows?.length) {
|
|
61
|
-
return true
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
65
|
-
|
|
66
|
-
return row.subRows.length
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
rowsToFilter = filterRows(rowsToFilter, depth)
|
|
70
|
-
|
|
71
|
-
// Apply the filter to any subRows
|
|
72
|
-
rowsToFilter.forEach(row => {
|
|
73
|
-
newFilteredFlatRows.push(row)
|
|
74
|
-
newFilteredRowsById[row.id] = row
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
return rowsToFilter
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
82
|
-
flatRows: newFilteredFlatRows,
|
|
83
|
-
rowsById: newFilteredRowsById,
|
|
84
46
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Filters top level and nested rows
|
|
88
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
89
|
-
// Filter from parents downward
|
|
90
|
-
rowsToFilter = filterRows(rowsToFilter, depth)
|
|
91
|
-
|
|
92
|
-
// Apply the filter to any subRows
|
|
93
|
-
// We technically could do this recursively in the above loop,
|
|
94
|
-
// but that would severely hinder the API for the user, since they
|
|
95
|
-
// would be required to do that recursion in some scenarios
|
|
96
|
-
rowsToFilter.forEach(row => {
|
|
97
|
-
newFilteredFlatRows.push(row)
|
|
98
|
-
newFilteredRowsById[row.id] = row
|
|
99
|
-
|
|
100
|
-
if (!filterFromChildrenUp) {
|
|
101
|
-
if (!row.subRows?.length) {
|
|
102
|
-
return
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
47
|
|
|
109
48
|
return rowsToFilter
|
|
110
49
|
}
|
|
111
50
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
flatRows: newFilteredFlatRows,
|
|
115
|
-
rowsById: newFilteredRowsById,
|
|
51
|
+
if (filterFromLeafRows) {
|
|
52
|
+
return filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
|
|
116
53
|
}
|
|
54
|
+
|
|
55
|
+
return filterRowModelFromRoot(rowModel.rows, filterRows, instance)
|
|
117
56
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { AnyGenerics, Row, RowModel, TableInstance } from '../types'
|
|
2
|
+
|
|
3
|
+
export function filterRowModelFromLeafs<TGenerics extends AnyGenerics>(
|
|
4
|
+
rowsToFilter: Row<TGenerics>[],
|
|
5
|
+
filterRows: (
|
|
6
|
+
rowsToFilter: Row<TGenerics>[],
|
|
7
|
+
depth: number
|
|
8
|
+
) => Row<TGenerics>[],
|
|
9
|
+
instance: TableInstance<TGenerics>
|
|
10
|
+
): RowModel<TGenerics> {
|
|
11
|
+
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
12
|
+
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
13
|
+
|
|
14
|
+
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
15
|
+
rowsToFilter = rowsToFilter.slice()
|
|
16
|
+
|
|
17
|
+
// Filter from children up first
|
|
18
|
+
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
19
|
+
const row = rowsToFilter[i]
|
|
20
|
+
|
|
21
|
+
if (!row.subRows?.length) {
|
|
22
|
+
continue
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
rowsToFilter[i] = instance.createRow(
|
|
26
|
+
row.id,
|
|
27
|
+
row.original,
|
|
28
|
+
row.index,
|
|
29
|
+
row.depth,
|
|
30
|
+
row.values
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
rowsToFilter[i].subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
34
|
+
|
|
35
|
+
if (!rowsToFilter[i].subRows.length) {
|
|
36
|
+
rowsToFilter.splice(i, 1)
|
|
37
|
+
i--
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
rowsToFilter = filterRows(rowsToFilter, depth)
|
|
42
|
+
|
|
43
|
+
// Apply the filter to any subRows
|
|
44
|
+
rowsToFilter.forEach(row => {
|
|
45
|
+
newFilteredFlatRows.push(row)
|
|
46
|
+
newFilteredRowsById[row.id] = row
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return rowsToFilter
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
rows: recurseFilterRows(rowsToFilter),
|
|
54
|
+
flatRows: newFilteredFlatRows,
|
|
55
|
+
rowsById: newFilteredRowsById,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function filterRowModelFromRoot<TGenerics extends AnyGenerics>(
|
|
60
|
+
rowsToFilter: Row<TGenerics>[],
|
|
61
|
+
filterRows: (
|
|
62
|
+
rowsToFilter: Row<TGenerics>[],
|
|
63
|
+
depth: number
|
|
64
|
+
) => Row<TGenerics>[],
|
|
65
|
+
instance: TableInstance<TGenerics>
|
|
66
|
+
): RowModel<TGenerics> {
|
|
67
|
+
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
68
|
+
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
69
|
+
|
|
70
|
+
// Filters top level and nested rows
|
|
71
|
+
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
72
|
+
// Filter from parents downward first
|
|
73
|
+
rowsToFilter = filterRows(rowsToFilter, depth)
|
|
74
|
+
|
|
75
|
+
// Apply the filter to any subRows
|
|
76
|
+
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
77
|
+
const row = rowsToFilter[i]
|
|
78
|
+
|
|
79
|
+
newFilteredFlatRows.push(row)
|
|
80
|
+
newFilteredRowsById[row.id] = row
|
|
81
|
+
|
|
82
|
+
if (!row.subRows?.length) {
|
|
83
|
+
rowsToFilter.splice(i, 1)
|
|
84
|
+
i--
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
rowsToFilter[i] = instance.createRow(
|
|
89
|
+
row.id,
|
|
90
|
+
row.original,
|
|
91
|
+
row.index,
|
|
92
|
+
row.depth,
|
|
93
|
+
row.values
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
rowsToFilter[i].subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return rowsToFilter
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
rows: recurseFilterRows(rowsToFilter),
|
|
104
|
+
flatRows: newFilteredFlatRows,
|
|
105
|
+
rowsById: newFilteredRowsById,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
+
import { TableInstance, Row, RowModel, AnyGenerics } from '../types'
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
AnyGenerics,
|
|
6
|
-
PartialGenerics,
|
|
7
|
-
} from '../types'
|
|
3
|
+
filterRowModelFromLeafs,
|
|
4
|
+
filterRowModelFromRoot,
|
|
5
|
+
} from './filterRowsUtils'
|
|
8
6
|
|
|
9
7
|
export function globalFilterRowsFn<TGenerics extends AnyGenerics>(
|
|
10
8
|
instance: TableInstance<TGenerics>,
|
|
11
9
|
rowModel: RowModel<TGenerics>
|
|
12
10
|
): RowModel<TGenerics> {
|
|
13
11
|
const globalFilter = instance.getState().globalFilter
|
|
14
|
-
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
15
|
-
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
16
12
|
|
|
17
|
-
const
|
|
13
|
+
const filterFromLeafRows = instance.options.filterFromLeafRows
|
|
18
14
|
|
|
19
15
|
const filterFn = instance.getGlobalFilterFn()
|
|
20
16
|
|
|
@@ -31,65 +27,13 @@ export function globalFilterRowsFn<TGenerics extends AnyGenerics>(
|
|
|
31
27
|
|
|
32
28
|
const filterableColumnIds = filterableColumns.map(d => d.id)
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// Filter from children up
|
|
37
|
-
rowsToFilter = rowsToFilter.filter(row => {
|
|
38
|
-
if (!row.subRows?.length) {
|
|
39
|
-
return true
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
43
|
-
|
|
44
|
-
return row.subRows.length
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter)
|
|
48
|
-
|
|
49
|
-
// Apply the filter to any subRows
|
|
50
|
-
rowsToFilter.forEach(row => {
|
|
51
|
-
newFilteredFlatRows.push(row)
|
|
52
|
-
newFilteredRowsById[row.id] = row
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
return rowsToFilter
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
60
|
-
flatRows: newFilteredFlatRows,
|
|
61
|
-
rowsById: newFilteredRowsById,
|
|
62
|
-
}
|
|
30
|
+
const filterRows = (rows: Row<TGenerics>[]) => {
|
|
31
|
+
return filterFn(rows, filterableColumnIds, globalFilter)
|
|
63
32
|
}
|
|
64
33
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Filter from parents downward
|
|
68
|
-
rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter)
|
|
69
|
-
|
|
70
|
-
// Apply the filter to any subRows
|
|
71
|
-
// We technically could do this recursively in the above loop,
|
|
72
|
-
// but that would severely hinder the API for the user, since they
|
|
73
|
-
// would be required to do that recursion in some scenarios
|
|
74
|
-
rowsToFilter.forEach(row => {
|
|
75
|
-
newFilteredFlatRows.push(row)
|
|
76
|
-
newFilteredRowsById[row.id] = row
|
|
77
|
-
|
|
78
|
-
if (!filterFromChildrenUp) {
|
|
79
|
-
if (!row.subRows?.length) {
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
return rowsToFilter
|
|
34
|
+
if (filterFromLeafRows) {
|
|
35
|
+
filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
|
|
88
36
|
}
|
|
89
37
|
|
|
90
|
-
return
|
|
91
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
92
|
-
flatRows: newFilteredFlatRows,
|
|
93
|
-
rowsById: newFilteredRowsById,
|
|
94
|
-
}
|
|
38
|
+
return filterRowModelFromRoot(rowModel.rows, filterRows, instance)
|
|
95
39
|
}
|
package/src/utils/groupRowsFn.ts
CHANGED
|
@@ -39,21 +39,19 @@ export function groupRowsFn<TGenerics extends AnyGenerics>(
|
|
|
39
39
|
const aggregateFn = instance.getColumnAggregationFn(column.id)
|
|
40
40
|
|
|
41
41
|
if (aggregateFn) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
values[column.id] = aggregateFn(leafValues, groupedValues)
|
|
42
|
+
values[column.id] = aggregateFn(
|
|
43
|
+
() =>
|
|
44
|
+
leafRows.map(row => {
|
|
45
|
+
let columnValue = row.values[column.id]
|
|
46
|
+
|
|
47
|
+
if (!depth && column.aggregateValue) {
|
|
48
|
+
columnValue = column.aggregateValue(columnValue)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return columnValue
|
|
52
|
+
}),
|
|
53
|
+
() => groupedRows.map(row => row.values[column.id])
|
|
54
|
+
)
|
|
57
55
|
} else if (column.aggregationType) {
|
|
58
56
|
console.info({ column })
|
|
59
57
|
throw new Error(
|
|
@@ -103,7 +101,7 @@ export function groupRowsFn<TGenerics extends AnyGenerics>(
|
|
|
103
101
|
|
|
104
102
|
// Flatten the leaf rows of the rows in this group
|
|
105
103
|
const leafRows = depth
|
|
106
|
-
? flattenBy(groupedRows, row => row.
|
|
104
|
+
? flattenBy(groupedRows, row => row.subRows)
|
|
107
105
|
: groupedRows
|
|
108
106
|
|
|
109
107
|
const values = aggregateRowsToValues(leafRows, groupedRows, depth)
|
package/src/utils/sortRowsFn.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TableInstance,
|
|
3
|
-
Row,
|
|
4
|
-
RowModel,
|
|
5
|
-
AnyGenerics,
|
|
6
|
-
PartialGenerics,
|
|
7
|
-
} from '../types'
|
|
1
|
+
import { TableInstance, Row, RowModel, AnyGenerics } from '../types'
|
|
8
2
|
import { SortingFn } from '../features/Sorting'
|
|
9
3
|
|
|
10
4
|
export function sortRowsFn<TGenerics extends AnyGenerics>(
|
|
@@ -58,7 +52,11 @@ export function sortRowsFn<TGenerics extends AnyGenerics>(
|
|
|
58
52
|
const bUndefined = typeof bValue === 'undefined'
|
|
59
53
|
|
|
60
54
|
if (aUndefined || bUndefined) {
|
|
61
|
-
return aUndefined && bUndefined
|
|
55
|
+
return aUndefined && bUndefined
|
|
56
|
+
? 0
|
|
57
|
+
: aUndefined
|
|
58
|
+
? columnInfo.sortUndefined
|
|
59
|
+
: -columnInfo.sortUndefined
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
|