@tanstack/table-core 8.0.0-alpha.22 → 8.0.0-alpha.25
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 +17 -29
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +2 -2
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +23 -8
- package/build/cjs/features/ColumnSizing.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 +1 -1
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +3 -3
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterTypes.js.map +1 -1
- package/build/cjs/sortTypes.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 +2587 -2620
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +368 -335
- package/build/types/aggregationTypes.d.ts +9 -9
- package/build/types/core.d.ts +8 -13
- package/build/types/createTable.d.ts +4 -4
- package/build/types/features/ColumnSizing.d.ts +13 -8
- package/build/types/features/Expanding.d.ts +6 -6
- package/build/types/features/Filters.d.ts +15 -15
- package/build/types/features/Grouping.d.ts +16 -16
- package/build/types/features/Headers.d.ts +6 -6
- package/build/types/features/Ordering.d.ts +4 -4
- package/build/types/features/Pagination.d.ts +5 -5
- package/build/types/features/Pinning.d.ts +5 -5
- package/build/types/features/RowSelection.d.ts +8 -8
- package/build/types/features/Sorting.d.ts +12 -12
- package/build/types/features/Visibility.d.ts +6 -6
- package/build/types/filterTypes.d.ts +10 -10
- package/build/types/sortTypes.d.ts +7 -7
- package/build/types/types.d.ts +22 -13
- package/build/types/utils/filterRowsUtils.d.ts +3 -0
- package/build/types/utils/sortRowsQuicksortFn.d.ts +11 -0
- package/build/umd/index.development.js +2587 -2620
- 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 +29 -55
- package/src/createTable.tsx +17 -11
- package/src/features/ColumnSizing.ts +31 -7
- package/src/features/Expanding.ts +7 -15
- package/src/features/Filters.ts +15 -15
- package/src/features/Grouping.ts +19 -19
- package/src/features/Headers.ts +5 -5
- package/src/features/Ordering.ts +3 -3
- package/src/features/Pagination.ts +4 -4
- package/src/features/Pinning.ts +4 -4
- package/src/features/RowSelection.ts +9 -11
- package/src/features/Sorting.ts +11 -11
- package/src/features/Visibility.ts +5 -5
- package/src/filterTypes.ts +9 -9
- package/src/sortTypes.ts +6 -6
- package/src/types.ts +34 -25
- 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 +15 -17
- package/src/utils/sortRowsFn.ts +6 -8
- package/src/utils/sortRowsQuicksortFn.ts +174 -0
package/src/filterTypes.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const filterTypes = {
|
|
|
14
14
|
|
|
15
15
|
export type BuiltInFilterType = keyof typeof filterTypes
|
|
16
16
|
|
|
17
|
-
function includesString<TGenerics extends
|
|
17
|
+
function includesString<TGenerics extends AnyGenerics>(
|
|
18
18
|
rows: Row<TGenerics>[],
|
|
19
19
|
columnIds: string[],
|
|
20
20
|
filterValue: unknown
|
|
@@ -31,7 +31,7 @@ function includesString<TGenerics extends PartialGenerics>(
|
|
|
31
31
|
|
|
32
32
|
includesString.autoRemove = (val: any) => testFalsey(val)
|
|
33
33
|
|
|
34
|
-
function includesStringSensitive<TGenerics extends
|
|
34
|
+
function includesStringSensitive<TGenerics extends AnyGenerics>(
|
|
35
35
|
rows: Row<TGenerics>[],
|
|
36
36
|
columnIds: string[],
|
|
37
37
|
filterValue: unknown
|
|
@@ -48,7 +48,7 @@ function includesStringSensitive<TGenerics extends PartialGenerics>(
|
|
|
48
48
|
|
|
49
49
|
includesStringSensitive.autoRemove = (val: any) => testFalsey(val)
|
|
50
50
|
|
|
51
|
-
function equalsString<TGenerics extends
|
|
51
|
+
function equalsString<TGenerics extends AnyGenerics>(
|
|
52
52
|
rows: Row<TGenerics>[],
|
|
53
53
|
columnIds: string[],
|
|
54
54
|
filterValue: unknown
|
|
@@ -67,7 +67,7 @@ function equalsString<TGenerics extends PartialGenerics>(
|
|
|
67
67
|
|
|
68
68
|
equalsString.autoRemove = (val: any) => testFalsey(val)
|
|
69
69
|
|
|
70
|
-
function equalsStringSensitive<TGenerics extends
|
|
70
|
+
function equalsStringSensitive<TGenerics extends AnyGenerics>(
|
|
71
71
|
rows: Row<TGenerics>[],
|
|
72
72
|
columnIds: string[],
|
|
73
73
|
filterValue: unknown
|
|
@@ -83,7 +83,7 @@ function equalsStringSensitive<TGenerics extends PartialGenerics>(
|
|
|
83
83
|
|
|
84
84
|
equalsStringSensitive.autoRemove = (val: any) => testFalsey(val)
|
|
85
85
|
|
|
86
|
-
function arrIncludes<TGenerics extends
|
|
86
|
+
function arrIncludes<TGenerics extends AnyGenerics>(
|
|
87
87
|
rows: Row<TGenerics>[],
|
|
88
88
|
columnIds: string[],
|
|
89
89
|
filterValue: unknown
|
|
@@ -98,7 +98,7 @@ function arrIncludes<TGenerics extends PartialGenerics>(
|
|
|
98
98
|
|
|
99
99
|
arrIncludes.autoRemove = (val: any) => testFalsey(val) || !val?.length
|
|
100
100
|
|
|
101
|
-
function arrIncludesAll<TGenerics extends
|
|
101
|
+
function arrIncludesAll<TGenerics extends AnyGenerics>(
|
|
102
102
|
rows: Row<TGenerics>[],
|
|
103
103
|
columnIds: string[],
|
|
104
104
|
filterValue: unknown[]
|
|
@@ -117,7 +117,7 @@ function arrIncludesAll<TGenerics extends PartialGenerics>(
|
|
|
117
117
|
|
|
118
118
|
arrIncludesAll.autoRemove = (val: any) => testFalsey(val) || !val?.length
|
|
119
119
|
|
|
120
|
-
function equals<TGenerics extends
|
|
120
|
+
function equals<TGenerics extends AnyGenerics>(
|
|
121
121
|
rows: Row<TGenerics>[],
|
|
122
122
|
columnIds: string[],
|
|
123
123
|
filterValue: unknown
|
|
@@ -132,7 +132,7 @@ function equals<TGenerics extends PartialGenerics>(
|
|
|
132
132
|
|
|
133
133
|
equals.autoRemove = (val: any) => testFalsey(val)
|
|
134
134
|
|
|
135
|
-
function weakEquals<TGenerics extends
|
|
135
|
+
function weakEquals<TGenerics extends AnyGenerics>(
|
|
136
136
|
rows: Row<TGenerics>[],
|
|
137
137
|
columnIds: string[],
|
|
138
138
|
filterValue: unknown
|
|
@@ -148,7 +148,7 @@ function weakEquals<TGenerics extends PartialGenerics>(
|
|
|
148
148
|
|
|
149
149
|
weakEquals.autoRemove = (val: any) => testFalsey(val)
|
|
150
150
|
|
|
151
|
-
function betweenNumberRange<TGenerics extends
|
|
151
|
+
function betweenNumberRange<TGenerics extends AnyGenerics>(
|
|
152
152
|
rows: Row<TGenerics>[],
|
|
153
153
|
columnIds: string[],
|
|
154
154
|
filterValue: [unknown, unknown]
|
package/src/sortTypes.ts
CHANGED
|
@@ -13,7 +13,7 @@ export const sortTypes = {
|
|
|
13
13
|
|
|
14
14
|
export type BuiltInSortType = keyof typeof sortTypes
|
|
15
15
|
|
|
16
|
-
function alphanumeric<TGenerics extends
|
|
16
|
+
function alphanumeric<TGenerics extends AnyGenerics>(
|
|
17
17
|
rowA: Row<TGenerics>,
|
|
18
18
|
rowB: Row<TGenerics>,
|
|
19
19
|
columnId: string
|
|
@@ -24,7 +24,7 @@ function alphanumeric<TGenerics extends PartialGenerics>(
|
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function alphanumericCaseSensitive<TGenerics extends
|
|
27
|
+
function alphanumericCaseSensitive<TGenerics extends AnyGenerics>(
|
|
28
28
|
rowA: Row<TGenerics>,
|
|
29
29
|
rowB: Row<TGenerics>,
|
|
30
30
|
columnId: string
|
|
@@ -84,7 +84,7 @@ function compareAlphanumeric(aStr: string, bStr: string) {
|
|
|
84
84
|
|
|
85
85
|
// The text filter is more basic (less numeric support)
|
|
86
86
|
// but is much faster
|
|
87
|
-
function text<TGenerics extends
|
|
87
|
+
function text<TGenerics extends AnyGenerics>(
|
|
88
88
|
rowA: Row<TGenerics>,
|
|
89
89
|
rowB: Row<TGenerics>,
|
|
90
90
|
columnId: string
|
|
@@ -97,7 +97,7 @@ function text<TGenerics extends PartialGenerics>(
|
|
|
97
97
|
|
|
98
98
|
// The text filter is more basic (less numeric support)
|
|
99
99
|
// but is much faster
|
|
100
|
-
function textCaseSensitive<TGenerics extends
|
|
100
|
+
function textCaseSensitive<TGenerics extends AnyGenerics>(
|
|
101
101
|
rowA: Row<TGenerics>,
|
|
102
102
|
rowB: Row<TGenerics>,
|
|
103
103
|
columnId: string
|
|
@@ -108,7 +108,7 @@ function textCaseSensitive<TGenerics extends PartialGenerics>(
|
|
|
108
108
|
)
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
function datetime<TGenerics extends
|
|
111
|
+
function datetime<TGenerics extends AnyGenerics>(
|
|
112
112
|
rowA: Row<TGenerics>,
|
|
113
113
|
rowB: Row<TGenerics>,
|
|
114
114
|
columnId: string
|
|
@@ -119,7 +119,7 @@ function datetime<TGenerics extends PartialGenerics>(
|
|
|
119
119
|
)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function basic<TGenerics extends
|
|
122
|
+
function basic<TGenerics extends AnyGenerics>(
|
|
123
123
|
rowA: Row<TGenerics>,
|
|
124
124
|
rowB: Row<TGenerics>,
|
|
125
125
|
columnId: string
|
package/src/types.ts
CHANGED
|
@@ -88,7 +88,7 @@ export type DefaultGenerics = {
|
|
|
88
88
|
|
|
89
89
|
export type AnyRender = (Comp: any, props: any) => any
|
|
90
90
|
|
|
91
|
-
export type UseRenderer<TGenerics extends
|
|
91
|
+
export type UseRenderer<TGenerics extends AnyGenerics> =
|
|
92
92
|
TGenerics['Render'] extends (...args: any) => any ? TGenerics['Render'] : any
|
|
93
93
|
|
|
94
94
|
export type PartialGenerics = Partial<DefaultGenerics>
|
|
@@ -97,7 +97,17 @@ export type AnyGenerics = {
|
|
|
97
97
|
[TKey in keyof PartialGenerics]?: any
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export type
|
|
100
|
+
export type TableFeature = {
|
|
101
|
+
getDefaultOptions?: (instance: any) => any
|
|
102
|
+
getInitialState?: () => any
|
|
103
|
+
getInstance?: (instance: any) => any
|
|
104
|
+
getDefaultColumn?: () => any
|
|
105
|
+
createColumn?: (column: any, instance: any) => any
|
|
106
|
+
createCell?: (cell: any, column: any, row: any, instance: any) => any
|
|
107
|
+
createRow?: (row: any, instance: any) => any
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type TableInstance<TGenerics extends AnyGenerics> =
|
|
101
111
|
TableCore<TGenerics> &
|
|
102
112
|
VisibilityInstance<TGenerics> &
|
|
103
113
|
ColumnOrderInstance<TGenerics> &
|
|
@@ -113,18 +123,17 @@ export type TableInstance<TGenerics extends PartialGenerics> =
|
|
|
113
123
|
|
|
114
124
|
//
|
|
115
125
|
|
|
116
|
-
export type Options<TGenerics extends
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
RowSelectionOptions<TGenerics>
|
|
126
|
+
export type Options<TGenerics extends AnyGenerics> = CoreOptions<TGenerics> &
|
|
127
|
+
VisibilityOptions &
|
|
128
|
+
ColumnOrderOptions &
|
|
129
|
+
ColumnPinningOptions &
|
|
130
|
+
FiltersOptions<TGenerics> &
|
|
131
|
+
SortingOptions<TGenerics> &
|
|
132
|
+
GroupingOptions<TGenerics> &
|
|
133
|
+
ExpandedOptions<TGenerics> &
|
|
134
|
+
ColumnSizingOptions &
|
|
135
|
+
PaginationOptions<TGenerics> &
|
|
136
|
+
RowSelectionOptions<TGenerics>
|
|
128
137
|
|
|
129
138
|
export type Updater<T> = T | ((old: T) => T)
|
|
130
139
|
export type OnChangeFn<T> = (updaterOrValue: Updater<T>, value: T) => void
|
|
@@ -140,7 +149,7 @@ export type TableState = VisibilityTableState &
|
|
|
140
149
|
PaginationTableState &
|
|
141
150
|
RowSelectionTableState
|
|
142
151
|
|
|
143
|
-
export type Row<TGenerics extends
|
|
152
|
+
export type Row<TGenerics extends AnyGenerics> = CoreRow<TGenerics> &
|
|
144
153
|
VisibilityRow<TGenerics> &
|
|
145
154
|
HeadersRow<TGenerics> &
|
|
146
155
|
GroupingRow &
|
|
@@ -151,7 +160,7 @@ export type RowValues = {
|
|
|
151
160
|
[key: string]: any
|
|
152
161
|
}
|
|
153
162
|
|
|
154
|
-
export type RowModel<TGenerics extends
|
|
163
|
+
export type RowModel<TGenerics extends AnyGenerics> = {
|
|
155
164
|
rows: Row<TGenerics>[]
|
|
156
165
|
flatRows: Row<TGenerics>[]
|
|
157
166
|
rowsById: Record<string, Row<TGenerics>>
|
|
@@ -159,7 +168,7 @@ export type RowModel<TGenerics extends PartialGenerics> = {
|
|
|
159
168
|
|
|
160
169
|
export type AccessorFn<TData> = (originalRow: TData, index: number) => any
|
|
161
170
|
|
|
162
|
-
// export type UserColumnDef<TGenerics extends
|
|
171
|
+
// export type UserColumnDef<TGenerics extends AnyGenerics> = Overwrite<
|
|
163
172
|
// ColumnDef<TGenerics>,
|
|
164
173
|
// GeneratedProperties<false>
|
|
165
174
|
// >
|
|
@@ -178,11 +187,11 @@ export type AccessorFn<TData> = (originalRow: TData, index: number) => any
|
|
|
178
187
|
// }
|
|
179
188
|
// : never
|
|
180
189
|
|
|
181
|
-
export type Renderable<TGenerics extends
|
|
190
|
+
export type Renderable<TGenerics extends AnyGenerics, TProps> =
|
|
182
191
|
| string
|
|
183
192
|
| ((props: TProps) => ReturnType<UseRenderer<TGenerics>>)
|
|
184
193
|
|
|
185
|
-
export type ColumnDef<TGenerics extends
|
|
194
|
+
export type ColumnDef<TGenerics extends AnyGenerics> =
|
|
186
195
|
CoreColumnDef<TGenerics> &
|
|
187
196
|
VisibilityColumnDef &
|
|
188
197
|
ColumnPinningColumnDef &
|
|
@@ -191,7 +200,7 @@ export type ColumnDef<TGenerics extends PartialGenerics> =
|
|
|
191
200
|
GroupingColumnDef<TGenerics> &
|
|
192
201
|
ColumnSizingColumnDef
|
|
193
202
|
|
|
194
|
-
export type Column<TGenerics extends
|
|
203
|
+
export type Column<TGenerics extends AnyGenerics> = ColumnDef<TGenerics> &
|
|
195
204
|
CoreColumn<TGenerics> &
|
|
196
205
|
ColumnVisibilityColumn &
|
|
197
206
|
ColumnPinningColumn &
|
|
@@ -200,10 +209,10 @@ export type Column<TGenerics extends PartialGenerics> = ColumnDef<TGenerics> &
|
|
|
200
209
|
GroupingColumn<TGenerics> &
|
|
201
210
|
ColumnSizingColumn<TGenerics>
|
|
202
211
|
|
|
203
|
-
export type Cell<TGenerics extends
|
|
212
|
+
export type Cell<TGenerics extends AnyGenerics> = CoreCell<TGenerics> &
|
|
204
213
|
GroupingCell<TGenerics>
|
|
205
214
|
|
|
206
|
-
export type CoreCell<TGenerics extends
|
|
215
|
+
export type CoreCell<TGenerics extends AnyGenerics> = {
|
|
207
216
|
id: string
|
|
208
217
|
rowId: string
|
|
209
218
|
columnId: string
|
|
@@ -214,10 +223,10 @@ export type CoreCell<TGenerics extends PartialGenerics> = {
|
|
|
214
223
|
renderCell: () => string | null | ReturnType<UseRenderer<TGenerics>>
|
|
215
224
|
}
|
|
216
225
|
|
|
217
|
-
export type Header<TGenerics extends
|
|
226
|
+
export type Header<TGenerics extends AnyGenerics> = CoreHeader<TGenerics> &
|
|
218
227
|
ColumnSizingHeader<TGenerics>
|
|
219
228
|
|
|
220
|
-
export type CoreHeader<TGenerics extends
|
|
229
|
+
export type CoreHeader<TGenerics extends AnyGenerics> = {
|
|
221
230
|
id: string
|
|
222
231
|
depth: number
|
|
223
232
|
column: Column<TGenerics>
|
|
@@ -238,7 +247,7 @@ export type CoreHeader<TGenerics extends PartialGenerics> = {
|
|
|
238
247
|
}) => string | null | ReturnType<UseRenderer<TGenerics>>
|
|
239
248
|
}
|
|
240
249
|
|
|
241
|
-
export type HeaderGroup<TGenerics extends
|
|
250
|
+
export type HeaderGroup<TGenerics extends AnyGenerics> = {
|
|
242
251
|
id: string
|
|
243
252
|
depth: number
|
|
244
253
|
headers: Header<TGenerics>[]
|
|
@@ -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)
|
|
@@ -157,7 +155,7 @@ export function groupRowsFn<TGenerics extends AnyGenerics>(
|
|
|
157
155
|
}
|
|
158
156
|
}
|
|
159
157
|
|
|
160
|
-
function groupBy<TGenerics extends
|
|
158
|
+
function groupBy<TGenerics extends AnyGenerics>(
|
|
161
159
|
rows: Row<TGenerics>[],
|
|
162
160
|
columnId: string
|
|
163
161
|
) {
|
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
|
|