@tanstack/react-table 8.0.0-alpha.2 → 8.0.0-alpha.22

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.
Files changed (99) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -78
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  3. package/build/cjs/index.js +96 -12
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.js +40 -3663
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +28 -676
  9. package/build/types/index.d.ts +13 -7
  10. package/build/umd/index.development.js +50 -3665
  11. package/build/umd/index.development.js.map +1 -1
  12. package/build/umd/index.production.js +1 -1
  13. package/build/umd/index.production.js.map +1 -1
  14. package/package.json +4 -1
  15. package/src/index.tsx +104 -7
  16. package/build/cjs/aggregationTypes.js +0 -130
  17. package/build/cjs/aggregationTypes.js.map +0 -1
  18. package/build/cjs/core.js +0 -519
  19. package/build/cjs/core.js.map +0 -1
  20. package/build/cjs/createTable.js +0 -103
  21. package/build/cjs/createTable.js.map +0 -1
  22. package/build/cjs/features/ColumnSizing.js +0 -331
  23. package/build/cjs/features/ColumnSizing.js.map +0 -1
  24. package/build/cjs/features/Expanding.js +0 -234
  25. package/build/cjs/features/Expanding.js.map +0 -1
  26. package/build/cjs/features/Filters.js +0 -396
  27. package/build/cjs/features/Filters.js.map +0 -1
  28. package/build/cjs/features/Grouping.js +0 -228
  29. package/build/cjs/features/Grouping.js.map +0 -1
  30. package/build/cjs/features/Headers.js +0 -486
  31. package/build/cjs/features/Headers.js.map +0 -1
  32. package/build/cjs/features/Ordering.js +0 -83
  33. package/build/cjs/features/Ordering.js.map +0 -1
  34. package/build/cjs/features/Pinning.js +0 -163
  35. package/build/cjs/features/Pinning.js.map +0 -1
  36. package/build/cjs/features/Sorting.js +0 -269
  37. package/build/cjs/features/Sorting.js.map +0 -1
  38. package/build/cjs/features/Visibility.js +0 -160
  39. package/build/cjs/features/Visibility.js.map +0 -1
  40. package/build/cjs/filterTypes.js +0 -172
  41. package/build/cjs/filterTypes.js.map +0 -1
  42. package/build/cjs/sortTypes.js +0 -121
  43. package/build/cjs/sortTypes.js.map +0 -1
  44. package/build/cjs/utils/columnFilterRowsFn.js +0 -130
  45. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  46. package/build/cjs/utils/expandRowsFn.js +0 -38
  47. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  48. package/build/cjs/utils/globalFilterRowsFn.js +0 -100
  49. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  50. package/build/cjs/utils/groupRowsFn.js +0 -154
  51. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  52. package/build/cjs/utils/sortRowsFn.js +0 -93
  53. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  54. package/build/cjs/utils.js +0 -143
  55. package/build/cjs/utils.js.map +0 -1
  56. package/build/types/aggregationTypes.d.ts +0 -22
  57. package/build/types/core.d.ts +0 -126
  58. package/build/types/createTable.d.ts +0 -35
  59. package/build/types/features/ColumnSizing.d.ts +0 -73
  60. package/build/types/features/Expanding.d.ts +0 -52
  61. package/build/types/features/Filters.d.ts +0 -93
  62. package/build/types/features/Grouping.d.ts +0 -82
  63. package/build/types/features/Headers.d.ts +0 -41
  64. package/build/types/features/Ordering.d.ts +0 -19
  65. package/build/types/features/Pinning.d.ts +0 -39
  66. package/build/types/features/Sorting.d.ts +0 -75
  67. package/build/types/features/Visibility.d.ts +0 -47
  68. package/build/types/filterTypes.d.ts +0 -50
  69. package/build/types/sortTypes.d.ts +0 -17
  70. package/build/types/types.d.ts +0 -124
  71. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  72. package/build/types/utils/expandRowsFn.d.ts +0 -2
  73. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  74. package/build/types/utils/groupRowsFn.d.ts +0 -2
  75. package/build/types/utils/sortRowsFn.d.ts +0 -2
  76. package/build/types/utils.d.ts +0 -24
  77. package/src/aggregationTypes.ts +0 -115
  78. package/src/core.tsx +0 -1232
  79. package/src/createTable.tsx +0 -181
  80. package/src/features/ColumnSizing.ts +0 -482
  81. package/src/features/Expanding.ts +0 -388
  82. package/src/features/Filters.ts +0 -707
  83. package/src/features/Grouping.ts +0 -451
  84. package/src/features/Headers.ts +0 -944
  85. package/src/features/Ordering.ts +0 -134
  86. package/src/features/Pinning.ts +0 -213
  87. package/src/features/Sorting.ts +0 -487
  88. package/src/features/Visibility.ts +0 -281
  89. package/src/features/withPagination.oldts +0 -208
  90. package/src/features/withRowSelection.oldts +0 -467
  91. package/src/filterTypes.ts +0 -251
  92. package/src/sortTypes.ts +0 -159
  93. package/src/types.ts +0 -314
  94. package/src/utils/columnFilterRowsFn.ts +0 -162
  95. package/src/utils/expandRowsFn.ts +0 -53
  96. package/src/utils/globalFilterRowsFn.ts +0 -129
  97. package/src/utils/groupRowsFn.ts +0 -196
  98. package/src/utils/sortRowsFn.ts +0 -115
  99. package/src/utils.tsx +0 -249
