@tanstack/react-table 8.0.0-alpha.7 → 8.0.0-alpha.70

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