@tanstack/table-core 8.0.0-alpha.67 → 8.0.0-alpha.68
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/aggregationFns.js +25 -37
- package/build/cjs/aggregationFns.js.map +1 -1
- package/build/cjs/core.js +167 -46
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +24 -40
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +28 -34
- package/build/cjs/features/Cells.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +90 -107
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +52 -79
- package/build/cjs/features/Columns.js.map +1 -1
- package/build/cjs/features/Expanding.js +48 -57
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +96 -191
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +52 -70
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +109 -165
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +30 -42
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +63 -71
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +65 -121
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +92 -111
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +32 -22
- package/build/cjs/features/Rows.js.map +1 -1
- package/build/cjs/features/Sorting.js +49 -68
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +43 -87
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +48 -72
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/index.js +13 -13
- package/build/cjs/sortingFns.js +21 -21
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +49 -55
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +98 -0
- package/build/cjs/utils/getCoreRowModel.js.map +1 -0
- package/build/cjs/utils/getExpandedRowModel.js +17 -21
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +48 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
- package/build/cjs/utils/getFacetedRowModel.js +50 -0
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
- package/build/cjs/utils/getFilteredRowModel.js +130 -0
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +126 -136
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +39 -39
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +112 -0
- package/build/cjs/utils/getSortedRowModel.js.map +1 -0
- package/build/cjs/utils.js +36 -207
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +1729 -2313
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +421 -481
- package/build/types/core.d.ts +3 -5
- package/build/types/features/Cells.d.ts +1 -1
- package/build/types/features/Columns.d.ts +1 -1
- package/build/types/features/Filters.d.ts +10 -5
- package/build/types/features/Grouping.d.ts +4 -3
- package/build/types/features/Rows.d.ts +4 -3
- package/build/types/index.d.ts +6 -4
- package/build/types/types.d.ts +3 -13
- package/build/types/utils/filterRowsUtils.d.ts +3 -3
- package/build/types/utils/getCoreRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
- package/build/types/utils/getFacetedRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
- package/build/types/utils/{getCoreRowModelSync.d.ts → getFilteredRowModel.d.ts} +1 -1
- package/build/types/utils/getGroupedRowModel.d.ts +1 -1
- package/build/types/utils/getSortedRowModel.d.ts +2 -0
- package/build/types/utils.d.ts +1 -17
- package/build/umd/index.development.js +1730 -2316
- 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.ts +197 -45
- package/src/features/Cells.ts +7 -11
- package/src/features/ColumnSizing.ts +6 -5
- package/src/features/Columns.ts +4 -8
- package/src/features/Filters.ts +95 -156
- package/src/features/Grouping.ts +16 -20
- package/src/features/Rows.ts +21 -6
- package/src/features/Sorting.ts +2 -2
- package/src/filterFns.ts +9 -9
- package/src/index.ts +12 -4
- package/src/sortingFns.ts +11 -11
- package/src/types.ts +3 -16
- package/src/utils/filterRowsUtils.ts +47 -68
- package/src/utils/{getCoreRowModelSync.ts → getCoreRowModel.ts} +2 -8
- package/src/utils/getFacetedMinMaxValues.ts +37 -0
- package/src/utils/getFacetedRowModel.ts +50 -0
- package/src/utils/getFacetedUniqueValues.ts +37 -0
- package/src/utils/{getFilteredRowModelSync.ts → getFilteredRowModel.ts} +29 -20
- package/src/utils/getGroupedRowModel.ts +52 -61
- package/src/utils/{getSortedRowModelSync.ts → getSortedRowModel.ts} +3 -3
- package/src/utils.ts +28 -236
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/utils/getCoreRowModelAsync.js +0 -125
- package/build/cjs/utils/getCoreRowModelAsync.js.map +0 -1
- package/build/cjs/utils/getCoreRowModelSync.js +0 -102
- package/build/cjs/utils/getCoreRowModelSync.js.map +0 -1
- package/build/cjs/utils/getFilteredRowModelSync.js +0 -125
- package/build/cjs/utils/getFilteredRowModelSync.js.map +0 -1
- package/build/cjs/utils/getSortedRowModelSync.js +0 -118
- package/build/cjs/utils/getSortedRowModelSync.js.map +0 -1
- package/build/types/utils/getCoreRowModelAsync.d.ts +0 -4
- package/build/types/utils/getFilteredRowModelAsync.d.ts +0 -4
- package/build/types/utils/getFilteredRowModelSync.d.ts +0 -2
- package/build/types/utils/getSortedRowModelAsync.d.ts +0 -13
- package/build/types/utils/getSortedRowModelSync.d.ts +0 -2
- package/src/utils/getCoreRowModelAsync.ts +0 -104
- package/src/utils/getFilteredRowModelAsync.ts +0 -157
- package/src/utils/getSortedRowModelAsync.ts +0 -200
package/src/sortingFns.ts
CHANGED
|
@@ -19,8 +19,8 @@ function alphanumeric<TGenerics extends TableGenerics>(
|
|
|
19
19
|
columnId: string
|
|
20
20
|
) {
|
|
21
21
|
return compareAlphanumeric(
|
|
22
|
-
toString(rowA.
|
|
23
|
-
toString(rowB.
|
|
22
|
+
toString(rowA.getValue(columnId)).toLowerCase(),
|
|
23
|
+
toString(rowB.getValue(columnId)).toLowerCase()
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -30,8 +30,8 @@ function alphanumericCaseSensitive<TGenerics extends TableGenerics>(
|
|
|
30
30
|
columnId: string
|
|
31
31
|
) {
|
|
32
32
|
return compareAlphanumeric(
|
|
33
|
-
toString(rowA.
|
|
34
|
-
toString(rowB.
|
|
33
|
+
toString(rowA.getValue(columnId)),
|
|
34
|
+
toString(rowB.getValue(columnId))
|
|
35
35
|
)
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -90,8 +90,8 @@ function text<TGenerics extends TableGenerics>(
|
|
|
90
90
|
columnId: string
|
|
91
91
|
) {
|
|
92
92
|
return compareBasic(
|
|
93
|
-
toString(rowA.
|
|
94
|
-
toString(rowB.
|
|
93
|
+
toString(rowA.getValue(columnId)).toLowerCase(),
|
|
94
|
+
toString(rowB.getValue(columnId)).toLowerCase()
|
|
95
95
|
)
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -103,8 +103,8 @@ function textCaseSensitive<TGenerics extends TableGenerics>(
|
|
|
103
103
|
columnId: string
|
|
104
104
|
) {
|
|
105
105
|
return compareBasic(
|
|
106
|
-
toString(rowA.
|
|
107
|
-
toString(rowB.
|
|
106
|
+
toString(rowA.getValue(columnId)),
|
|
107
|
+
toString(rowB.getValue(columnId))
|
|
108
108
|
)
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -114,8 +114,8 @@ function datetime<TGenerics extends TableGenerics>(
|
|
|
114
114
|
columnId: string
|
|
115
115
|
) {
|
|
116
116
|
return compareBasic(
|
|
117
|
-
(rowA.
|
|
118
|
-
(rowB.
|
|
117
|
+
(rowA.getValue(columnId) as Date).getTime(),
|
|
118
|
+
(rowB.getValue(columnId) as Date).getTime()
|
|
119
119
|
)
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -124,7 +124,7 @@ function basic<TGenerics extends TableGenerics>(
|
|
|
124
124
|
rowB: Row<TGenerics>,
|
|
125
125
|
columnId: string
|
|
126
126
|
) {
|
|
127
|
-
return compareBasic(rowA.
|
|
127
|
+
return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId))
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// Utils
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreOptions, CoreTableState,
|
|
1
|
+
import { CoreOptions, CoreTableState, CoreInstance } from './core'
|
|
2
2
|
import { ColumnsOptions, CoreColumn, CoreColumnDef } from './features/Columns'
|
|
3
3
|
import {
|
|
4
4
|
VisibilityInstance,
|
|
@@ -107,7 +107,7 @@ export type TableFeature = {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
export type TableInstance<TGenerics extends TableGenerics> =
|
|
110
|
-
|
|
110
|
+
CoreInstance<TGenerics> &
|
|
111
111
|
ColumnsInstance<TGenerics> &
|
|
112
112
|
RowsInstance<TGenerics> &
|
|
113
113
|
CellsInstance<TGenerics> &
|
|
@@ -214,7 +214,7 @@ export type CoreCell<TGenerics extends TableGenerics> = {
|
|
|
214
214
|
id: string
|
|
215
215
|
rowId: string
|
|
216
216
|
columnId: string
|
|
217
|
-
|
|
217
|
+
getValue: () => TGenerics['Value']
|
|
218
218
|
row: Row<TGenerics>
|
|
219
219
|
column: Column<TGenerics>
|
|
220
220
|
renderCell: () => string | null | TGenerics['Rendered']
|
|
@@ -249,17 +249,4 @@ export type HeaderGroup<TGenerics extends TableGenerics> = {
|
|
|
249
249
|
headers: Header<TGenerics>[]
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
export type HeaderRenderProps<THeader> = {
|
|
253
|
-
header: THeader
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export type FooterRenderProps<THeader> = {
|
|
257
|
-
header: THeader
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export type CellRenderProps<TCell, TRow> = {
|
|
261
|
-
cell: TCell
|
|
262
|
-
row: TRow
|
|
263
|
-
}
|
|
264
|
-
|
|
265
252
|
export type NoInfer<A extends any> = [A][A extends any ? 0 : never]
|
|
@@ -2,21 +2,9 @@ import { TableGenerics, Row, RowModel, TableInstance } from '../types'
|
|
|
2
2
|
|
|
3
3
|
export function filterRows<TGenerics extends TableGenerics>(
|
|
4
4
|
rows: Row<TGenerics>[],
|
|
5
|
-
|
|
5
|
+
filterRowImpl: (row: Row<TGenerics>) => any,
|
|
6
6
|
instance: TableInstance<TGenerics>
|
|
7
7
|
) {
|
|
8
|
-
const filterRowImpl = (rowsToFilter: Row<TGenerics>[]) => {
|
|
9
|
-
// Horizontally filter rows through each column
|
|
10
|
-
return rowsToFilter.filter(row => {
|
|
11
|
-
for (let i = 0; i < columnIds.length; i++) {
|
|
12
|
-
if (row.columnFilterMap[columnIds[i]] === false) {
|
|
13
|
-
return false
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return true
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
8
|
if (instance.options.filterFromLeafRows) {
|
|
21
9
|
return filterRowModelFromLeafs(rows, filterRowImpl, instance)
|
|
22
10
|
}
|
|
@@ -26,51 +14,40 @@ export function filterRows<TGenerics extends TableGenerics>(
|
|
|
26
14
|
|
|
27
15
|
export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
|
|
28
16
|
rowsToFilter: Row<TGenerics>[],
|
|
29
|
-
|
|
30
|
-
rowsToFilter: Row<TGenerics>[],
|
|
31
|
-
depth: number
|
|
32
|
-
) => Row<TGenerics>[],
|
|
17
|
+
filterRow: (row: Row<TGenerics>) => Row<TGenerics>[],
|
|
33
18
|
instance: TableInstance<TGenerics>
|
|
34
19
|
): RowModel<TGenerics> {
|
|
35
20
|
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
36
21
|
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
37
22
|
|
|
23
|
+
let row
|
|
24
|
+
let newRow
|
|
25
|
+
|
|
38
26
|
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
39
|
-
|
|
27
|
+
const rows: Row<TGenerics>[] = []
|
|
40
28
|
|
|
41
29
|
// Filter from children up first
|
|
42
30
|
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
31
|
+
row = rowsToFilter[i]!
|
|
32
|
+
|
|
33
|
+
if (row.subRows?.length) {
|
|
34
|
+
newRow = instance.createRow(row.id, row.original, row.index, row.depth)
|
|
35
|
+
newRow.columnFilterMap = row.columnFilterMap
|
|
36
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
37
|
+
if (!newRow.subRows.length) {
|
|
38
|
+
continue
|
|
39
|
+
}
|
|
40
|
+
row = newRow
|
|
47
41
|
}
|
|
48
42
|
|
|
49
|
-
|
|
50
|
-
row
|
|
51
|
-
row.
|
|
52
|
-
row
|
|
53
|
-
row.depth,
|
|
54
|
-
row.values
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
rowsToFilter[i].subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
58
|
-
|
|
59
|
-
if (!rowsToFilter[i].subRows.length) {
|
|
60
|
-
rowsToFilter.splice(i, 1)
|
|
61
|
-
i--
|
|
43
|
+
if (filterRow(row)) {
|
|
44
|
+
rows.push(row)
|
|
45
|
+
newFilteredRowsById[row.id] = row
|
|
46
|
+
newFilteredRowsById[i] = row
|
|
62
47
|
}
|
|
63
48
|
}
|
|
64
49
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Apply the filter to any subRows
|
|
68
|
-
rowsToFilter.forEach(row => {
|
|
69
|
-
newFilteredFlatRows.push(row)
|
|
70
|
-
newFilteredRowsById[row.id] = row
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return rowsToFilter
|
|
50
|
+
return rows
|
|
74
51
|
}
|
|
75
52
|
|
|
76
53
|
return {
|
|
@@ -82,45 +59,47 @@ export function filterRowModelFromLeafs<TGenerics extends TableGenerics>(
|
|
|
82
59
|
|
|
83
60
|
export function filterRowModelFromRoot<TGenerics extends TableGenerics>(
|
|
84
61
|
rowsToFilter: Row<TGenerics>[],
|
|
85
|
-
|
|
86
|
-
rowsToFilter: Row<TGenerics>[],
|
|
87
|
-
depth: number
|
|
88
|
-
) => Row<TGenerics>[],
|
|
62
|
+
filterRow: (row: Row<TGenerics>) => any,
|
|
89
63
|
instance: TableInstance<TGenerics>
|
|
90
64
|
): RowModel<TGenerics> {
|
|
91
65
|
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
92
66
|
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
93
67
|
|
|
68
|
+
let rows
|
|
69
|
+
let row
|
|
70
|
+
let newRow
|
|
71
|
+
|
|
94
72
|
// Filters top level and nested rows
|
|
95
73
|
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
96
74
|
// Filter from parents downward first
|
|
97
|
-
|
|
75
|
+
|
|
76
|
+
rows = []
|
|
98
77
|
|
|
99
78
|
// Apply the filter to any subRows
|
|
100
79
|
for (let i = 0; i < rowsToFilter.length; i++) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
80
|
+
row = rowsToFilter[i]!
|
|
81
|
+
|
|
82
|
+
const pass = filterRow(row)
|
|
83
|
+
|
|
84
|
+
if (pass) {
|
|
85
|
+
if (row.subRows?.length) {
|
|
86
|
+
newRow = instance.createRow(
|
|
87
|
+
row.id,
|
|
88
|
+
row.original,
|
|
89
|
+
row.index,
|
|
90
|
+
row.depth
|
|
91
|
+
)
|
|
92
|
+
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
93
|
+
row = newRow
|
|
94
|
+
}
|
|
105
95
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
continue
|
|
96
|
+
rows.push(row)
|
|
97
|
+
newFilteredFlatRows.push(row)
|
|
98
|
+
newFilteredRowsById[row.id] = row
|
|
110
99
|
}
|
|
111
|
-
|
|
112
|
-
rowsToFilter[i] = instance.createRow(
|
|
113
|
-
row.id,
|
|
114
|
-
row.original,
|
|
115
|
-
row.index,
|
|
116
|
-
row.depth,
|
|
117
|
-
row.values
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
rowsToFilter[i].subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
121
100
|
}
|
|
122
101
|
|
|
123
|
-
return
|
|
102
|
+
return rows
|
|
124
103
|
}
|
|
125
104
|
|
|
126
105
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TableInstance, Row, RowModel, TableGenerics } from '../types'
|
|
2
2
|
import { memo } from '../utils'
|
|
3
3
|
|
|
4
|
-
export function
|
|
4
|
+
export function getCoreRowModel<TGenerics extends TableGenerics>(): (
|
|
5
5
|
instance: TableInstance<TGenerics>
|
|
6
6
|
) => () => RowModel<TGenerics> {
|
|
7
7
|
return instance =>
|
|
@@ -46,13 +46,7 @@ export function getCoreRowModelSync<TGenerics extends TableGenerics>(): (
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// Make the row
|
|
49
|
-
const row = instance.createRow(
|
|
50
|
-
id,
|
|
51
|
-
originalRow,
|
|
52
|
-
rowIndex,
|
|
53
|
-
depth,
|
|
54
|
-
values
|
|
55
|
-
)
|
|
49
|
+
const row = instance.createRow(id, originalRow, rowIndex, depth)
|
|
56
50
|
|
|
57
51
|
// Push instance row into the parentRows array
|
|
58
52
|
parentRows.push(row)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TableInstance, TableGenerics } from '../types'
|
|
2
|
+
import { memo } from '../utils'
|
|
3
|
+
|
|
4
|
+
export function getFacetedMinMaxValues<TGenerics extends TableGenerics>(): (
|
|
5
|
+
instance: TableInstance<TGenerics>,
|
|
6
|
+
columnId: string
|
|
7
|
+
) => () => [number, number] {
|
|
8
|
+
return (instance, columnId) =>
|
|
9
|
+
memo(
|
|
10
|
+
() => [instance.getColumn(columnId).getFacetedRowModel()],
|
|
11
|
+
facetedRowModel => {
|
|
12
|
+
let facetedMinMaxValues: [any, any] = [
|
|
13
|
+
facetedRowModel.flatRows[0]?.getValue(columnId) ?? null,
|
|
14
|
+
facetedRowModel.flatRows[0]?.getValue(columnId) ?? null,
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
|
|
18
|
+
const value = facetedRowModel.flatRows[i]?.getValue(columnId)
|
|
19
|
+
|
|
20
|
+
if (value < facetedMinMaxValues[0]) {
|
|
21
|
+
facetedMinMaxValues[0] = value
|
|
22
|
+
} else if (value > facetedMinMaxValues[1]) {
|
|
23
|
+
facetedMinMaxValues[1] = value
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return facetedMinMaxValues
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key:
|
|
31
|
+
process.env.NODE_ENV === 'development' &&
|
|
32
|
+
'getFacetedMinMaxValues_' + columnId,
|
|
33
|
+
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
34
|
+
onChange: () => {},
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TableInstance, RowModel, TableGenerics, Row } from '../types'
|
|
2
|
+
import { memo } from '../utils'
|
|
3
|
+
import { filterRows } from './filterRowsUtils'
|
|
4
|
+
|
|
5
|
+
export function getFacetedRowModel<TGenerics extends TableGenerics>(): (
|
|
6
|
+
instance: TableInstance<TGenerics>,
|
|
7
|
+
columnId: string
|
|
8
|
+
) => () => RowModel<TGenerics> {
|
|
9
|
+
return (instance, columnId) =>
|
|
10
|
+
memo(
|
|
11
|
+
() => [
|
|
12
|
+
instance.getPreFilteredRowModel(),
|
|
13
|
+
instance.getState().columnFilters,
|
|
14
|
+
instance.getState().globalFilter,
|
|
15
|
+
instance.getFilteredRowModel(),
|
|
16
|
+
],
|
|
17
|
+
(preRowModel, columnFilters, globalFilter) => {
|
|
18
|
+
if (
|
|
19
|
+
!preRowModel.rows.length ||
|
|
20
|
+
(!columnFilters?.length && !globalFilter)
|
|
21
|
+
) {
|
|
22
|
+
return preRowModel
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const filterableIds = [
|
|
26
|
+
...columnFilters.map(d => d.id).filter(d => d !== columnId),
|
|
27
|
+
globalFilter ? '__global__' : undefined,
|
|
28
|
+
].filter(Boolean) as string[]
|
|
29
|
+
|
|
30
|
+
const filterRowsImpl = (row: Row<TGenerics>) => {
|
|
31
|
+
// Horizontally filter rows through each column
|
|
32
|
+
for (let i = 0; i < filterableIds.length; i++) {
|
|
33
|
+
if (row.columnFilterMap[filterableIds[i]!] === false) {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return filterRows(preRowModel.rows, filterRowsImpl, instance)
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key:
|
|
44
|
+
process.env.NODE_ENV === 'development' &&
|
|
45
|
+
'getFacetedRowModel_' + columnId,
|
|
46
|
+
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
47
|
+
onChange: () => {},
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TableInstance, TableGenerics } from '../types'
|
|
2
|
+
import { memo } from '../utils'
|
|
3
|
+
|
|
4
|
+
export function getFacetedUniqueValues<TGenerics extends TableGenerics>(): (
|
|
5
|
+
instance: TableInstance<TGenerics>,
|
|
6
|
+
columnId: string
|
|
7
|
+
) => () => Map<any, number> {
|
|
8
|
+
return (instance, columnId) =>
|
|
9
|
+
memo(
|
|
10
|
+
() => [instance.getColumn(columnId).getFacetedRowModel()],
|
|
11
|
+
facetedRowModel => {
|
|
12
|
+
let facetedUniqueValues = new Map<any, number>()
|
|
13
|
+
|
|
14
|
+
for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
|
|
15
|
+
const value = facetedRowModel.flatRows[i]?.getValue(columnId)
|
|
16
|
+
|
|
17
|
+
if (facetedUniqueValues.has(value)) {
|
|
18
|
+
facetedUniqueValues.set(
|
|
19
|
+
value,
|
|
20
|
+
(facetedUniqueValues.get(value) ?? 0) + 1
|
|
21
|
+
)
|
|
22
|
+
} else {
|
|
23
|
+
facetedUniqueValues.set(value, 1)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return facetedUniqueValues
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key:
|
|
31
|
+
process.env.NODE_ENV === 'development' &&
|
|
32
|
+
'getFacetedUniqueValues_' + columnId,
|
|
33
|
+
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
34
|
+
onChange: () => {},
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ColumnFilter,
|
|
3
|
-
FilterFn,
|
|
4
|
-
ResolvedColumnFilter,
|
|
5
|
-
} from '../features/Filters'
|
|
1
|
+
import { ResolvedColumnFilter } from '../features/Filters'
|
|
6
2
|
import { TableInstance, RowModel, TableGenerics, Row } from '../types'
|
|
7
3
|
import { memo } from '../utils'
|
|
8
4
|
import { filterRows } from './filterRowsUtils'
|
|
9
5
|
|
|
10
|
-
export function
|
|
6
|
+
export function getFilteredRowModel<TGenerics extends TableGenerics>(): (
|
|
11
7
|
instance: TableInstance<TGenerics>
|
|
12
8
|
) => () => RowModel<TGenerics> {
|
|
13
9
|
return instance =>
|
|
@@ -83,34 +79,38 @@ export function getFilteredRowModelSync<TGenerics extends TableGenerics>(): (
|
|
|
83
79
|
})
|
|
84
80
|
}
|
|
85
81
|
|
|
82
|
+
let currentColumnFilter
|
|
83
|
+
let currentGlobalFilter
|
|
84
|
+
|
|
86
85
|
// Flag the prefiltered row model with each filter state
|
|
87
86
|
for (let j = 0; j < rowModel.flatRows.length; j++) {
|
|
88
|
-
const row = rowModel.flatRows[j]
|
|
87
|
+
const row = rowModel.flatRows[j]!
|
|
89
88
|
|
|
90
89
|
row.columnFilterMap = {}
|
|
91
90
|
|
|
92
91
|
if (resolvedColumnFilters.length) {
|
|
93
92
|
for (let i = 0; i < resolvedColumnFilters.length; i++) {
|
|
94
|
-
|
|
93
|
+
currentColumnFilter = resolvedColumnFilters[i]!
|
|
95
94
|
|
|
96
95
|
// Tag the row with the column filter state
|
|
97
|
-
row.columnFilterMap[
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
row.columnFilterMap[currentColumnFilter.id] =
|
|
97
|
+
currentColumnFilter.filterFn(
|
|
98
|
+
row,
|
|
99
|
+
currentColumnFilter.id,
|
|
100
|
+
currentColumnFilter.resolvedValue
|
|
101
|
+
)
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
if (resolvedGlobalFilters.length) {
|
|
106
106
|
for (let i = 0; i < resolvedGlobalFilters.length; i++) {
|
|
107
|
-
|
|
107
|
+
currentGlobalFilter = resolvedGlobalFilters[i]!
|
|
108
108
|
// Tag the row with the first truthy global filter state
|
|
109
109
|
if (
|
|
110
|
-
|
|
110
|
+
currentGlobalFilter.filterFn(
|
|
111
111
|
row,
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
currentGlobalFilter.id,
|
|
113
|
+
currentGlobalFilter.resolvedValue
|
|
114
114
|
)
|
|
115
115
|
) {
|
|
116
116
|
row.columnFilterMap.__global__ = true
|
|
@@ -124,12 +124,21 @@ export function getFilteredRowModelSync<TGenerics extends TableGenerics>(): (
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
const filterRowsImpl = (row: Row<TGenerics>) => {
|
|
128
|
+
// Horizontally filter rows through each column
|
|
129
|
+
for (let i = 0; i < filterableIds.length; i++) {
|
|
130
|
+
if (row.columnFilterMap[filterableIds[i]!] === false) {
|
|
131
|
+
return false
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return true
|
|
135
|
+
}
|
|
136
|
+
|
|
127
137
|
// Filter final rows using all of the active filters
|
|
128
|
-
return filterRows(rowModel.rows,
|
|
138
|
+
return filterRows(rowModel.rows, filterRowsImpl, instance)
|
|
129
139
|
},
|
|
130
140
|
{
|
|
131
|
-
key:
|
|
132
|
-
process.env.NODE_ENV === 'development' && 'getFilteredRowModelSync',
|
|
141
|
+
key: process.env.NODE_ENV === 'development' && 'getFilteredRowModel',
|
|
133
142
|
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
134
143
|
onChange: () => {
|
|
135
144
|
instance.queue(() => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { CoreRow } from '../features/Rows'
|
|
1
2
|
import { TableInstance, Row, RowModel, TableGenerics } from '../types'
|
|
2
3
|
import { flattenBy, memo } from '../utils'
|
|
3
4
|
|
|
4
|
-
export function
|
|
5
|
+
export function getGroupedRowModel<TGenerics extends TableGenerics>(): (
|
|
5
6
|
instance: TableInstance<TGenerics>
|
|
6
7
|
) => () => RowModel<TGenerics> {
|
|
7
8
|
return instance =>
|
|
@@ -17,56 +18,6 @@ export function getGroupedRowModelSync<TGenerics extends TableGenerics>(): (
|
|
|
17
18
|
instance.getColumn(columnId)
|
|
18
19
|
)
|
|
19
20
|
|
|
20
|
-
// Find the columns that can or are aggregating
|
|
21
|
-
// Uses each column to aggregate rows into a single value
|
|
22
|
-
const aggregateRowsToValues = (
|
|
23
|
-
leafRows: Row<TGenerics>[],
|
|
24
|
-
groupedRows: Row<TGenerics>[],
|
|
25
|
-
depth: number
|
|
26
|
-
) => {
|
|
27
|
-
const values: Record<string, unknown> = {}
|
|
28
|
-
|
|
29
|
-
instance.getAllLeafColumns().forEach(column => {
|
|
30
|
-
// Don't aggregate columns that are in the grouping
|
|
31
|
-
if (existingGrouping.includes(column.id)) {
|
|
32
|
-
values[column.id] = groupedRows[0]
|
|
33
|
-
? groupedRows[0].values[column.id]
|
|
34
|
-
: null
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Aggregate the values
|
|
39
|
-
const aggregateFn = instance.getColumnAggregationFn(column.id)
|
|
40
|
-
|
|
41
|
-
if (aggregateFn) {
|
|
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
|
-
)
|
|
55
|
-
} else if (column.aggregationFn) {
|
|
56
|
-
console.info({ column })
|
|
57
|
-
throw new Error(
|
|
58
|
-
process.env.NODE_ENV !== 'production'
|
|
59
|
-
? `Table: Invalid column.aggregateType option for column listed above`
|
|
60
|
-
: ''
|
|
61
|
-
)
|
|
62
|
-
} else {
|
|
63
|
-
values[column.id] = null
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
return values
|
|
68
|
-
}
|
|
69
|
-
|
|
70
21
|
const groupedFlatRows: Row<TGenerics>[] = []
|
|
71
22
|
const groupedRowsById: Record<string, Row<TGenerics>> = {}
|
|
72
23
|
// const onlyGroupedFlatRows: Row[] = [];
|
|
@@ -104,21 +55,61 @@ export function getGroupedRowModelSync<TGenerics extends TableGenerics>(): (
|
|
|
104
55
|
? flattenBy(groupedRows, row => row.subRows)
|
|
105
56
|
: groupedRows
|
|
106
57
|
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const row = instance.createRow(
|
|
110
|
-
id,
|
|
111
|
-
undefined,
|
|
112
|
-
index,
|
|
113
|
-
depth,
|
|
114
|
-
values
|
|
115
|
-
)
|
|
58
|
+
const row = instance.createRow(id, undefined, index, depth)
|
|
116
59
|
|
|
117
60
|
Object.assign(row, {
|
|
118
61
|
groupingColumnId: columnId,
|
|
119
62
|
groupingValue,
|
|
120
63
|
subRows,
|
|
121
64
|
leafRows,
|
|
65
|
+
getValue: (columnId: string) => {
|
|
66
|
+
// Don't aggregate columns that are in the grouping
|
|
67
|
+
if (existingGrouping.includes(columnId)) {
|
|
68
|
+
if (row.valuesCache.hasOwnProperty(columnId)) {
|
|
69
|
+
return row.valuesCache[columnId]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (groupedRows[0]) {
|
|
73
|
+
row.valuesCache[columnId] =
|
|
74
|
+
groupedRows[0].getValue(columnId) ?? undefined
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return row.valuesCache[columnId]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (row.groupingValuesCache.hasOwnProperty(columnId)) {
|
|
81
|
+
return row.groupingValuesCache[columnId]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Aggregate the values
|
|
85
|
+
const column = instance.getColumn(columnId)
|
|
86
|
+
const aggregateFn = column.getColumnAggregationFn()
|
|
87
|
+
|
|
88
|
+
if (aggregateFn) {
|
|
89
|
+
row.groupingValuesCache[columnId] = aggregateFn(
|
|
90
|
+
() =>
|
|
91
|
+
leafRows.map(row => {
|
|
92
|
+
let columnValue = row.getValue(columnId)
|
|
93
|
+
|
|
94
|
+
if (!depth && column.aggregateValue) {
|
|
95
|
+
columnValue = column.aggregateValue(columnValue)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return columnValue
|
|
99
|
+
}),
|
|
100
|
+
() => groupedRows.map(row => row.getValue(columnId))
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
return row.groupingValuesCache[columnId]
|
|
104
|
+
} else if (column.aggregationFn) {
|
|
105
|
+
console.info({ column })
|
|
106
|
+
throw new Error(
|
|
107
|
+
process.env.NODE_ENV !== 'production'
|
|
108
|
+
? `Table: Invalid column.aggregateType option for column listed above`
|
|
109
|
+
: ''
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
},
|
|
122
113
|
})
|
|
123
114
|
|
|
124
115
|
subRows.forEach(subRow => {
|
|
@@ -180,7 +171,7 @@ function groupBy<TGenerics extends TableGenerics>(
|
|
|
180
171
|
const groupMap = new Map<any, Row<TGenerics>[]>()
|
|
181
172
|
|
|
182
173
|
return rows.reduce((map, row) => {
|
|
183
|
-
const resKey = `${row.
|
|
174
|
+
const resKey = `${row.getValue(columnId)}`
|
|
184
175
|
const previous = map.get(resKey)
|
|
185
176
|
if (!previous) {
|
|
186
177
|
map.set(resKey, [row])
|
|
@@ -2,7 +2,7 @@ import { TableInstance, Row, RowModel, TableGenerics } from '../types'
|
|
|
2
2
|
import { SortingFn } from '../features/Sorting'
|
|
3
3
|
import { memo } from '../utils'
|
|
4
4
|
|
|
5
|
-
export function
|
|
5
|
+
export function getSortedRowModel<TGenerics extends TableGenerics>(): (
|
|
6
6
|
instance: TableInstance<TGenerics>
|
|
7
7
|
) => () => RowModel<TGenerics> {
|
|
8
8
|
return instance =>
|
|
@@ -53,8 +53,8 @@ export function getSortedRowModelSync<TGenerics extends TableGenerics>(): (
|
|
|
53
53
|
const isDesc = sortEntry?.desc ?? false
|
|
54
54
|
|
|
55
55
|
if (columnInfo.sortUndefined) {
|
|
56
|
-
const aValue = rowA.
|
|
57
|
-
const bValue = rowB.
|
|
56
|
+
const aValue = rowA.getValue(sortEntry.id)
|
|
57
|
+
const bValue = rowB.getValue(sortEntry.id)
|
|
58
58
|
|
|
59
59
|
const aUndefined = typeof aValue === 'undefined'
|
|
60
60
|
const bUndefined = typeof bValue === 'undefined'
|