package/src/sortTypes.ts DELETED
@@ -1,159 +0,0 @@
1
- import { Row } from './types'
2
-
3
- const reSplitAlphaNumeric = /([0-9]+)/gm
4
-
5
- export const sortTypes = {
6
- alphanumeric,
7
- alphanumericCaseSensitive,
8
- text,
9
- textCaseSensitive,
10
- datetime,
11
- basic,
12
- }
13
-
14
- export type BuiltInSortType = keyof typeof sortTypes
15
-
16
- function alphanumeric<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>(
17
- rowA: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
18
- rowB: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
19
- columnId: string
20
- ) {
21
- return compareAlphanumeric(
22
- toString(rowA.values[columnId]).toLowerCase(),
23
- toString(rowB.values[columnId]).toLowerCase()
24
- )
25
- }
26
-
27
- function alphanumericCaseSensitive<
28
- TData,
29
- TValue,
30
- TFilterFns,
31
- TSortingFns,
32
- TAggregationFns
33
- >(
34
- rowA: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
35
- rowB: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
36
- columnId: string
37
- ) {
38
- return compareAlphanumeric(
39
- toString(rowA.values[columnId]),
40
- toString(rowB.values[columnId])
41
- )
42
- }
43
-
44
- // Mixed sorting is slow, but very inclusive of many edge cases.
45
- // It handles numbers, mixed alphanumeric combinations, and even
46
- // null, undefined, and Infinity
47
- function compareAlphanumeric(aStr: string, bStr: string) {
48
- // Split on number groups, but keep the delimiter
49
- // Then remove falsey split values
50
- const a = aStr.split(reSplitAlphaNumeric).filter(Boolean)
51
- const b = bStr.split(reSplitAlphaNumeric).filter(Boolean)
52
-
53
- // While
54
- while (a.length && b.length) {
55
- const aa = a.shift()!
56
- const bb = b.shift()!
57
-
58
- const an = parseInt(aa, 10)
59
- const bn = parseInt(bb, 10)
60
-
61
- const combo = [an, bn].sort()
62
-
63
- // Both are string
64
- if (isNaN(combo[0]!)) {
65
- if (aa > bb) {
66
- return 1
67
- }
68
- if (bb > aa) {
69
- return -1
70
- }
71
- continue
72
- }
73
-
74
- // One is a string, one is a number
75
- if (isNaN(combo[1]!)) {
76
- return isNaN(an) ? -1 : 1
77
- }
78
-
79
- // Both are numbers
80
- if (an > bn) {
81
- return 1
82
- }
83
- if (bn > an) {
84
- return -1
85
- }
86
- }
87
-
88
- return a.length - b.length
89
- }
90
-
91
- // The text filter is more basic (less numeric support)
92
- // but is much faster
93
- function text<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>(
94
- rowA: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
95
- rowB: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
96
- columnId: string
97
- ) {
98
- return compareBasic(
99
- toString(rowA.values[columnId]).toLowerCase(),
100
- toString(rowB.values[columnId]).toLowerCase()
101
- )
102
- }
103
-
104
- // The text filter is more basic (less numeric support)
105
- // but is much faster
106
- function textCaseSensitive<
107
- TData,
108
- TValue,
109
- TFilterFns,
110
- TSortingFns,
111
- TAggregationFns
112
- >(
113
- rowA: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
114
- rowB: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
115
- columnId: string
116
- ) {
117
- return compareBasic(
118
- toString(rowA.values[columnId]),
119
- toString(rowB.values[columnId])
120
- )
121
- }
122
-
123
- function datetime<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>(
124
- rowA: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
125
- rowB: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
126
- columnId: string
127
- ) {
128
- return compareBasic(
129
- (rowA.values[columnId] as Date).getTime(),
130
- (rowB.values[columnId] as Date).getTime()
131
- )
132
- }
133
-
134
- function basic<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>(
135
- rowA: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
136
- rowB: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
137
- columnId: string
138
- ) {
139
- return compareBasic(rowA.values[columnId], rowB.values[columnId])
140
- }
141
-
142
- // Utils
143
-
144
- function compareBasic(a: any, b: any) {
145
- return a === b ? 0 : a > b ? 1 : -1
146
- }
147
-
148
- function toString(a: any) {
149
- if (typeof a === 'number') {
150
- if (isNaN(a) || a === Infinity || a === -Infinity) {
151
- return ''
152
- }
153
- return String(a)
154
- }
155
- if (typeof a === 'string') {
156
- return a
157
- }
158
- return ''
159
- }
package/src/types.ts DELETED
@@ -1,314 +0,0 @@
1
- import React from 'react'
2
- // import * as TS from 'ts-toolbelt'
3
- import {
4
- CoreColumn,
5
- CoreColumnDef,
6
- CoreOptions,
7
- CoreRow,
8
- TableCore,
9
- } from './core'
10
- import {
11
- VisibilityInstance,
12
- VisibilityTableState,
13
- VisibilityColumn as ColumnVisibilityColumn,
14
- VisibilityOptions,
15
- VisibilityColumnDef,
16
- VisibilityRow,
17
- } from './features/Visibility'
18
- import {
19
- ColumnOrderInstance,
20
- ColumnOrderOptions,
21
- ColumnOrderTableState,
22
- } from './features/Ordering'
23
- import {
24
- ColumnPinningColumn,
25
- ColumnPinningColumnDef,
26
- ColumnPinningInstance,
27
- ColumnPinningOptions,
28
- ColumnPinningTableState,
29
- } from './features/Pinning'
30
- import { HeadersInstance, HeadersRow } from './features/Headers'
31
- import {
32
- FiltersColumn,
33
- FiltersColumnDef,
34
- FiltersInstance,
35
- FiltersOptions,
36
- FiltersTableState,
37
- } from './features/Filters'
38
- import {
39
- SortingColumn,
40
- SortingColumnDef,
41
- SortingInstance,
42
- SortingOptions,
43
- SortingTableState,
44
- } from './features/Sorting'
45
- import {
46
- GroupingColumn,
47
- GroupingColumnDef,
48
- GroupingInstance,
49
- GroupingOptions,
50
- GroupingRow,
51
- GroupingTableState,
52
- } from './features/Grouping'
53
- import {
54
- ExpandedInstance,
55
- ExpandedOptions,
56
- ExpandedTableState,
57
- } from './features/Expanding'
58
- import { Overwrite } from './utils'
59
- import {
60
- ColumnSizingColumn,
61
- ColumnSizingColumnDef,
62
- ColumnSizingHeader,
63
- ColumnSizingInstance,
64
- ColumnSizingOptions,
65
- ColumnSizingTableState,
66
- } from './features/ColumnSizing'
67
-
68
- // declare global {
69
- // const process.env.NODE_ENV !== 'production': boolean
70
- // }
71
-
72
- export type ReactTable<
73
- TData,
74
- TValue,
75
- TFilterFns,
76
- TSortingFns,
77
- TAggregationFns
78
- > = TableCore<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
79
- VisibilityInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
80
- ColumnOrderInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
81
- ColumnPinningInstance<
82
- TData,
83
- TValue,
84
- TFilterFns,
85
- TSortingFns,
86
- TAggregationFns
87
- > &
88
- HeadersInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
89
- FiltersInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
90
- SortingInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
91
- GroupingInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
92
- ColumnSizingInstance<
93
- TData,
94
- TValue,
95
- TFilterFns,
96
- TSortingFns,
97
- TAggregationFns
98
- > &
99
- ExpandedInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
100
-
101
- export type Renderable<TProps> =
102
- | React.ReactNode
103
- | React.FunctionComponent<TProps>
104
- | React.Component<TProps>
105
-
106
- //
107
-
108
- export type Options<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
109
- CoreOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
110
- VisibilityOptions &
111
- ColumnOrderOptions &
112
- ColumnPinningOptions &
113
- FiltersOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
114
- SortingOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
115
- GroupingOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
116
- ExpandedOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
117
- ColumnSizingOptions
118
-
119
- export type Updater<T> = T | ((old: T) => T)
120
- export type OnChangeFn<T> = (updaterOrValue: Updater<T>, value: T) => void
121
-
122
- export type TableState = VisibilityTableState &
123
- ColumnOrderTableState &
124
- ColumnPinningTableState &
125
- FiltersTableState &
126
- SortingTableState &
127
- ExpandedTableState &
128
- GroupingTableState &
129
- ColumnSizingTableState
130
-
131
- export type Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
132
- CoreRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
133
- VisibilityRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
134
- HeadersRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
135
- GroupingRow
136
-
137
- export type RowValues = {
138
- [key: string]: any
139
- }
140
-
141
- export type RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
142
- {
143
- rows: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[]
144
- flatRows: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[]
145
- rowsById: Record<
146
- string,
147
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
148
- >
149
- }
150
-
151
- export type AccessorFn<TData> = (originalRow: TData, index: number) => any
152
-
153
- export type ColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
154
- CoreColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
155
- VisibilityColumnDef &
156
- ColumnPinningColumnDef &
157
- FiltersColumnDef<TFilterFns> &
158
- SortingColumnDef<TSortingFns> &
159
- GroupingColumnDef<TAggregationFns> &
160
- ColumnSizingColumnDef
161
-
162
- export type Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
163
- ColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
164
- CoreColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
165
- ColumnVisibilityColumn &
166
- ColumnPinningColumn &
167
- FiltersColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
168
- SortingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
169
- GroupingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
170
- ColumnSizingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
171
-
172
- export type Cell<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> = {
173
- id: string
174
- rowId: string
175
- columnId: string
176
- value: TValue
177
- row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
178
- column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
179
- getCellProps: PropGetter<CellProps>
180
- renderCell: () => React.ReactNode
181
- }
182
-
183
- export type Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
184
- CoreHeader<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
185
- ColumnSizingHeader<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
186
-
187
- export type CoreHeader<
188
- TData,
189
- TValue,
190
- TFilterFns,
191
- TSortingFns,
192
- TAggregationFns
193
- > = {
194
- id: string
195
- depth: number
196
- column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
197
- getWidth: () => number
198
- subHeaders: Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[]
199
- colSpan?: number
200
- rowSpan?: number
201
- getHeaderProps: PropGetter<HeaderProps>
202
- getFooterProps: PropGetter<HeaderProps>
203
- getLeafHeaders: () => Header<
204
- TData,
205
- TValue,
206
- TFilterFns,
207
- TSortingFns,
208
- TAggregationFns
209
- >[]
210
- isPlaceholder?: boolean
211
- placeholderId?: string
212
- renderHeader: (options?: { renderPlaceholder?: boolean }) => React.ReactNode
213
- renderFooter: (options?: { renderPlaceholder?: boolean }) => React.ReactNode
214
- }
215
-
216
- export type HeaderGroup<
217
- TData,
218
- TValue,
219
- TFilterFns,
220
- TSortingFns,
221
- TAggregationFns
222
- > = {
223
- id: string
224
- depth: number
225
- headers: Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>[]
226
- getHeaderGroupProps: PropGetter<HeaderGroupProps>
227
- getFooterGroupProps: PropGetter<FooterGroupProps>
228
- }
229
-
230
- export type HeaderRenderProps<THeader> = {
231
- header: THeader
232
- }
233
-
234
- export type FooterRenderProps<THeader> = {
235
- header: THeader
236
- }
237
-
238
- export type CellRenderProps<TCell, TRow> = {
239
- cell: TCell
240
- row: TRow
241
- }
242
-
243
- export type TableProps = {
244
- role: string
245
- }
246
-
247
- export type TableBodyProps = {
248
- role: string
249
- }
250
-
251
- export type TableHeadProps = {
252
- key: string
253
- role: string
254
- }
255
-
256
- export type TableFooterProps = {
257
- key: string
258
- role: string
259
- }
260
-
261
- export type HeaderGroupProps = {
262
- key: string
263
- role: string
264
- }
265
-
266
- export type FooterGroupProps = {
267
- key: string
268
- role: string
269
- }
270
-
271
- export type HeaderProps = {
272
- key: string
273
- role: string
274
- colSpan?: number
275
- rowSpan?: number
276
- }
277
-
278
- export type FooterProps = {
279
- key: string
280
- role: string
281
- colSpan?: number
282
- rowSpan?: number
283
- }
284
-
285
- export type RowProps = {
286
- key: string
287
- role: string
288
- }
289
-
290
- export type CellProps = {
291
- key: string
292
- role: string
293
- }
294
-
295
- //
296
-
297
- export type PropGetter<TBase> = <TGetter extends Getter<TBase>>(
298
- userProps?: TGetter
299
- ) => PropGetterValue<TBase, TGetter>
300
-
301
- export type Getter<TInitial> =
302
- | ((initial: TInitial) => object)
303
- | object
304
- | undefined
305
-
306
- export type PropGetterValue<TBase, TGetter> = TGetter extends undefined
307
- ? TBase
308
- : TGetter extends (...args: any[]) => infer TReturn
309
- ? Overwrite<TBase, TReturn>
310
- : TGetter extends object
311
- ? Overwrite<TBase, TGetter>
312
- : never
313
-
314
- export type NoInfer<A extends any> = [A][A extends any ? 0 : never]
@@ -1,162 +0,0 @@
1
- import { ReactTable, Row, RowModel } from '../types'
2
- import { ColumnFiltersState } from '../features/Filters'
3
- import { Options } from '..'
4
-
5
- export const columnFilterRowsFn: Options<
6
- any,
7
- any,
8
- {},
9
- {},
10
- {}
11
- >['columnFilterRowsFn'] = <
12
- TData,
13
- TValue,
14
- TFilterFns,
15
- TSortingFns,
16
- TAggregationFns
17
- >(
18
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
19
- columnFilters: ColumnFiltersState,
20
- rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
21
- ): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> => {
22
- const newFilteredFlatRows: Row<
23
- TData,
24
- TValue,
25
- TFilterFns,
26
- TSortingFns,
27
- TAggregationFns
28
- >[] = []
29
- const newFilteredRowsById: Record<
30
- string,
31
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
32
- > = {}
33
-
34
- const filterFromChildrenUp = instance.options.filterFromChildrenUp
35
-
36
- const filterRows = (
37
- rowsToFilter: Row<
38
- TData,
39
- TValue,
40
- TFilterFns,
41
- TSortingFns,
42
- TAggregationFns
43
- >[],
44
- depth: number
45
- ) => {
46
- columnFilters.forEach(({ id: columnId, value: filterValue }) => {
47
- // Find the columnFilters column
48
- const column = instance.getColumn(columnId)
49
-
50
- if (!column) {
51
- if (process.env.NODE_ENV !== 'production') {
52
- console.warn(
53
- `React-Table: Could not find a column with id: ${columnId}`
54
- )
55
- }
56
- throw new Error()
57
- }
58
-
59
- if (depth === 0) {
60
- const preFilteredRows = [...rowsToFilter]
61
- column.getPreFilteredRows = () => preFilteredRows
62
- }
63
-
64
- const filterFn = instance.getColumnFilterFn(column.id)
65
-
66
- if (!filterFn) {
67
- if (process.env.NODE_ENV !== 'production') {
68
- console.warn(
69
- `Could not find a valid 'column.filterType' for column with the ID: ${column.id}.`
70
- )
71
- }
72
- return
73
- }
74
-
75
- // Pass the rows, id, filterValue and column to the filterFn
76
- // to get the filtered rows back
77
- rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue)
78
- })
79
-
80
- return rowsToFilter
81
- }
82
-
83
- if (filterFromChildrenUp) {
84
- const recurseFilterRows = (
85
- rowsToFilter: Row<
86
- TData,
87
- TValue,
88
- TFilterFns,
89
- TSortingFns,
90
- TAggregationFns
91
- >[],
92
- depth = 0
93
- ) => {
94
- // Filter from children up
95
- rowsToFilter = rowsToFilter.filter(row => {
96
- if (!row.subRows?.length) {
97
- return true
98
- }
99
-
100
- row.subRows = recurseFilterRows(row.subRows, depth + 1)
101
-
102
- return row.subRows.length
103
- })
104
-
105
- rowsToFilter = filterRows(rowsToFilter, depth)
106
-
107
- // Apply the filter to any subRows
108
- rowsToFilter.forEach(row => {
109
- newFilteredFlatRows.push(row)
110
- newFilteredRowsById[row.id] = row
111
- })
112
-
113
- return rowsToFilter
114
- }
115
-
116
- return {
117
- rows: recurseFilterRows(rowModel.rows),
118
- flatRows: newFilteredFlatRows,
119
- rowsById: newFilteredRowsById,
120
- }
121
- }
122
-
123
- // Filters top level and nested rows
124
- const recurseFilterRows = (
125
- rowsToFilter: Row<
126
- TData,
127
- TValue,
128
- TFilterFns,
129
- TSortingFns,
130
- TAggregationFns
131
- >[],
132
- depth = 0
133
- ) => {
134
- // Filter from parents downward
135
- rowsToFilter = filterRows(rowsToFilter, depth)
136
-
137
- // Apply the filter to any subRows
138
- // We technically could do this recursively in the above loop,
139
- // but that would severely hinder the API for the user, since they
140
- // would be required to do that recursion in some scenarios
141
- rowsToFilter.forEach(row => {
142
- newFilteredFlatRows.push(row)
143
- newFilteredRowsById[row.id] = row
144
-
145
- if (!filterFromChildrenUp) {
146
- if (!row.subRows?.length) {
147
- return
148
- }
149
-
150
- row.subRows = recurseFilterRows(row.subRows, depth + 1)
151
- }
152
- })
153
-
154
- return rowsToFilter
155
- }
156
-
157
- return {
158
- rows: recurseFilterRows(rowModel.rows),
159
- flatRows: newFilteredFlatRows,
160
- rowsById: newFilteredRowsById,
161
- }
162
- }
@@ -1,53 +0,0 @@
1
- import { ReactTable, Row, RowModel } from '../types'
2
- import { Options } from '../types'
3
- import { ExpandedState } from '../features/Expanding'
4
-
5
- export const expandRowsFn: Options<any, any, {}, {}, {}>['expandRowsFn'] = <
6
- TData,
7
- TValue,
8
- TFilterFns,
9
- TSortingFns,
10
- TAggregationFns
11
- >(
12
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
13
- _expandedState: ExpandedState,
14
- sortedRowModel: RowModel<
15
- TData,
16
- TValue,
17
- TFilterFns,
18
- TSortingFns,
19
- TAggregationFns
20
- >
21
- ): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> => {
22
- const expandedRows: Row<
23
- TData,
24
- TValue,
25
- TFilterFns,
26
- TSortingFns,
27
- TAggregationFns
28
- >[] = []
29
-
30
- const { expandSubRows } = instance.options
31
-
32
- const handleRow = (
33
- row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
34
- ) => {
35
- expandedRows.push(row)
36
-
37
- if (
38
- expandSubRows &&
39
- row.subRows?.length &&
40
- instance.getIsRowExpanded(row.id)
41
- ) {
42
- row.subRows.forEach(handleRow)
43
- }
44
- }
45
-
46
- sortedRowModel.rows.forEach(handleRow)
47
-
48
- return {
49
- rows: expandedRows,
50
- flatRows: sortedRowModel.flatRows,
51
- rowsById: sortedRowModel.rowsById,
52
- }
53
- }