@tanstack/table-core 8.0.0-alpha.9 → 8.0.0-beta.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/aggregationFns.js +120 -0
- package/build/cjs/aggregationFns.js.map +1 -0
- package/build/cjs/core/cell.js +40 -0
- package/build/cjs/core/cell.js.map +1 -0
- package/build/cjs/core/column.js +88 -0
- package/build/cjs/core/column.js.map +1 -0
- package/build/cjs/core/headers.js +403 -0
- package/build/cjs/core/headers.js.map +1 -0
- package/build/cjs/core/instance.js +255 -0
- package/build/cjs/core/instance.js.map +1 -0
- package/build/cjs/core/row.js +77 -0
- package/build/cjs/core/row.js.map +1 -0
- package/build/cjs/createTable.js +36 -29
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +157 -189
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +103 -155
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +155 -304
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +97 -157
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Ordering.js +30 -41
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +102 -105
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +131 -89
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +138 -267
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +82 -167
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +69 -115
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +107 -0
- package/build/cjs/filterFns.js.map +1 -0
- package/build/cjs/index.js +36 -23
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/sortingFns.js +124 -0
- package/build/cjs/sortingFns.js.map +1 -0
- package/build/cjs/utils/filterRowsUtils.js +117 -0
- package/build/cjs/utils/filterRowsUtils.js.map +1 -0
- package/build/cjs/utils/getCoreRowModel.js +79 -0
- package/build/cjs/utils/getCoreRowModel.js.map +1 -0
- package/build/cjs/utils/getExpandedRowModel.js +57 -0
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js +54 -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 +139 -0
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +161 -0
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
- package/build/cjs/utils/getPaginationRowModel.js +61 -0
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
- package/build/cjs/utils/getSortedRowModel.js +110 -0
- package/build/cjs/utils/getSortedRowModel.js.map +1 -0
- package/build/cjs/utils.js +38 -107
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +2976 -3853
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +586 -408
- package/build/types/aggregationFns.d.ts +13 -0
- package/build/types/core/cell.d.ts +9 -0
- package/build/types/core/column.d.ts +40 -0
- package/build/types/core/headers.d.ts +46 -0
- package/build/types/core/instance.d.ts +57 -0
- package/build/types/core/row.d.ts +15 -0
- package/build/types/createTable.d.ts +47 -26
- package/build/types/features/ColumnSizing.d.ts +32 -44
- package/build/types/features/Expanding.d.ts +15 -26
- package/build/types/features/Filters.d.ts +64 -63
- package/build/types/features/Grouping.d.ts +32 -46
- package/build/types/features/Ordering.d.ts +7 -10
- package/build/types/features/Pagination.d.ts +16 -15
- package/build/types/features/Pinning.d.ts +16 -17
- package/build/types/features/RowSelection.d.ts +13 -33
- package/build/types/features/Sorting.d.ts +25 -44
- package/build/types/features/Visibility.d.ts +16 -25
- package/build/types/filterFns.d.ts +13 -0
- package/build/types/index.d.ts +16 -10
- package/build/types/sortingFns.d.ts +11 -0
- package/build/types/types.d.ts +37 -122
- package/build/types/utils/filterRowsUtils.d.ts +4 -0
- package/build/types/utils/getCoreRowModel.d.ts +2 -0
- package/build/types/utils/getExpandedRowModel.d.ts +7 -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/getFilteredRowModel.d.ts +2 -0
- package/build/types/utils/getGroupedRowModel.d.ts +2 -0
- package/build/types/utils/getPaginationRowModel.d.ts +4 -0
- package/build/types/utils/getSortedRowModel.d.ts +2 -0
- package/build/types/utils.d.ts +7 -11
- package/build/umd/index.development.js +3024 -3893
- 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 +9 -10
- package/src/.DS_Store +0 -0
- package/src/aggregationFns.ts +123 -0
- package/src/core/cell.ts +48 -0
- package/src/core/column.ts +147 -0
- package/src/core/headers.ts +575 -0
- package/src/core/instance.ts +361 -0
- package/src/core/row.ts +85 -0
- package/src/createTable.ts +188 -0
- package/src/features/ColumnSizing.ts +170 -185
- package/src/features/Expanding.ts +122 -194
- package/src/features/Filters.ts +301 -381
- package/src/features/Grouping.ts +160 -220
- package/src/features/Ordering.ts +24 -25
- package/src/features/Pagination.ts +90 -73
- package/src/features/Pinning.ts +186 -63
- package/src/features/RowSelection.ts +107 -245
- package/src/features/Sorting.ts +127 -225
- package/src/features/Visibility.ts +116 -132
- package/src/filterFns.ts +135 -0
- package/src/index.ts +29 -0
- package/src/{sortTypes.ts → sortingFns.ts} +63 -85
- package/src/types.ts +62 -168
- package/src/utils/filterRowsUtils.ts +112 -0
- package/src/utils/getCoreRowModel.ts +84 -0
- package/src/utils/getExpandedRowModel.ts +54 -0
- package/src/utils/getFacetedMinMaxValues.ts +40 -0
- package/src/utils/getFacetedRowModel.ts +50 -0
- package/src/utils/getFacetedUniqueValues.ts +37 -0
- package/src/utils/getFilteredRowModel.ts +159 -0
- package/src/utils/getGroupedRowModel.ts +175 -0
- package/src/utils/getPaginationRowModel.ts +48 -0
- package/src/utils/getSortedRowModel.ts +116 -0
- package/src/utils.ts +126 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/aggregationTypes.js +0 -130
- package/build/cjs/aggregationTypes.js.map +0 -1
- package/build/cjs/core.js +0 -545
- package/build/cjs/core.js.map +0 -1
- package/build/cjs/features/Headers.js +0 -630
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/sortTypes.js +0 -122
- package/build/cjs/sortTypes.js.map +0 -1
- package/build/cjs/types.js +0 -22
- package/build/cjs/types.js.map +0 -1
- package/build/cjs/utils/columnFilterRowsFn.js +0 -131
- package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/expandRowsFn.js +0 -38
- package/build/cjs/utils/expandRowsFn.js.map +0 -1
- package/build/cjs/utils/globalFilterRowsFn.js +0 -101
- package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/groupRowsFn.js +0 -155
- package/build/cjs/utils/groupRowsFn.js.map +0 -1
- package/build/cjs/utils/paginateRowsFn.js +0 -44
- package/build/cjs/utils/paginateRowsFn.js.map +0 -1
- package/build/cjs/utils/sortRowsFn.js +0 -94
- package/build/cjs/utils/sortRowsFn.js.map +0 -1
- package/build/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -105
- package/build/types/features/Headers.d.ts +0 -43
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
- package/build/types/utils/expandRowsFn.d.ts +0 -2
- package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
- package/build/types/utils/groupRowsFn.d.ts +0 -2
- package/build/types/utils/paginateRowsFn.d.ts +0 -2
- package/build/types/utils/sortRowsFn.d.ts +0 -2
- package/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -763
- package/src/createTable.tsx +0 -137
- package/src/features/Headers.ts +0 -747
- package/src/filterTypes.ts +0 -188
- package/src/index.tsx +0 -23
- package/src/utils/columnFilterRowsFn.ts +0 -113
- package/src/utils/expandRowsFn.ts +0 -30
- package/src/utils/globalFilterRowsFn.ts +0 -89
- package/src/utils/groupRowsFn.ts +0 -170
- package/src/utils/paginateRowsFn.ts +0 -28
- package/src/utils/sortRowsFn.ts +0 -95
- package/src/utils.tsx +0 -221
package/src/filterTypes.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, Row } from './types'
|
|
2
|
-
|
|
3
|
-
export const filterTypes = {
|
|
4
|
-
includesString,
|
|
5
|
-
includesStringSensitive,
|
|
6
|
-
equalsString,
|
|
7
|
-
equalsStringSensitive,
|
|
8
|
-
arrIncludes,
|
|
9
|
-
arrIncludesAll,
|
|
10
|
-
equals,
|
|
11
|
-
weakEquals,
|
|
12
|
-
betweenNumberRange,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type BuiltInFilterType = keyof typeof filterTypes
|
|
16
|
-
|
|
17
|
-
function includesString<TGenerics extends PartialGenerics>(
|
|
18
|
-
rows: Row<TGenerics>[],
|
|
19
|
-
columnIds: string[],
|
|
20
|
-
filterValue: unknown
|
|
21
|
-
) {
|
|
22
|
-
const search = String(filterValue).toLowerCase()
|
|
23
|
-
|
|
24
|
-
rows = rows.filter(row => {
|
|
25
|
-
return columnIds.some(id => {
|
|
26
|
-
return String(row.values[id]).toLowerCase().includes(search)
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
return rows
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
includesString.autoRemove = (val: any) => testFalsey(val)
|
|
33
|
-
|
|
34
|
-
function includesStringSensitive<TGenerics extends PartialGenerics>(
|
|
35
|
-
rows: Row<TGenerics>[],
|
|
36
|
-
columnIds: string[],
|
|
37
|
-
filterValue: unknown
|
|
38
|
-
) {
|
|
39
|
-
const search = String(filterValue)
|
|
40
|
-
|
|
41
|
-
rows = rows.filter(row => {
|
|
42
|
-
return columnIds.some(id => {
|
|
43
|
-
return String(row.values[id]).includes(search)
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
return rows
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
includesStringSensitive.autoRemove = (val: any) => testFalsey(val)
|
|
50
|
-
|
|
51
|
-
function equalsString<TGenerics extends PartialGenerics>(
|
|
52
|
-
rows: Row<TGenerics>[],
|
|
53
|
-
columnIds: string[],
|
|
54
|
-
filterValue: unknown
|
|
55
|
-
) {
|
|
56
|
-
const search = String(filterValue).toLowerCase()
|
|
57
|
-
|
|
58
|
-
return rows.filter(row => {
|
|
59
|
-
return columnIds.some(id => {
|
|
60
|
-
const rowValue = row.values[id]
|
|
61
|
-
return rowValue !== undefined
|
|
62
|
-
? String(rowValue).toLowerCase() === search
|
|
63
|
-
: true
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
equalsString.autoRemove = (val: any) => testFalsey(val)
|
|
69
|
-
|
|
70
|
-
function equalsStringSensitive<TGenerics extends PartialGenerics>(
|
|
71
|
-
rows: Row<TGenerics>[],
|
|
72
|
-
columnIds: string[],
|
|
73
|
-
filterValue: unknown
|
|
74
|
-
) {
|
|
75
|
-
const search = String(filterValue)
|
|
76
|
-
return rows.filter(row => {
|
|
77
|
-
return columnIds.some(id => {
|
|
78
|
-
const rowValue = row.values[id]
|
|
79
|
-
return rowValue !== undefined ? String(rowValue) === search : true
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
equalsStringSensitive.autoRemove = (val: any) => testFalsey(val)
|
|
85
|
-
|
|
86
|
-
function arrIncludes<TGenerics extends PartialGenerics>(
|
|
87
|
-
rows: Row<TGenerics>[],
|
|
88
|
-
columnIds: string[],
|
|
89
|
-
filterValue: unknown
|
|
90
|
-
) {
|
|
91
|
-
return rows.filter(row => {
|
|
92
|
-
return columnIds.some(id => {
|
|
93
|
-
const rowValue = row.values[id]
|
|
94
|
-
return rowValue.includes(filterValue)
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
arrIncludes.autoRemove = (val: any) => testFalsey(val) || !val?.length
|
|
100
|
-
|
|
101
|
-
function arrIncludesAll<TGenerics extends PartialGenerics>(
|
|
102
|
-
rows: Row<TGenerics>[],
|
|
103
|
-
columnIds: string[],
|
|
104
|
-
filterValue: unknown[]
|
|
105
|
-
) {
|
|
106
|
-
return rows.filter(row => {
|
|
107
|
-
return columnIds.some(id => {
|
|
108
|
-
const rowValue = row.values[id]
|
|
109
|
-
return (
|
|
110
|
-
rowValue &&
|
|
111
|
-
rowValue.length &&
|
|
112
|
-
filterValue.every(val => rowValue.includes(val))
|
|
113
|
-
)
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
arrIncludesAll.autoRemove = (val: any) => testFalsey(val) || !val?.length
|
|
119
|
-
|
|
120
|
-
function equals<TGenerics extends PartialGenerics>(
|
|
121
|
-
rows: Row<TGenerics>[],
|
|
122
|
-
columnIds: string[],
|
|
123
|
-
filterValue: unknown
|
|
124
|
-
) {
|
|
125
|
-
return rows.filter(row => {
|
|
126
|
-
return columnIds.some(id => {
|
|
127
|
-
const rowValue = row.values[id]
|
|
128
|
-
return rowValue === filterValue
|
|
129
|
-
})
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
equals.autoRemove = (val: any) => testFalsey(val)
|
|
134
|
-
|
|
135
|
-
function weakEquals<TGenerics extends PartialGenerics>(
|
|
136
|
-
rows: Row<TGenerics>[],
|
|
137
|
-
columnIds: string[],
|
|
138
|
-
filterValue: unknown
|
|
139
|
-
) {
|
|
140
|
-
return rows.filter(row => {
|
|
141
|
-
return columnIds.some(id => {
|
|
142
|
-
const rowValue = row.values[id]
|
|
143
|
-
// eslint-disable-next-line eqeqeq
|
|
144
|
-
return rowValue == filterValue
|
|
145
|
-
})
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
weakEquals.autoRemove = (val: any) => testFalsey(val)
|
|
150
|
-
|
|
151
|
-
function betweenNumberRange<TGenerics extends PartialGenerics>(
|
|
152
|
-
rows: Row<TGenerics>[],
|
|
153
|
-
columnIds: string[],
|
|
154
|
-
filterValue: [unknown, unknown]
|
|
155
|
-
) {
|
|
156
|
-
let [unsafeMin, unsafeMax] = filterValue || []
|
|
157
|
-
|
|
158
|
-
let parsedMin =
|
|
159
|
-
typeof unsafeMin !== 'number' ? parseFloat(unsafeMin as string) : unsafeMin
|
|
160
|
-
let parsedMax =
|
|
161
|
-
typeof unsafeMax !== 'number' ? parseFloat(unsafeMax as string) : unsafeMax
|
|
162
|
-
|
|
163
|
-
let min =
|
|
164
|
-
unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin
|
|
165
|
-
let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax
|
|
166
|
-
|
|
167
|
-
if (min > max) {
|
|
168
|
-
const temp = min
|
|
169
|
-
min = max
|
|
170
|
-
max = temp
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return rows.filter(row => {
|
|
174
|
-
return columnIds.some(id => {
|
|
175
|
-
const rowValue = row.values[id]
|
|
176
|
-
return rowValue >= min && rowValue <= max
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
betweenNumberRange.autoRemove = (val: any) =>
|
|
182
|
-
testFalsey(val) || (testFalsey(val[0]) && testFalsey(val[1]))
|
|
183
|
-
|
|
184
|
-
// Utils
|
|
185
|
-
|
|
186
|
-
function testFalsey(val: any) {
|
|
187
|
-
return val === undefined || val === null || val === ''
|
|
188
|
-
}
|
package/src/index.tsx
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export * from './core'
|
|
2
|
-
export * from './types'
|
|
3
|
-
export * from './createTable'
|
|
4
|
-
export * from './features/ColumnSizing'
|
|
5
|
-
export * from './features/ColumnSizing'
|
|
6
|
-
export * from './features/Expanding'
|
|
7
|
-
export * from './features/Filters'
|
|
8
|
-
export * from './features/Grouping'
|
|
9
|
-
export * from './features/Headers'
|
|
10
|
-
export * from './features/Ordering'
|
|
11
|
-
export * from './features/Pagination'
|
|
12
|
-
export * from './features/Pinning'
|
|
13
|
-
export * from './features/RowSelection'
|
|
14
|
-
export * from './features/Sorting'
|
|
15
|
-
export * from './features/Visibility'
|
|
16
|
-
export * from './features/Expanding'
|
|
17
|
-
export * from './utils'
|
|
18
|
-
export * from './utils/columnFilterRowsFn'
|
|
19
|
-
export * from './utils/globalFilterRowsFn'
|
|
20
|
-
export * from './utils/sortRowsFn'
|
|
21
|
-
export * from './utils/groupRowsFn'
|
|
22
|
-
export * from './utils/expandRowsFn'
|
|
23
|
-
export * from './utils/paginateRowsFn'
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
|
|
2
|
-
|
|
3
|
-
export function columnFilterRowsFn<TGenerics extends PartialGenerics>(
|
|
4
|
-
instance: TableInstance<TGenerics>,
|
|
5
|
-
rowModel: RowModel<TGenerics>
|
|
6
|
-
): RowModel<TGenerics> {
|
|
7
|
-
const columnFilters = instance.getState().columnFilters
|
|
8
|
-
|
|
9
|
-
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
10
|
-
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
11
|
-
|
|
12
|
-
const filterFromChildrenUp = instance.options.filterFromChildrenUp
|
|
13
|
-
|
|
14
|
-
const filterRows = (rowsToFilter: Row<TGenerics>[], depth: number) => {
|
|
15
|
-
columnFilters.forEach(({ id: columnId, value: filterValue }) => {
|
|
16
|
-
// Find the columnFilters column
|
|
17
|
-
const column = instance.getColumn(columnId)
|
|
18
|
-
|
|
19
|
-
if (!column) {
|
|
20
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
21
|
-
console.warn(
|
|
22
|
-
`React-Table: Could not find a column with id: ${columnId}`
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
throw new Error()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (depth === 0) {
|
|
29
|
-
const preFilteredRows = [...rowsToFilter]
|
|
30
|
-
column.getPreFilteredRows = () => preFilteredRows
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const filterFn = instance.getColumnFilterFn(column.id)
|
|
34
|
-
|
|
35
|
-
if (!filterFn) {
|
|
36
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
37
|
-
console.warn(
|
|
38
|
-
`Could not find a valid 'column.filterType' for column with the ID: ${column.id}.`
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Pass the rows, id, filterValue and column to the filterFn
|
|
45
|
-
// to get the filtered rows back
|
|
46
|
-
rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
return rowsToFilter
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (filterFromChildrenUp) {
|
|
53
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
54
|
-
// Filter from children up
|
|
55
|
-
rowsToFilter = rowsToFilter.filter(row => {
|
|
56
|
-
if (!row.subRows?.length) {
|
|
57
|
-
return true
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
61
|
-
|
|
62
|
-
return row.subRows.length
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
rowsToFilter = filterRows(rowsToFilter, depth)
|
|
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
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
78
|
-
flatRows: newFilteredFlatRows,
|
|
79
|
-
rowsById: newFilteredRowsById,
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Filters top level and nested rows
|
|
84
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
85
|
-
// Filter from parents downward
|
|
86
|
-
rowsToFilter = filterRows(rowsToFilter, depth)
|
|
87
|
-
|
|
88
|
-
// Apply the filter to any subRows
|
|
89
|
-
// We technically could do this recursively in the above loop,
|
|
90
|
-
// but that would severely hinder the API for the user, since they
|
|
91
|
-
// would be required to do that recursion in some scenarios
|
|
92
|
-
rowsToFilter.forEach(row => {
|
|
93
|
-
newFilteredFlatRows.push(row)
|
|
94
|
-
newFilteredRowsById[row.id] = row
|
|
95
|
-
|
|
96
|
-
if (!filterFromChildrenUp) {
|
|
97
|
-
if (!row.subRows?.length) {
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
return rowsToFilter
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
110
|
-
flatRows: newFilteredFlatRows,
|
|
111
|
-
rowsById: newFilteredRowsById,
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
|
|
2
|
-
|
|
3
|
-
export function expandRowsFn<TGenerics extends PartialGenerics>(
|
|
4
|
-
instance: TableInstance<TGenerics>,
|
|
5
|
-
sortedRowModel: RowModel<TGenerics>
|
|
6
|
-
): RowModel<TGenerics> {
|
|
7
|
-
const expandedRows: Row<TGenerics>[] = []
|
|
8
|
-
|
|
9
|
-
const { expandSubRows } = instance.options
|
|
10
|
-
|
|
11
|
-
const handleRow = (row: Row<TGenerics>) => {
|
|
12
|
-
expandedRows.push(row)
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
expandSubRows &&
|
|
16
|
-
row.subRows?.length &&
|
|
17
|
-
instance.getIsRowExpanded(row.id)
|
|
18
|
-
) {
|
|
19
|
-
row.subRows.forEach(handleRow)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
sortedRowModel.rows.forEach(handleRow)
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
rows: expandedRows,
|
|
27
|
-
flatRows: sortedRowModel.flatRows,
|
|
28
|
-
rowsById: sortedRowModel.rowsById,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
|
|
2
|
-
|
|
3
|
-
export function globalFilterRowsFn<TGenerics extends PartialGenerics>(
|
|
4
|
-
instance: TableInstance<TGenerics>,
|
|
5
|
-
rowModel: RowModel<TGenerics>
|
|
6
|
-
): RowModel<TGenerics> {
|
|
7
|
-
const globalFilter = instance.getState().globalFilter
|
|
8
|
-
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
9
|
-
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
10
|
-
|
|
11
|
-
const filterFromChildrenUp = instance.options.filterFromChildrenUp
|
|
12
|
-
|
|
13
|
-
const filterFn = instance.getGlobalFilterFn()
|
|
14
|
-
|
|
15
|
-
if (!filterFn) {
|
|
16
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
17
|
-
console.warn(`Could not find a valid 'globalFilterType'`)
|
|
18
|
-
}
|
|
19
|
-
return rowModel
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const filterableColumns = instance
|
|
23
|
-
.getAllLeafColumns()
|
|
24
|
-
.filter(column => column.getCanGlobalFilter())
|
|
25
|
-
|
|
26
|
-
const filterableColumnIds = filterableColumns.map(d => d.id)
|
|
27
|
-
|
|
28
|
-
if (filterFromChildrenUp) {
|
|
29
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
30
|
-
// Filter from children up
|
|
31
|
-
rowsToFilter = rowsToFilter.filter(row => {
|
|
32
|
-
if (!row.subRows?.length) {
|
|
33
|
-
return true
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
37
|
-
|
|
38
|
-
return row.subRows.length
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter)
|
|
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(rowModel.rows),
|
|
54
|
-
flatRows: newFilteredFlatRows,
|
|
55
|
-
rowsById: newFilteredRowsById,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Filters top level and nested rows
|
|
60
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
61
|
-
// Filter from parents downward
|
|
62
|
-
rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter)
|
|
63
|
-
|
|
64
|
-
// Apply the filter to any subRows
|
|
65
|
-
// We technically could do this recursively in the above loop,
|
|
66
|
-
// but that would severely hinder the API for the user, since they
|
|
67
|
-
// would be required to do that recursion in some scenarios
|
|
68
|
-
rowsToFilter.forEach(row => {
|
|
69
|
-
newFilteredFlatRows.push(row)
|
|
70
|
-
newFilteredRowsById[row.id] = row
|
|
71
|
-
|
|
72
|
-
if (!filterFromChildrenUp) {
|
|
73
|
-
if (!row.subRows?.length) {
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
return rowsToFilter
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
86
|
-
flatRows: newFilteredFlatRows,
|
|
87
|
-
rowsById: newFilteredRowsById,
|
|
88
|
-
}
|
|
89
|
-
}
|
package/src/utils/groupRowsFn.ts
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
|
|
2
|
-
import { flattenBy } from '../utils'
|
|
3
|
-
|
|
4
|
-
export function groupRowsFn<TGenerics extends PartialGenerics>(
|
|
5
|
-
instance: TableInstance<TGenerics>,
|
|
6
|
-
sortedRowModel: RowModel<TGenerics>
|
|
7
|
-
): RowModel<TGenerics> {
|
|
8
|
-
const groupingState = instance.getState().grouping
|
|
9
|
-
// Filter the grouping list down to columns that exist
|
|
10
|
-
const existingGrouping = groupingState.filter(columnId =>
|
|
11
|
-
instance.getColumn(columnId)
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
// Find the columns that can or are aggregating
|
|
15
|
-
// Uses each column to aggregate rows into a single value
|
|
16
|
-
const aggregateRowsToValues = (
|
|
17
|
-
leafRows: Row<TGenerics>[],
|
|
18
|
-
groupedRows: Row<TGenerics>[],
|
|
19
|
-
depth: number
|
|
20
|
-
) => {
|
|
21
|
-
const values: Record<string, unknown> = {}
|
|
22
|
-
|
|
23
|
-
instance.getAllLeafColumns().forEach(column => {
|
|
24
|
-
// Don't aggregate columns that are in the grouping
|
|
25
|
-
if (existingGrouping.includes(column.id)) {
|
|
26
|
-
values[column.id] = groupedRows[0]
|
|
27
|
-
? groupedRows[0].values[column.id]
|
|
28
|
-
: null
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Aggregate the values
|
|
33
|
-
const aggregateFn = instance.getColumnAggregationFn(column.id)
|
|
34
|
-
|
|
35
|
-
if (aggregateFn) {
|
|
36
|
-
// Get the columnValues to aggregate
|
|
37
|
-
const groupedValues = groupedRows.map(row => row.values[column.id])
|
|
38
|
-
|
|
39
|
-
// Get the columnValues to aggregate
|
|
40
|
-
const leafValues = leafRows.map(row => {
|
|
41
|
-
let columnValue = row.values[column.id]
|
|
42
|
-
|
|
43
|
-
if (!depth && column.aggregateValue) {
|
|
44
|
-
columnValue = column.aggregateValue(columnValue)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return columnValue
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
values[column.id] = aggregateFn(leafValues, groupedValues)
|
|
51
|
-
} else if (column.aggregationType) {
|
|
52
|
-
console.info({ column })
|
|
53
|
-
throw new Error(
|
|
54
|
-
process.env.NODE_ENV !== 'production'
|
|
55
|
-
? `React Table: Invalid column.aggregateType option for column listed above`
|
|
56
|
-
: ''
|
|
57
|
-
)
|
|
58
|
-
} else {
|
|
59
|
-
values[column.id] = null
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
return values
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const groupedFlatRows: Row<TGenerics>[] = []
|
|
67
|
-
const groupedRowsById: Record<string, Row<TGenerics>> = {}
|
|
68
|
-
// const onlyGroupedFlatRows: Row[] = [];
|
|
69
|
-
// const onlyGroupedRowsById: Record<RowId, Row> = {};
|
|
70
|
-
// const nonGroupedFlatRows: Row[] = [];
|
|
71
|
-
// const nonGroupedRowsById: Record<RowId, Row> = {};
|
|
72
|
-
|
|
73
|
-
// Recursively group the data
|
|
74
|
-
const groupUpRecursively = (
|
|
75
|
-
rows: Row<TGenerics>[],
|
|
76
|
-
depth = 0,
|
|
77
|
-
parentId: string
|
|
78
|
-
) => {
|
|
79
|
-
// This is the last level, just return the rows
|
|
80
|
-
if (depth === existingGrouping.length) {
|
|
81
|
-
return rows
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const columnId = existingGrouping[depth]!
|
|
85
|
-
|
|
86
|
-
// Group the rows together for this level
|
|
87
|
-
const rowGroupsMap = groupBy(rows, columnId)
|
|
88
|
-
|
|
89
|
-
// Peform aggregations for each group
|
|
90
|
-
const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(
|
|
91
|
-
([groupingValue, groupedRows], index) => {
|
|
92
|
-
let id = `${columnId}:${groupingValue}`
|
|
93
|
-
id = parentId ? `${parentId}>${id}` : id
|
|
94
|
-
|
|
95
|
-
// First, Recurse to group sub rows before aggregation
|
|
96
|
-
const subRows = groupUpRecursively(groupedRows, depth + 1, id)
|
|
97
|
-
|
|
98
|
-
// Flatten the leaf rows of the rows in this group
|
|
99
|
-
const leafRows = depth
|
|
100
|
-
? flattenBy(groupedRows, row => row.leafRows)
|
|
101
|
-
: groupedRows
|
|
102
|
-
|
|
103
|
-
const values = aggregateRowsToValues(leafRows, groupedRows, depth)
|
|
104
|
-
|
|
105
|
-
const row = instance.createRow(id, undefined, index, depth, values)
|
|
106
|
-
|
|
107
|
-
Object.assign(row, {
|
|
108
|
-
groupingColumnId: columnId,
|
|
109
|
-
groupingValue,
|
|
110
|
-
subRows,
|
|
111
|
-
leafRows,
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
subRows.forEach(subRow => {
|
|
115
|
-
groupedFlatRows.push(subRow)
|
|
116
|
-
groupedRowsById[subRow.id] = subRow
|
|
117
|
-
// if (subRow.getIsGrouped?.()) {
|
|
118
|
-
// onlyGroupedFlatRows.push(subRow);
|
|
119
|
-
// onlyGroupedRowsById[subRow.id] = subRow;
|
|
120
|
-
// } else {
|
|
121
|
-
// nonGroupedFlatRows.push(subRow);
|
|
122
|
-
// nonGroupedRowsById[subRow.id] = subRow;
|
|
123
|
-
// }
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
return row
|
|
127
|
-
}
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
return aggregatedGroupedRows
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const groupedRows = groupUpRecursively(sortedRowModel.rows, 0, '')
|
|
134
|
-
|
|
135
|
-
groupedRows.forEach(subRow => {
|
|
136
|
-
groupedFlatRows.push(subRow)
|
|
137
|
-
groupedRowsById[subRow.id] = subRow
|
|
138
|
-
// if (subRow.getIsGrouped?.()) {
|
|
139
|
-
// onlyGroupedFlatRows.push(subRow);
|
|
140
|
-
// onlyGroupedRowsById[subRow.id] = subRow;
|
|
141
|
-
// } else {
|
|
142
|
-
// nonGroupedFlatRows.push(subRow);
|
|
143
|
-
// nonGroupedRowsById[subRow.id] = subRow;
|
|
144
|
-
// }
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
rows: groupedRows,
|
|
149
|
-
flatRows: groupedFlatRows,
|
|
150
|
-
rowsById: groupedRowsById,
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function groupBy<TGenerics extends PartialGenerics>(
|
|
155
|
-
rows: Row<TGenerics>[],
|
|
156
|
-
columnId: string
|
|
157
|
-
) {
|
|
158
|
-
const groupMap = new Map<any, Row<TGenerics>[]>()
|
|
159
|
-
|
|
160
|
-
return rows.reduce((map, row) => {
|
|
161
|
-
const resKey = `${row.values[columnId]}`
|
|
162
|
-
const previous = map.get(resKey)
|
|
163
|
-
if (!previous) {
|
|
164
|
-
map.set(resKey, [row])
|
|
165
|
-
} else {
|
|
166
|
-
map.set(resKey, [...previous, row])
|
|
167
|
-
}
|
|
168
|
-
return map
|
|
169
|
-
}, groupMap)
|
|
170
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, RowModel } from '../types'
|
|
2
|
-
import { expandRowsFn } from './expandRowsFn'
|
|
3
|
-
|
|
4
|
-
export function paginateRowsFn<TGenerics extends PartialGenerics>(
|
|
5
|
-
instance: TableInstance<TGenerics>,
|
|
6
|
-
rowModel: RowModel<TGenerics>
|
|
7
|
-
): RowModel<TGenerics> {
|
|
8
|
-
const { pageSize, pageIndex } = instance.getState().pagination
|
|
9
|
-
let { rows, flatRows, rowsById } = rowModel
|
|
10
|
-
const pageStart = pageSize * pageIndex
|
|
11
|
-
const pageEnd = pageStart + pageSize
|
|
12
|
-
|
|
13
|
-
rows = rows.slice(pageStart, pageEnd)
|
|
14
|
-
|
|
15
|
-
if (!instance.options.paginateExpandedRows) {
|
|
16
|
-
return expandRowsFn(instance, {
|
|
17
|
-
rows,
|
|
18
|
-
flatRows,
|
|
19
|
-
rowsById,
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
rows,
|
|
25
|
-
flatRows,
|
|
26
|
-
rowsById,
|
|
27
|
-
}
|
|
28
|
-
}
|