@tanstack/react-table 8.0.0-alpha.1 → 8.0.0-alpha.4
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 +118 -59
- 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 +317 -0
- package/build/cjs/features/ColumnSizing.js.map +1 -0
- 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 +88 -22
- 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 +198 -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/index.js +2 -0
- package/build/cjs/index.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/paginateRowsFn.js +44 -0
- package/build/cjs/utils/paginateRowsFn.js.map +1 -0
- 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 +1613 -225
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +363 -217
- package/build/types/core.d.ts +14 -25
- package/build/types/createTable.d.ts +21 -3
- package/build/types/features/ColumnSizing.d.ts +67 -0
- 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 +44 -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/index.d.ts +1 -0
- package/build/types/sortTypes.d.ts +5 -4
- package/build/types/types.d.ts +13 -8
- 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 +7 -3
- package/build/umd/index.development.js +1613 -224
- 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 +252 -265
- package/src/createTable.tsx +69 -9
- package/src/features/ColumnSizing.ts +453 -0
- package/src/features/Expanding.ts +27 -11
- package/src/features/Filters.ts +75 -20
- package/src/features/Grouping.ts +27 -12
- package/src/features/Headers.ts +55 -50
- package/src/features/Ordering.ts +2 -3
- package/src/features/Pagination.ts +327 -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/index.tsx +1 -0
- package/src/sortTypes.ts +1 -1
- package/src/types.ts +55 -9
- 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 +20 -6
- package/src/features/withColumnResizing.oldts +0 -281
- 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/index.tsx
CHANGED
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,
|
|
@@ -56,6 +55,24 @@ import {
|
|
|
56
55
|
ExpandedTableState,
|
|
57
56
|
} from './features/Expanding'
|
|
58
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'
|
|
59
76
|
|
|
60
77
|
// declare global {
|
|
61
78
|
// const process.env.NODE_ENV !== 'production': boolean
|
|
@@ -81,7 +98,16 @@ export type ReactTable<
|
|
|
81
98
|
FiltersInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
82
99
|
SortingInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
83
100
|
GroupingInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
84
|
-
|
|
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>
|
|
85
111
|
|
|
86
112
|
export type Renderable<TProps> =
|
|
87
113
|
| React.ReactNode
|
|
@@ -98,9 +124,12 @@ export type Options<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
|
98
124
|
FiltersOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
99
125
|
SortingOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
100
126
|
GroupingOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
101
|
-
ExpandedOptions<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>
|
|
102
131
|
|
|
103
|
-
export type Updater<T> = T | ((old
|
|
132
|
+
export type Updater<T> = T | ((old: T) => T)
|
|
104
133
|
export type OnChangeFn<T> = (updaterOrValue: Updater<T>, value: T) => void
|
|
105
134
|
|
|
106
135
|
export type TableState = VisibilityTableState &
|
|
@@ -109,13 +138,17 @@ export type TableState = VisibilityTableState &
|
|
|
109
138
|
FiltersTableState &
|
|
110
139
|
SortingTableState &
|
|
111
140
|
ExpandedTableState &
|
|
112
|
-
GroupingTableState
|
|
141
|
+
GroupingTableState &
|
|
142
|
+
ColumnSizingTableState &
|
|
143
|
+
PaginationTableState &
|
|
144
|
+
RowSelectionTableState
|
|
113
145
|
|
|
114
146
|
export type Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
115
147
|
CoreRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
116
148
|
VisibilityRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
117
149
|
HeadersRow<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
118
|
-
GroupingRow
|
|
150
|
+
GroupingRow &
|
|
151
|
+
RowSelectionRow
|
|
119
152
|
|
|
120
153
|
export type RowValues = {
|
|
121
154
|
[key: string]: any
|
|
@@ -139,7 +172,8 @@ export type ColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
|
139
172
|
ColumnPinningColumnDef &
|
|
140
173
|
FiltersColumnDef<TFilterFns> &
|
|
141
174
|
SortingColumnDef<TSortingFns> &
|
|
142
|
-
GroupingColumnDef<TAggregationFns>
|
|
175
|
+
GroupingColumnDef<TAggregationFns> &
|
|
176
|
+
ColumnSizingColumnDef
|
|
143
177
|
|
|
144
178
|
export type Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
145
179
|
ColumnDef<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
@@ -148,7 +182,8 @@ export type Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
|
148
182
|
ColumnPinningColumn &
|
|
149
183
|
FiltersColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
150
184
|
SortingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
151
|
-
GroupingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
185
|
+
GroupingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
|
|
186
|
+
ColumnSizingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
152
187
|
|
|
153
188
|
export type Cell<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> = {
|
|
154
189
|
id: string
|
|
@@ -161,7 +196,16 @@ export type Cell<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> = {
|
|
|
161
196
|
renderCell: () => React.ReactNode
|
|
162
197
|
}
|
|
163
198
|
|
|
164
|
-
export type Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> =
|
|
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
|
+
> = {
|
|
165
209
|
id: string
|
|
166
210
|
depth: number
|
|
167
211
|
column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
@@ -263,6 +307,8 @@ export type CellProps = {
|
|
|
263
307
|
role: string
|
|
264
308
|
}
|
|
265
309
|
|
|
310
|
+
export type Listener<TArgs extends [...any]> = (...args: [...TArgs]) => void
|
|
311
|
+
|
|
266
312
|
//
|
|
267
313
|
|
|
268
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
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Getter,
|
|
4
|
+
NoInfer,
|
|
5
|
+
PropGetterValue,
|
|
6
|
+
Renderable,
|
|
7
|
+
TableState,
|
|
8
|
+
} from './types'
|
|
3
9
|
|
|
4
10
|
export type IsAny<T> = 0 extends 1 & T ? true : false
|
|
5
11
|
export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
|
@@ -26,7 +32,7 @@ export function noop() {
|
|
|
26
32
|
//
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
export function makeStateUpdater(key:
|
|
35
|
+
export function makeStateUpdater(key: keyof TableState, instance: unknown) {
|
|
30
36
|
return (updater: Updater<any, any>) => {
|
|
31
37
|
;(instance as any).setState(<TTableState,>(old: TTableState) => {
|
|
32
38
|
return {
|
|
@@ -107,8 +113,11 @@ export const propGetter: PropGetterImpl = (initial, getter) => {
|
|
|
107
113
|
export function memo<TDeps extends readonly any[], TResult>(
|
|
108
114
|
getDeps: () => [...TDeps],
|
|
109
115
|
fn: (...args: NoInfer<[...TDeps]>) => TResult,
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
opts: {
|
|
117
|
+
key: string
|
|
118
|
+
debug?: boolean
|
|
119
|
+
onChange?: (result: TResult, previousResult?: TResult) => void
|
|
120
|
+
}
|
|
112
121
|
): () => TResult {
|
|
113
122
|
let deps: any[] = []
|
|
114
123
|
let result: TResult | undefined
|
|
@@ -125,8 +134,8 @@ export function memo<TDeps extends readonly any[], TResult>(
|
|
|
125
134
|
)
|
|
126
135
|
|
|
127
136
|
if (depsChanged) {
|
|
128
|
-
if (debug) {
|
|
129
|
-
console.info(key, {
|
|
137
|
+
if (opts?.debug) {
|
|
138
|
+
console.info(opts?.key, {
|
|
130
139
|
length: `${oldSerializedDeps.length} -> ${newSerializedDeps.length}`,
|
|
131
140
|
...newSerializedDeps
|
|
132
141
|
.map((_, index) => {
|
|
@@ -151,8 +160,13 @@ export function memo<TDeps extends readonly any[], TResult>(
|
|
|
151
160
|
parent,
|
|
152
161
|
})
|
|
153
162
|
}
|
|
163
|
+
|
|
164
|
+
let oldResult = result
|
|
154
165
|
result = fn(...newDeps)
|
|
155
166
|
deps = newSerializedDeps
|
|
167
|
+
opts?.onChange?.(result, oldResult)
|
|
168
|
+
|
|
169
|
+
oldResult = undefined
|
|
156
170
|
}
|
|
157
171
|
|
|
158
172
|
return result!
|