@tanstack/react-table 8.0.0-alpha.8 → 8.0.0-alpha.80
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/react-table/src/index.js +133 -0
- package/build/cjs/react-table/src/index.js.map +1 -0
- package/build/cjs/table-core/build/esm/index.js +3951 -0
- package/build/cjs/table-core/build/esm/index.js.map +1 -0
- package/build/esm/index.js +3253 -4059
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +24 -797
- package/build/types/index.d.ts +16 -8
- package/build/umd/index.development.js +3349 -4124
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +11 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +7 -9
- package/src/index.tsx +113 -8
- 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 -560
- package/build/cjs/core.js.map +0 -1
- package/build/cjs/createTable.js +0 -108
- package/build/cjs/createTable.js.map +0 -1
- package/build/cjs/features/ColumnSizing.js +0 -317
- package/build/cjs/features/ColumnSizing.js.map +0 -1
- package/build/cjs/features/Expanding.js +0 -251
- package/build/cjs/features/Expanding.js.map +0 -1
- package/build/cjs/features/Filters.js +0 -445
- package/build/cjs/features/Filters.js.map +0 -1
- package/build/cjs/features/Grouping.js +0 -249
- package/build/cjs/features/Grouping.js.map +0 -1
- package/build/cjs/features/Headers.js +0 -549
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/features/Ordering.js +0 -86
- package/build/cjs/features/Ordering.js.map +0 -1
- package/build/cjs/features/Pagination.js +0 -198
- package/build/cjs/features/Pagination.js.map +0 -1
- package/build/cjs/features/Pinning.js +0 -149
- package/build/cjs/features/Pinning.js.map +0 -1
- package/build/cjs/features/RowSelection.js +0 -541
- package/build/cjs/features/RowSelection.js.map +0 -1
- package/build/cjs/features/Sorting.js +0 -327
- package/build/cjs/features/Sorting.js.map +0 -1
- package/build/cjs/features/Visibility.js +0 -166
- package/build/cjs/features/Visibility.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/index.js +0 -32
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/sortTypes.js +0 -122
- package/build/cjs/sortTypes.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/cjs/utils.js +0 -141
- package/build/cjs/utils.js.map +0 -1
- package/build/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -110
- package/build/types/createTable.d.ts +0 -52
- package/build/types/features/ColumnSizing.d.ts +0 -67
- package/build/types/features/Expanding.d.ts +0 -53
- package/build/types/features/Filters.d.ts +0 -98
- package/build/types/features/Grouping.d.ts +0 -82
- package/build/types/features/Headers.d.ts +0 -41
- package/build/types/features/Ordering.d.ts +0 -19
- package/build/types/features/Pagination.d.ts +0 -44
- package/build/types/features/Pinning.d.ts +0 -39
- package/build/types/features/RowSelection.d.ts +0 -66
- package/build/types/features/Sorting.d.ts +0 -78
- package/build/types/features/Visibility.d.ts +0 -47
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- package/build/types/types.d.ts +0 -127
- 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/build/types/utils.d.ts +0 -24
- package/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -1096
- package/src/createTable.tsx +0 -244
- package/src/features/ColumnSizing.ts +0 -453
- package/src/features/Expanding.ts +0 -406
- package/src/features/Filters.ts +0 -762
- package/src/features/Grouping.ts +0 -466
- package/src/features/Headers.ts +0 -912
- package/src/features/Ordering.ts +0 -133
- package/src/features/Pagination.ts +0 -325
- package/src/features/Pinning.ts +0 -198
- package/src/features/RowSelection.ts +0 -831
- package/src/features/Sorting.ts +0 -547
- package/src/features/Visibility.ts +0 -279
- package/src/filterTypes.ts +0 -251
- package/src/sortTypes.ts +0 -159
- package/src/types.ts +0 -331
- package/src/utils/columnFilterRowsFn.ts +0 -155
- package/src/utils/expandRowsFn.ts +0 -50
- package/src/utils/globalFilterRowsFn.ts +0 -122
- package/src/utils/groupRowsFn.ts +0 -194
- package/src/utils/paginateRowsFn.ts +0 -34
- package/src/utils/sortRowsFn.ts +0 -115
- package/src/utils.tsx +0 -195
package/src/features/Grouping.ts
DELETED
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
import React, { MouseEvent, TouchEvent } from 'react'
|
|
2
|
-
import { RowModel } from '..'
|
|
3
|
-
import { BuiltInAggregationType, aggregationTypes } from '../aggregationTypes'
|
|
4
|
-
import {
|
|
5
|
-
Cell,
|
|
6
|
-
Column,
|
|
7
|
-
Getter,
|
|
8
|
-
OnChangeFn,
|
|
9
|
-
PropGetterValue,
|
|
10
|
-
ReactTable,
|
|
11
|
-
Row,
|
|
12
|
-
Updater,
|
|
13
|
-
} from '../types'
|
|
14
|
-
import {
|
|
15
|
-
functionalUpdate,
|
|
16
|
-
isFunction,
|
|
17
|
-
makeStateUpdater,
|
|
18
|
-
memo,
|
|
19
|
-
propGetter,
|
|
20
|
-
} from '../utils'
|
|
21
|
-
|
|
22
|
-
export type GroupingState = string[]
|
|
23
|
-
|
|
24
|
-
export type AggregationFn = (leafValues: any[], childValues: any[]) => any
|
|
25
|
-
|
|
26
|
-
export type AggregationType<TAggregationFns> =
|
|
27
|
-
| 'auto'
|
|
28
|
-
| BuiltInAggregationType
|
|
29
|
-
| keyof TAggregationFns
|
|
30
|
-
| AggregationFn
|
|
31
|
-
|
|
32
|
-
export type GroupingTableState = {
|
|
33
|
-
grouping: GroupingState
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type GroupingColumnDef<TAggregationFns> = {
|
|
37
|
-
aggregationType?: AggregationType<TAggregationFns>
|
|
38
|
-
aggregateValue?: (columnValue: unknown) => any
|
|
39
|
-
renderAggregatedCell?: () => React.ReactNode
|
|
40
|
-
enableGrouping?: boolean
|
|
41
|
-
defaultCanGroup?: boolean
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export type GroupingColumn<
|
|
45
|
-
_TData,
|
|
46
|
-
_TValue,
|
|
47
|
-
_TFilterFns,
|
|
48
|
-
_TSortingFns,
|
|
49
|
-
TAggregationFns
|
|
50
|
-
> = {
|
|
51
|
-
aggregationType?: AggregationType<TAggregationFns>
|
|
52
|
-
getCanGroup: () => boolean
|
|
53
|
-
getIsGrouped: () => boolean
|
|
54
|
-
getGroupedIndex: () => number
|
|
55
|
-
toggleGrouping: () => void
|
|
56
|
-
getToggleGroupingProps: <TGetter extends Getter<ToggleGroupingProps>>(
|
|
57
|
-
userProps?: TGetter
|
|
58
|
-
) => undefined | PropGetterValue<ToggleGroupingProps, TGetter>
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export type GroupingRow = {
|
|
62
|
-
groupingColumnId?: string
|
|
63
|
-
groupingValue?: any
|
|
64
|
-
getIsGrouped: () => boolean
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type GroupingCell = {
|
|
68
|
-
getIsGrouped: () => boolean
|
|
69
|
-
getIsPlaceholder: () => boolean
|
|
70
|
-
getIsAggregated: () => boolean
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type ColumnDefaultOptions = {
|
|
74
|
-
// Column
|
|
75
|
-
onGroupingChange: OnChangeFn<GroupingState>
|
|
76
|
-
autoResetGrouping: boolean
|
|
77
|
-
enableGrouping: boolean
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export type GroupingOptions<
|
|
81
|
-
TData,
|
|
82
|
-
TValue,
|
|
83
|
-
TFilterFns,
|
|
84
|
-
TSortingFns,
|
|
85
|
-
TAggregationFns
|
|
86
|
-
> = {
|
|
87
|
-
aggregationTypes?: TAggregationFns
|
|
88
|
-
onGroupingChange?: OnChangeFn<GroupingState>
|
|
89
|
-
autoResetGrouping?: boolean
|
|
90
|
-
enableGrouping?: boolean
|
|
91
|
-
enableGroupingRemoval?: boolean
|
|
92
|
-
groupRowsFn?: (
|
|
93
|
-
instance: ReactTable<
|
|
94
|
-
TData,
|
|
95
|
-
TValue,
|
|
96
|
-
TFilterFns,
|
|
97
|
-
TSortingFns,
|
|
98
|
-
TAggregationFns
|
|
99
|
-
>,
|
|
100
|
-
rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
101
|
-
) => RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
102
|
-
|
|
103
|
-
groupedColumnMode?: false | 'reorder' | 'remove'
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export type GroupingColumnMode = false | 'reorder' | 'remove'
|
|
107
|
-
|
|
108
|
-
export type ToggleGroupingProps = {
|
|
109
|
-
title?: string
|
|
110
|
-
onClick?: (event: MouseEvent | TouchEvent) => void
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export type GroupingInstance<
|
|
114
|
-
TData,
|
|
115
|
-
TValue,
|
|
116
|
-
TFilterFns,
|
|
117
|
-
TSortingFns,
|
|
118
|
-
TAggregationFns
|
|
119
|
-
> = {
|
|
120
|
-
_notifyGroupingReset: () => void
|
|
121
|
-
getColumnAutoAggregationFn: (columnId: string) => AggregationFn | undefined
|
|
122
|
-
getColumnAggregationFn: (columnId: string) => AggregationFn | undefined
|
|
123
|
-
setGrouping: (updater: Updater<GroupingState>) => void
|
|
124
|
-
resetGrouping: () => void
|
|
125
|
-
toggleColumnGrouping: (columnId: string) => void
|
|
126
|
-
getColumnCanGroup: (columnId: string) => boolean
|
|
127
|
-
getColumnIsGrouped: (columnId: string) => boolean
|
|
128
|
-
getColumnGroupedIndex: (columnId: string) => number
|
|
129
|
-
getToggleGroupingProps: <TGetter extends Getter<ToggleGroupingProps>>(
|
|
130
|
-
columnId: string,
|
|
131
|
-
userProps?: TGetter
|
|
132
|
-
) => undefined | PropGetterValue<ToggleGroupingProps, TGetter>
|
|
133
|
-
getRowIsGrouped: (rowId: string) => boolean
|
|
134
|
-
getGroupedRowModel: () => RowModel<
|
|
135
|
-
TData,
|
|
136
|
-
TValue,
|
|
137
|
-
TFilterFns,
|
|
138
|
-
TSortingFns,
|
|
139
|
-
TAggregationFns
|
|
140
|
-
>
|
|
141
|
-
getPreGroupedRows: () => Row<
|
|
142
|
-
TData,
|
|
143
|
-
TValue,
|
|
144
|
-
TFilterFns,
|
|
145
|
-
TSortingFns,
|
|
146
|
-
TAggregationFns
|
|
147
|
-
>[]
|
|
148
|
-
getPreGroupedFlatRows: () => Row<
|
|
149
|
-
TData,
|
|
150
|
-
TValue,
|
|
151
|
-
TFilterFns,
|
|
152
|
-
TSortingFns,
|
|
153
|
-
TAggregationFns
|
|
154
|
-
>[]
|
|
155
|
-
getPreGroupedRowsById: () => Record<
|
|
156
|
-
string,
|
|
157
|
-
Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
158
|
-
>
|
|
159
|
-
getGroupedRows: () => Row<
|
|
160
|
-
TData,
|
|
161
|
-
TValue,
|
|
162
|
-
TFilterFns,
|
|
163
|
-
TSortingFns,
|
|
164
|
-
TAggregationFns
|
|
165
|
-
>[]
|
|
166
|
-
getGroupedFlatRows: () => Row<
|
|
167
|
-
TData,
|
|
168
|
-
TValue,
|
|
169
|
-
TFilterFns,
|
|
170
|
-
TSortingFns,
|
|
171
|
-
TAggregationFns
|
|
172
|
-
>[]
|
|
173
|
-
getGroupedRowsById: () => Record<
|
|
174
|
-
string,
|
|
175
|
-
Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
176
|
-
>
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
//
|
|
180
|
-
|
|
181
|
-
export function getDefaultColumn<TFilterFns>(): GroupingColumnDef<TFilterFns> {
|
|
182
|
-
return {
|
|
183
|
-
aggregationType: 'auto',
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function getInitialState(): GroupingTableState {
|
|
188
|
-
return {
|
|
189
|
-
grouping: [],
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function getDefaultOptions<
|
|
194
|
-
TData,
|
|
195
|
-
TValue,
|
|
196
|
-
TFilterFns,
|
|
197
|
-
TSortingFns,
|
|
198
|
-
TAggregationFns
|
|
199
|
-
>(
|
|
200
|
-
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
201
|
-
): GroupingOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
202
|
-
return {
|
|
203
|
-
onGroupingChange: makeStateUpdater('grouping', instance),
|
|
204
|
-
autoResetGrouping: true,
|
|
205
|
-
groupedColumnMode: 'reorder',
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export function createColumn<
|
|
210
|
-
TData,
|
|
211
|
-
TValue,
|
|
212
|
-
TFilterFns,
|
|
213
|
-
TSortingFns,
|
|
214
|
-
TAggregationFns
|
|
215
|
-
>(
|
|
216
|
-
column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
217
|
-
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
218
|
-
): GroupingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
219
|
-
return {
|
|
220
|
-
aggregationType: column.aggregationType,
|
|
221
|
-
getCanGroup: () => instance.getColumnCanGroup(column.id),
|
|
222
|
-
getGroupedIndex: () => instance.getColumnGroupedIndex(column.id),
|
|
223
|
-
getIsGrouped: () => instance.getColumnIsGrouped(column.id),
|
|
224
|
-
toggleGrouping: () => instance.toggleColumnGrouping(column.id),
|
|
225
|
-
getToggleGroupingProps: userProps =>
|
|
226
|
-
instance.getToggleGroupingProps(column.id, userProps),
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function getInstance<
|
|
231
|
-
TData,
|
|
232
|
-
TValue,
|
|
233
|
-
TFilterFns,
|
|
234
|
-
TSortingFns,
|
|
235
|
-
TAggregationFns
|
|
236
|
-
>(
|
|
237
|
-
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
238
|
-
): GroupingInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
239
|
-
let registered = false
|
|
240
|
-
|
|
241
|
-
return {
|
|
242
|
-
_notifyGroupingReset: () => {
|
|
243
|
-
if (!registered) {
|
|
244
|
-
registered = true
|
|
245
|
-
return
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (instance.options.autoResetAll === false) {
|
|
249
|
-
return
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (
|
|
253
|
-
instance.options.autoResetAll === true ||
|
|
254
|
-
instance.options.autoResetGrouping
|
|
255
|
-
) {
|
|
256
|
-
instance.resetGrouping()
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
getColumnAutoAggregationFn: columnId => {
|
|
260
|
-
const firstRow = instance.getCoreFlatRows()[0]
|
|
261
|
-
|
|
262
|
-
const value = firstRow?.values[columnId]
|
|
263
|
-
|
|
264
|
-
if (typeof value === 'number') {
|
|
265
|
-
return aggregationTypes.sum
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
269
|
-
return aggregationTypes.extent
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return aggregationTypes.count
|
|
273
|
-
},
|
|
274
|
-
getColumnAggregationFn: columnId => {
|
|
275
|
-
const column = instance.getColumn(columnId)
|
|
276
|
-
const userAggregationTypes = instance.options.aggregationTypes
|
|
277
|
-
|
|
278
|
-
if (!column) {
|
|
279
|
-
throw new Error()
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return isFunction(column.aggregationType)
|
|
283
|
-
? column.aggregationType
|
|
284
|
-
: column.aggregationType === 'auto'
|
|
285
|
-
? instance.getColumnAutoFilterFn(columnId)
|
|
286
|
-
: (userAggregationTypes as Record<string, any>)?.[
|
|
287
|
-
column.aggregationType as string
|
|
288
|
-
] ??
|
|
289
|
-
(aggregationTypes[
|
|
290
|
-
column.aggregationType as BuiltInAggregationType
|
|
291
|
-
] as AggregationFn)
|
|
292
|
-
},
|
|
293
|
-
|
|
294
|
-
setGrouping: updater =>
|
|
295
|
-
instance.options.onGroupingChange?.(
|
|
296
|
-
updater,
|
|
297
|
-
functionalUpdate(updater, instance.getState().grouping)
|
|
298
|
-
),
|
|
299
|
-
|
|
300
|
-
toggleColumnGrouping: columnId => {
|
|
301
|
-
instance.setGrouping(old => {
|
|
302
|
-
// Find any existing grouping for this column
|
|
303
|
-
if (old?.includes(columnId)) {
|
|
304
|
-
return old.filter(d => d !== columnId)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return [...(old ?? []), columnId]
|
|
308
|
-
})
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
getColumnCanGroup: columnId => {
|
|
312
|
-
const column = instance.getColumn(columnId)
|
|
313
|
-
|
|
314
|
-
if (!column) {
|
|
315
|
-
throw new Error()
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return (
|
|
319
|
-
column.enableGrouping ??
|
|
320
|
-
instance.options.enableGrouping ??
|
|
321
|
-
column.defaultCanGroup ??
|
|
322
|
-
!!column.accessorFn
|
|
323
|
-
)
|
|
324
|
-
},
|
|
325
|
-
|
|
326
|
-
getColumnIsGrouped: columnId => {
|
|
327
|
-
return instance.getState().grouping?.includes(columnId)
|
|
328
|
-
},
|
|
329
|
-
|
|
330
|
-
getColumnGroupedIndex: columnId =>
|
|
331
|
-
instance.getState().grouping?.indexOf(columnId),
|
|
332
|
-
|
|
333
|
-
resetGrouping: () => {
|
|
334
|
-
instance.setGrouping(instance.initialState?.grouping ?? [])
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
getToggleGroupingProps: (columnId, userProps) => {
|
|
338
|
-
const column = instance.getColumn(columnId)
|
|
339
|
-
|
|
340
|
-
if (!column) {
|
|
341
|
-
return
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const canGroup = column.getCanGroup()
|
|
345
|
-
|
|
346
|
-
const initialProps: ToggleGroupingProps = {
|
|
347
|
-
title: canGroup ? 'Toggle Grouping' : undefined,
|
|
348
|
-
onClick: canGroup
|
|
349
|
-
? (e: MouseEvent | TouchEvent) => {
|
|
350
|
-
e.persist()
|
|
351
|
-
column.toggleGrouping?.()
|
|
352
|
-
}
|
|
353
|
-
: undefined,
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
return propGetter(initialProps, userProps)
|
|
357
|
-
},
|
|
358
|
-
|
|
359
|
-
getRowIsGrouped: rowId => !!instance.getRow(rowId)?.groupingColumnId,
|
|
360
|
-
|
|
361
|
-
getGroupedRowModel: memo(
|
|
362
|
-
() => [
|
|
363
|
-
instance.getState().grouping,
|
|
364
|
-
instance.getSortedRowModel(),
|
|
365
|
-
instance.options.groupRowsFn,
|
|
366
|
-
],
|
|
367
|
-
(grouping, rowModel, groupRowsFn) => {
|
|
368
|
-
if (!groupRowsFn || !grouping.length) {
|
|
369
|
-
return rowModel
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (process.env.NODE_ENV !== 'production' && instance.options.debug)
|
|
373
|
-
console.info('Grouping...')
|
|
374
|
-
|
|
375
|
-
return groupRowsFn(instance, rowModel)
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
key: 'getGroupedRowModel',
|
|
379
|
-
debug: instance.options.debug,
|
|
380
|
-
onChange: () => instance._notifyExpandedReset(),
|
|
381
|
-
}
|
|
382
|
-
),
|
|
383
|
-
|
|
384
|
-
getPreGroupedRows: () => instance.getSortedRowModel().rows,
|
|
385
|
-
getPreGroupedFlatRows: () => instance.getSortedRowModel().flatRows,
|
|
386
|
-
getPreGroupedRowsById: () => instance.getSortedRowModel().rowsById,
|
|
387
|
-
getGroupedRows: () => instance.getGroupedRowModel().rows,
|
|
388
|
-
getGroupedFlatRows: () => instance.getGroupedRowModel().flatRows,
|
|
389
|
-
getGroupedRowsById: () => instance.getGroupedRowModel().rowsById,
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
export function createRow<
|
|
394
|
-
TData,
|
|
395
|
-
TValue,
|
|
396
|
-
TFilterFns,
|
|
397
|
-
TSortingFns,
|
|
398
|
-
TAggregationFns
|
|
399
|
-
>(
|
|
400
|
-
row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
401
|
-
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
402
|
-
): GroupingRow {
|
|
403
|
-
return {
|
|
404
|
-
getIsGrouped: () => instance.getRowIsGrouped(row.id),
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
export function createCell<
|
|
409
|
-
TData,
|
|
410
|
-
TValue,
|
|
411
|
-
TFilterFns,
|
|
412
|
-
TSortingFns,
|
|
413
|
-
TAggregationFns
|
|
414
|
-
>(
|
|
415
|
-
cell: Cell<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
416
|
-
GroupingCell,
|
|
417
|
-
column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
418
|
-
row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
419
|
-
_instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
420
|
-
): GroupingCell {
|
|
421
|
-
return {
|
|
422
|
-
getIsGrouped: () =>
|
|
423
|
-
column.getIsGrouped() && column.id === row.groupingColumnId,
|
|
424
|
-
getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
|
|
425
|
-
getIsAggregated: () =>
|
|
426
|
-
!cell.getIsGrouped() &&
|
|
427
|
-
!cell.getIsPlaceholder() &&
|
|
428
|
-
row.subRows?.length > 1,
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
export function orderColumns<
|
|
433
|
-
TData,
|
|
434
|
-
TValue,
|
|
435
|
-
TFilterFns,
|
|
436
|
-
TSortingFns,
|
|
437
|
-
TAggregationFns
|
|
438
|
-
>(
|
|
439
|
-
leafColumns: Column<
|
|
440
|
-
TData,
|
|
441
|
-
TValue,
|
|
442
|
-
TFilterFns,
|
|
443
|
-
TSortingFns,
|
|
444
|
-
TAggregationFns
|
|
445
|
-
>[],
|
|
446
|
-
grouping: string[],
|
|
447
|
-
groupedColumnMode?: GroupingColumnMode
|
|
448
|
-
) {
|
|
449
|
-
if (!grouping?.length || !groupedColumnMode) {
|
|
450
|
-
return leafColumns
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
const nonGroupingColumns = leafColumns.filter(
|
|
454
|
-
col => !grouping.includes(col.id)
|
|
455
|
-
)
|
|
456
|
-
|
|
457
|
-
if (groupedColumnMode === 'remove') {
|
|
458
|
-
return nonGroupingColumns
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
const groupingColumns = grouping
|
|
462
|
-
.map(g => leafColumns.find(col => col.id === g)!)
|
|
463
|
-
.filter(Boolean)
|
|
464
|
-
|
|
465
|
-
return [...groupingColumns, ...nonGroupingColumns]
|
|
466
|
-
}
|