@tanstack/react-table 8.0.0-alpha.2 → 8.0.0-alpha.3
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/core.js +84 -51
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +11 -6
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +2 -16
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +23 -2
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +54 -5
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +23 -2
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +87 -24
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +4 -1
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +194 -0
- package/build/cjs/features/Pagination.js.map +1 -0
- package/build/cjs/features/Pinning.js +0 -14
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +541 -0
- package/build/cjs/features/RowSelection.js.map +1 -0
- package/build/cjs/features/Sorting.js +76 -18
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +8 -2
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/sortTypes.js +1 -0
- package/build/cjs/sortTypes.js.map +1 -1
- package/build/cjs/utils/columnFilterRowsFn.js +3 -2
- package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
- package/build/cjs/utils/expandRowsFn.js +2 -2
- package/build/cjs/utils/expandRowsFn.js.map +1 -1
- package/build/cjs/utils/globalFilterRowsFn.js +3 -2
- package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
- package/build/cjs/utils/groupRowsFn.js +4 -3
- package/build/cjs/utils/groupRowsFn.js.map +1 -1
- package/build/cjs/utils/sortRowsFn.js +3 -2
- package/build/cjs/utils/sortRowsFn.js.map +1 -1
- package/build/cjs/utils.js +6 -3
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +2608 -1583
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +318 -248
- package/build/types/core.d.ts +10 -25
- package/build/types/createTable.d.ts +20 -2
- package/build/types/features/ColumnSizing.d.ts +4 -10
- package/build/types/features/Expanding.d.ts +2 -1
- package/build/types/features/Filters.d.ts +7 -2
- package/build/types/features/Grouping.d.ts +2 -2
- package/build/types/features/Ordering.d.ts +1 -1
- package/build/types/features/Pagination.d.ts +43 -0
- package/build/types/features/Pinning.d.ts +3 -3
- package/build/types/features/RowSelection.d.ts +66 -0
- package/build/types/features/Sorting.d.ts +5 -2
- package/build/types/sortTypes.d.ts +1 -0
- package/build/types/types.d.ts +9 -6
- package/build/types/utils/columnFilterRowsFn.d.ts +2 -2
- package/build/types/utils/expandRowsFn.d.ts +2 -2
- package/build/types/utils/globalFilterRowsFn.d.ts +2 -2
- package/build/types/utils/groupRowsFn.d.ts +2 -2
- package/build/types/utils/paginateRowsFn.d.ts +2 -0
- package/build/types/utils/sortRowsFn.d.ts +2 -2
- package/build/types/utils.d.ts +5 -1
- package/build/umd/index.development.js +2608 -1583
- 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/core.tsx +222 -272
- package/src/createTable.tsx +68 -8
- package/src/features/ColumnSizing.ts +8 -37
- package/src/features/Expanding.ts +27 -11
- package/src/features/Filters.ts +74 -19
- package/src/features/Grouping.ts +27 -12
- package/src/features/Headers.ts +26 -58
- package/src/features/Ordering.ts +2 -3
- package/src/features/Pagination.ts +314 -0
- package/src/features/Pinning.ts +3 -16
- package/src/features/RowSelection.ts +831 -0
- package/src/features/Sorting.ts +82 -22
- package/src/features/Visibility.ts +2 -4
- package/src/sortTypes.ts +1 -1
- package/src/types.ts +25 -8
- package/src/utils/columnFilterRowsFn.ts +5 -12
- package/src/utils/expandRowsFn.ts +2 -5
- package/src/utils/globalFilterRowsFn.ts +3 -10
- package/src/utils/groupRowsFn.ts +3 -5
- package/src/utils/paginateRowsFn.ts +34 -0
- package/src/utils/sortRowsFn.ts +5 -5
- package/src/utils.tsx +12 -4
- package/src/features/withPagination.oldts +0 -208
- package/src/features/withRowSelection.oldts +0 -467
package/src/features/Sorting.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MouseEvent, TouchEvent } from 'react'
|
|
2
2
|
import { RowModel } from '..'
|
|
3
|
-
import { BuiltInSortType, sortTypes } from '../sortTypes'
|
|
3
|
+
import { BuiltInSortType, reSplitAlphaNumeric, sortTypes } from '../sortTypes'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
Column,
|
|
7
7
|
Getter,
|
|
8
|
+
Header,
|
|
8
9
|
OnChangeFn,
|
|
9
10
|
PropGetterValue,
|
|
10
11
|
ReactTable,
|
|
@@ -20,6 +21,8 @@ import {
|
|
|
20
21
|
propGetter,
|
|
21
22
|
} from '../utils'
|
|
22
23
|
|
|
24
|
+
export type SortDirection = 'asc' | 'desc'
|
|
25
|
+
|
|
23
26
|
export type ColumnSort = {
|
|
24
27
|
id: string
|
|
25
28
|
desc: boolean
|
|
@@ -67,7 +70,7 @@ export type SortingColumn<
|
|
|
67
70
|
getCanSort: () => boolean
|
|
68
71
|
getCanMultiSort: () => boolean
|
|
69
72
|
getSortIndex: () => number
|
|
70
|
-
getIsSorted: () => false |
|
|
73
|
+
getIsSorted: () => false | SortDirection
|
|
71
74
|
toggleSorting: (desc?: boolean, isMulti?: boolean) => void
|
|
72
75
|
getToggleSortingProps: <TGetter extends Getter<ToggleSortingProps>>(
|
|
73
76
|
userProps?: TGetter
|
|
@@ -97,14 +100,7 @@ export type SortingOptions<
|
|
|
97
100
|
TSortingFns,
|
|
98
101
|
TAggregationFns
|
|
99
102
|
>,
|
|
100
|
-
|
|
101
|
-
globalFilteredRowModel: RowModel<
|
|
102
|
-
TData,
|
|
103
|
-
TValue,
|
|
104
|
-
TFilterFns,
|
|
105
|
-
TSortingFns,
|
|
106
|
-
TAggregationFns
|
|
107
|
-
>
|
|
103
|
+
rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
108
104
|
) => RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
109
105
|
maxMultiSortColCount?: number
|
|
110
106
|
isMultiSortEvent?: (e: MouseEvent | TouchEvent) => boolean
|
|
@@ -122,9 +118,11 @@ export type SortingInstance<
|
|
|
122
118
|
TSortingFns,
|
|
123
119
|
TAggregationFns
|
|
124
120
|
> = {
|
|
121
|
+
_notifySortingReset: () => void
|
|
125
122
|
getColumnAutoSortingFn: (
|
|
126
123
|
columnId: string
|
|
127
124
|
) => SortingFn<any, any, any, any, any> | undefined
|
|
125
|
+
getColumnAutoSortDir: (columnId: string) => SortDirection
|
|
128
126
|
|
|
129
127
|
getColumnSortingFn: (
|
|
130
128
|
columnId: string
|
|
@@ -216,6 +214,9 @@ export function getDefaultOptions<
|
|
|
216
214
|
return {
|
|
217
215
|
onSortingChange: makeStateUpdater('sorting', instance),
|
|
218
216
|
autoResetSorting: true,
|
|
217
|
+
isMultiSortEvent: (e: MouseEvent | TouchEvent) => {
|
|
218
|
+
return e.shiftKey
|
|
219
|
+
},
|
|
219
220
|
}
|
|
220
221
|
}
|
|
221
222
|
|
|
@@ -251,22 +252,64 @@ export function getInstance<
|
|
|
251
252
|
>(
|
|
252
253
|
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
253
254
|
): SortingInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
255
|
+
let registered = false
|
|
256
|
+
|
|
254
257
|
return {
|
|
258
|
+
_notifySortingReset: () => {
|
|
259
|
+
if (!registered) {
|
|
260
|
+
registered = true
|
|
261
|
+
return
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (instance.options.autoResetAll === false) {
|
|
265
|
+
return
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (
|
|
269
|
+
instance.options.autoResetAll === true ||
|
|
270
|
+
instance.options.autoResetSorting
|
|
271
|
+
) {
|
|
272
|
+
instance.resetSorting()
|
|
273
|
+
}
|
|
274
|
+
},
|
|
255
275
|
getColumnAutoSortingFn: columnId => {
|
|
256
|
-
const
|
|
276
|
+
const firstRows = instance.getGlobalFilteredRowModel().flatRows.slice(100)
|
|
257
277
|
|
|
258
|
-
|
|
278
|
+
let isString = false
|
|
259
279
|
|
|
260
|
-
|
|
261
|
-
|
|
280
|
+
for (const row of firstRows) {
|
|
281
|
+
const value = row?.values[columnId]
|
|
282
|
+
|
|
283
|
+
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
284
|
+
return sortTypes.datetime
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (typeof value === 'string') {
|
|
288
|
+
isString = true
|
|
289
|
+
|
|
290
|
+
if (value.split(reSplitAlphaNumeric).length > 1) {
|
|
291
|
+
return sortTypes.alphanumeric
|
|
292
|
+
}
|
|
293
|
+
}
|
|
262
294
|
}
|
|
263
295
|
|
|
264
|
-
if (
|
|
265
|
-
return sortTypes.
|
|
296
|
+
if (isString) {
|
|
297
|
+
return sortTypes.text
|
|
266
298
|
}
|
|
267
299
|
|
|
268
300
|
return sortTypes.basic
|
|
269
301
|
},
|
|
302
|
+
getColumnAutoSortDir: columnId => {
|
|
303
|
+
const firstRow = instance.getGlobalFilteredRowModel().flatRows[0]
|
|
304
|
+
|
|
305
|
+
const value = firstRow?.values[columnId]
|
|
306
|
+
|
|
307
|
+
if (typeof value === 'string') {
|
|
308
|
+
return 'asc'
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return 'desc'
|
|
312
|
+
},
|
|
270
313
|
getColumnSortingFn: columnId => {
|
|
271
314
|
const column = instance.getColumn(columnId)
|
|
272
315
|
const userSortTypes = instance.options.sortTypes
|
|
@@ -278,7 +321,7 @@ export function getInstance<
|
|
|
278
321
|
return isFunction(column.sortType)
|
|
279
322
|
? column.sortType
|
|
280
323
|
: column.sortType === 'auto'
|
|
281
|
-
? instance.
|
|
324
|
+
? instance.getColumnAutoSortingFn(columnId)
|
|
282
325
|
: (userSortTypes as Record<string, any>)?.[column.sortType as string] ??
|
|
283
326
|
(sortTypes[column.sortType as BuiltInSortType] as SortingFn<
|
|
284
327
|
TData,
|
|
@@ -302,6 +345,15 @@ export function getInstance<
|
|
|
302
345
|
throw new Error()
|
|
303
346
|
}
|
|
304
347
|
|
|
348
|
+
// if (column.columns.length) {
|
|
349
|
+
// column.columns.forEach((c, i) => {
|
|
350
|
+
// if (c.id) {
|
|
351
|
+
// instance.toggleColumnSorting(c.id, undefined, multi || !!i)
|
|
352
|
+
// }
|
|
353
|
+
// })
|
|
354
|
+
// return
|
|
355
|
+
// }
|
|
356
|
+
|
|
305
357
|
instance.setSorting(old => {
|
|
306
358
|
// Find any existing sorting for this column
|
|
307
359
|
const existingSorting = old?.find(d => d.id === columnId)
|
|
@@ -313,7 +365,7 @@ export function getInstance<
|
|
|
313
365
|
// What should we do with this sort action?
|
|
314
366
|
let sortAction
|
|
315
367
|
|
|
316
|
-
if (
|
|
368
|
+
if (column.getCanMultiSort() && multi) {
|
|
317
369
|
if (existingSorting) {
|
|
318
370
|
sortAction = 'toggle'
|
|
319
371
|
} else {
|
|
@@ -331,7 +383,9 @@ export function getInstance<
|
|
|
331
383
|
}
|
|
332
384
|
|
|
333
385
|
const sortDescFirst =
|
|
334
|
-
column.sortDescFirst ??
|
|
386
|
+
column.sortDescFirst ??
|
|
387
|
+
instance.options.sortDescFirst ??
|
|
388
|
+
instance.getColumnAutoSortDir(columnId) === 'desc'
|
|
335
389
|
|
|
336
390
|
// Handle toggle states that will remove the sorting
|
|
337
391
|
if (
|
|
@@ -398,6 +452,9 @@ export function getInstance<
|
|
|
398
452
|
instance.options.enableSorting ??
|
|
399
453
|
column.defaultCanSort ??
|
|
400
454
|
!!column.accessorFn
|
|
455
|
+
// (!!column.accessorFn ||
|
|
456
|
+
// column.columns?.some(c => c.id && instance.getColumnCanSort(c.id))) ??
|
|
457
|
+
// false
|
|
401
458
|
)
|
|
402
459
|
},
|
|
403
460
|
|
|
@@ -471,10 +528,13 @@ export function getInstance<
|
|
|
471
528
|
if (process.env.NODE_ENV !== 'production' && instance.options.debug)
|
|
472
529
|
console.info('Sorting...')
|
|
473
530
|
|
|
474
|
-
return sortingFn(instance,
|
|
531
|
+
return sortingFn(instance, rowModel)
|
|
475
532
|
},
|
|
476
|
-
|
|
477
|
-
|
|
533
|
+
{
|
|
534
|
+
key: 'getSortedRowModel',
|
|
535
|
+
debug: instance.options.debug,
|
|
536
|
+
onChange: () => instance._notifyGroupingReset(),
|
|
537
|
+
}
|
|
478
538
|
),
|
|
479
539
|
|
|
480
540
|
getPreSortedRows: () => instance.getGlobalFilteredRowModel().rows,
|
|
@@ -172,8 +172,7 @@ export function getInstance<
|
|
|
172
172
|
allFlatColumns => {
|
|
173
173
|
return allFlatColumns.filter(d => d.getIsVisible?.())
|
|
174
174
|
},
|
|
175
|
-
'getVisibleFlatColumns',
|
|
176
|
-
instance.options.debug
|
|
175
|
+
{ key: 'getVisibleFlatColumns', debug: instance.options.debug }
|
|
177
176
|
),
|
|
178
177
|
|
|
179
178
|
getVisibleLeafColumns: memo(
|
|
@@ -188,8 +187,7 @@ export function getInstance<
|
|
|
188
187
|
allFlatColumns => {
|
|
189
188
|
return allFlatColumns.filter(d => d.getIsVisible?.())
|
|
190
189
|
},
|
|
191
|
-
'getVisibleLeafColumns',
|
|
192
|
-
instance.options.debug
|
|
190
|
+
{ key: 'getVisibleLeafColumns', debug: instance.options.debug }
|
|
193
191
|
),
|
|
194
192
|
|
|
195
193
|
setColumnVisibility: updater =>
|
package/src/sortTypes.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
// import * as TS from 'ts-toolbelt'
|
|
3
2
|
import {
|
|
4
3
|
CoreColumn,
|
|
5
4
|
CoreColumnDef,
|
|
@@ -59,11 +58,21 @@ import { Overwrite } from './utils'
|
|
|
59
58
|
import {
|
|
60
59
|
ColumnSizingColumn,
|
|
61
60
|
ColumnSizingColumnDef,
|
|
62
|
-
ColumnSizingHeader,
|
|
63
61
|
ColumnSizingInstance,
|
|
64
62
|
ColumnSizingOptions,
|
|
65
63
|
ColumnSizingTableState,
|
|
66
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'
|
|
67
76
|
|
|
68
77
|
// declare global {
|
|
69
78
|
// const process.env.NODE_ENV !== 'production': boolean
|
|
@@ -96,7 +105,9 @@ export type ReactTable<
|
|
|
96
105
|
TSortingFns,
|
|
97
106
|
TAggregationFns
|
|
98
107
|
> &
|
|
99
|
-
ExpandedInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
108
|
+
ExpandedInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
109
|
+
PaginationInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
110
|
+
RowSelectionInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
100
111
|
|
|
101
112
|
export type Renderable<TProps> =
|
|
102
113
|
| React.ReactNode
|
|
@@ -114,7 +125,9 @@ export type Options<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
|
114
125
|
SortingOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
115
126
|
GroupingOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
116
127
|
ExpandedOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
117
|
-
ColumnSizingOptions
|
|
128
|
+
ColumnSizingOptions &
|
|
129
|
+
PaginationOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
130
|
+
RowSelectionOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
118
131
|
|
|
119
132
|
export type Updater<T> = T | ((old: T) => T)
|
|
120
133
|
export type OnChangeFn<T> = (updaterOrValue: Updater<T>, value: T) => void
|
|
@@ -126,13 +139,16 @@ export type TableState = VisibilityTableState &
|
|
|
126
139
|
SortingTableState &
|
|
127
140
|
ExpandedTableState &
|
|
128
141
|
GroupingTableState &
|
|
129
|
-
ColumnSizingTableState
|
|
142
|
+
ColumnSizingTableState &
|
|
143
|
+
PaginationTableState &
|
|
144
|
+
RowSelectionTableState
|
|
130
145
|
|
|
131
146
|
export type Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
132
147
|
CoreRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
133
148
|
VisibilityRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
134
149
|
HeadersRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
135
|
-
GroupingRow
|
|
150
|
+
GroupingRow &
|
|
151
|
+
RowSelectionRow
|
|
136
152
|
|
|
137
153
|
export type RowValues = {
|
|
138
154
|
[key: string]: any
|
|
@@ -181,8 +197,7 @@ export type Cell<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> = {
|
|
|
181
197
|
}
|
|
182
198
|
|
|
183
199
|
export type Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
184
|
-
CoreHeader<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
185
|
-
ColumnSizingHeader<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
200
|
+
CoreHeader<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
186
201
|
|
|
187
202
|
export type CoreHeader<
|
|
188
203
|
TData,
|
|
@@ -292,6 +307,8 @@ export type CellProps = {
|
|
|
292
307
|
role: string
|
|
293
308
|
}
|
|
294
309
|
|
|
310
|
+
export type Listener<TArgs extends [...any]> = (...args: [...TArgs]) => void
|
|
311
|
+
|
|
295
312
|
//
|
|
296
313
|
|
|
297
314
|
export type PropGetter<TBase> = <TGetter extends Getter<TBase>>(
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { ReactTable, Row, RowModel } from '../types'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const columnFilterRowsFn: Options<
|
|
6
|
-
any,
|
|
7
|
-
any,
|
|
8
|
-
{},
|
|
9
|
-
{},
|
|
10
|
-
{}
|
|
11
|
-
>['columnFilterRowsFn'] = <
|
|
2
|
+
|
|
3
|
+
export function columnFilterRowsFn<
|
|
12
4
|
TData,
|
|
13
5
|
TValue,
|
|
14
6
|
TFilterFns,
|
|
@@ -16,9 +8,10 @@ export const columnFilterRowsFn: Options<
|
|
|
16
8
|
TAggregationFns
|
|
17
9
|
>(
|
|
18
10
|
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
19
|
-
columnFilters: ColumnFiltersState,
|
|
20
11
|
rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
21
|
-
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
12
|
+
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
13
|
+
const columnFilters = instance.getState().columnFilters
|
|
14
|
+
|
|
22
15
|
const newFilteredFlatRows: Row<
|
|
23
16
|
TData,
|
|
24
17
|
TValue,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { ReactTable, Row, RowModel } from '../types'
|
|
2
|
-
import { Options } from '../types'
|
|
3
|
-
import { ExpandedState } from '../features/Expanding'
|
|
4
2
|
|
|
5
|
-
export
|
|
3
|
+
export function expandRowsFn<
|
|
6
4
|
TData,
|
|
7
5
|
TValue,
|
|
8
6
|
TFilterFns,
|
|
@@ -10,7 +8,6 @@ export const expandRowsFn: Options<any, any, {}, {}, {}>['expandRowsFn'] = <
|
|
|
10
8
|
TAggregationFns
|
|
11
9
|
>(
|
|
12
10
|
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
13
|
-
_expandedState: ExpandedState,
|
|
14
11
|
sortedRowModel: RowModel<
|
|
15
12
|
TData,
|
|
16
13
|
TValue,
|
|
@@ -18,7 +15,7 @@ export const expandRowsFn: Options<any, any, {}, {}, {}>['expandRowsFn'] = <
|
|
|
18
15
|
TSortingFns,
|
|
19
16
|
TAggregationFns
|
|
20
17
|
>
|
|
21
|
-
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
18
|
+
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
22
19
|
const expandedRows: Row<
|
|
23
20
|
TData,
|
|
24
21
|
TValue,
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { Options } from '..'
|
|
2
1
|
import { ReactTable, Row, RowModel } from '../types'
|
|
3
2
|
|
|
4
|
-
export
|
|
5
|
-
any,
|
|
6
|
-
any,
|
|
7
|
-
{},
|
|
8
|
-
{},
|
|
9
|
-
{}
|
|
10
|
-
>['globalFilterRowsFn'] = <
|
|
3
|
+
export function globalFilterRowsFn<
|
|
11
4
|
TData,
|
|
12
5
|
TValue,
|
|
13
6
|
TFilterFns,
|
|
@@ -15,9 +8,9 @@ export const globalFilterRowsFn: Options<
|
|
|
15
8
|
TAggregationFns
|
|
16
9
|
>(
|
|
17
10
|
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
18
|
-
globalFilter: any,
|
|
19
11
|
rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
20
|
-
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
12
|
+
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
13
|
+
const globalFilter = instance.getState().globalFilter
|
|
21
14
|
const newFilteredFlatRows: Row<
|
|
22
15
|
TData,
|
|
23
16
|
TValue,
|
package/src/utils/groupRowsFn.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { ReactTable, Row, RowModel } from '../types'
|
|
2
|
-
import { Options } from '../types'
|
|
3
|
-
import { GroupingState } from '../features/Grouping'
|
|
4
2
|
import { flattenBy } from '../utils'
|
|
5
3
|
|
|
6
|
-
export
|
|
4
|
+
export function groupRowsFn<
|
|
7
5
|
TData,
|
|
8
6
|
TValue,
|
|
9
7
|
TFilterFns,
|
|
@@ -11,7 +9,6 @@ export const groupRowsFn: Options<any, any, {}, {}, {}>['groupRowsFn'] = <
|
|
|
11
9
|
TAggregationFns
|
|
12
10
|
>(
|
|
13
11
|
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
14
|
-
groupingState: GroupingState,
|
|
15
12
|
sortedRowModel: RowModel<
|
|
16
13
|
TData,
|
|
17
14
|
TValue,
|
|
@@ -19,7 +16,8 @@ export const groupRowsFn: Options<any, any, {}, {}, {}>['groupRowsFn'] = <
|
|
|
19
16
|
TSortingFns,
|
|
20
17
|
TAggregationFns
|
|
21
18
|
>
|
|
22
|
-
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
19
|
+
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
20
|
+
const groupingState = instance.getState().grouping
|
|
23
21
|
// Filter the grouping list down to columns that exist
|
|
24
22
|
const existingGrouping = groupingState.filter(columnId =>
|
|
25
23
|
instance.getColumn(columnId)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ReactTable, RowModel } from '../types'
|
|
2
|
+
import { expandRowsFn } from './expandRowsFn'
|
|
3
|
+
|
|
4
|
+
export function paginateRowsFn<
|
|
5
|
+
TData,
|
|
6
|
+
TValue,
|
|
7
|
+
TFilterFns,
|
|
8
|
+
TSortingFns,
|
|
9
|
+
TAggregationFns
|
|
10
|
+
>(
|
|
11
|
+
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
12
|
+
rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
13
|
+
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
14
|
+
const { pageSize, pageIndex } = instance.getState().pagination
|
|
15
|
+
let { rows, flatRows, rowsById } = rowModel
|
|
16
|
+
const pageStart = pageSize * pageIndex
|
|
17
|
+
const pageEnd = pageStart + pageSize
|
|
18
|
+
|
|
19
|
+
rows = rows.slice(pageStart, pageEnd)
|
|
20
|
+
|
|
21
|
+
if (!instance.options.paginateExpandedRows) {
|
|
22
|
+
return expandRowsFn(instance, {
|
|
23
|
+
rows,
|
|
24
|
+
flatRows,
|
|
25
|
+
rowsById,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
rows,
|
|
31
|
+
flatRows,
|
|
32
|
+
rowsById,
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/utils/sortRowsFn.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ReactTable, Row, RowModel } from '../types'
|
|
2
|
-
import { SortingFn
|
|
3
|
-
import { Options } from '../types'
|
|
2
|
+
import { SortingFn } from '../features/Sorting'
|
|
4
3
|
|
|
5
|
-
export
|
|
4
|
+
export function sortRowsFn<
|
|
6
5
|
TData,
|
|
7
6
|
TValue,
|
|
8
7
|
TFilterFns,
|
|
@@ -10,9 +9,10 @@ export const sortRowsFn: Options<any, any, {}, {}, {}>['sortRowsFn'] = <
|
|
|
10
9
|
TAggregationFns
|
|
11
10
|
>(
|
|
12
11
|
instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
|
|
13
|
-
sortingState: SortingState,
|
|
14
12
|
rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
15
|
-
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
13
|
+
): RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
|
|
14
|
+
const sortingState = instance.getState().sorting
|
|
15
|
+
|
|
16
16
|
const sortedFlatRows: Row<
|
|
17
17
|
TData,
|
|
18
18
|
TValue,
|
package/src/utils.tsx
CHANGED
|
@@ -113,8 +113,11 @@ export const propGetter: PropGetterImpl = (initial, getter) => {
|
|
|
113
113
|
export function memo<TDeps extends readonly any[], TResult>(
|
|
114
114
|
getDeps: () => [...TDeps],
|
|
115
115
|
fn: (...args: NoInfer<[...TDeps]>) => TResult,
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
opts: {
|
|
117
|
+
key: string
|
|
118
|
+
debug?: boolean
|
|
119
|
+
onChange?: (result: TResult, previousResult?: TResult) => void
|
|
120
|
+
}
|
|
118
121
|
): () => TResult {
|
|
119
122
|
let deps: any[] = []
|
|
120
123
|
let result: TResult | undefined
|
|
@@ -131,8 +134,8 @@ export function memo<TDeps extends readonly any[], TResult>(
|
|
|
131
134
|
)
|
|
132
135
|
|
|
133
136
|
if (depsChanged) {
|
|
134
|
-
if (debug) {
|
|
135
|
-
console.info(key, {
|
|
137
|
+
if (opts?.debug) {
|
|
138
|
+
console.info(opts?.key, {
|
|
136
139
|
length: `${oldSerializedDeps.length} -> ${newSerializedDeps.length}`,
|
|
137
140
|
...newSerializedDeps
|
|
138
141
|
.map((_, index) => {
|
|
@@ -157,8 +160,13 @@ export function memo<TDeps extends readonly any[], TResult>(
|
|
|
157
160
|
parent,
|
|
158
161
|
})
|
|
159
162
|
}
|
|
163
|
+
|
|
164
|
+
let oldResult = result
|
|
160
165
|
result = fn(...newDeps)
|
|
161
166
|
deps = newSerializedDeps
|
|
167
|
+
opts?.onChange?.(result, oldResult)
|
|
168
|
+
|
|
169
|
+
oldResult = undefined
|
|
162
170
|
}
|
|
163
171
|
|
|
164
172
|
return result!
|