@tanstack/table-core 8.0.0-alpha.30 → 8.0.0-alpha.36
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/aggregationTypes.js +1 -0
- package/build/cjs/aggregationTypes.js.map +1 -1
- package/build/cjs/core.js +43 -78
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +12 -16
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +28 -81
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +10 -16
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +8 -13
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +9 -3
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +10 -16
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterTypes.js.map +1 -1
- package/build/cjs/index.js +19 -12
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/sortTypes.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getColumnFilteredRowModelSync.js +115 -0
- package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -0
- package/build/cjs/utils/getCoreRowModelAsync.js +127 -0
- package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -0
- package/build/cjs/utils/getCoreRowModelSync.js +104 -0
- package/build/cjs/utils/getCoreRowModelSync.js.map +1 -0
- package/build/cjs/utils/getExpandedRowModel.js +61 -0
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
- package/build/cjs/utils/getGlobalFilteredRowModelSync.js +91 -0
- package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +176 -0
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
- package/build/cjs/utils/getPaginationRowModel.js +61 -0
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
- package/build/cjs/utils/getSortedRowModelSync.js +118 -0
- package/build/cjs/utils/getSortedRowModelSync.js.map +1 -0
- package/build/cjs/utils.js +155 -16
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +877 -488
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +408 -300
- package/build/types/aggregationTypes.d.ts +1 -1
- package/build/types/core.d.ts +9 -1
- package/build/types/features/Expanding.d.ts +2 -1
- package/build/types/features/Filters.d.ts +6 -2
- package/build/types/features/Grouping.d.ts +3 -2
- package/build/types/features/Pagination.d.ts +2 -1
- package/build/types/features/Sorting.d.ts +2 -1
- package/build/types/index.d.ts +8 -6
- package/build/types/types.d.ts +2 -2
- package/build/types/utils/getColumnFilteredRowModelAsync.d.ts +4 -0
- package/build/types/utils/getColumnFilteredRowModelSync.d.ts +2 -0
- package/build/types/utils/getCoreRowModelAsync.d.ts +4 -0
- package/build/types/utils/getCoreRowModelSync.d.ts +2 -0
- package/build/types/utils/getExpandedRowModel.d.ts +7 -0
- package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +4 -0
- package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +2 -0
- package/build/types/utils/getGroupedRowModel.d.ts +2 -0
- package/build/types/utils/getPaginationRowModel.d.ts +4 -0
- package/build/types/utils/{sortRowsQuicksortFn.d.ts → getSortedRowModelAsync.d.ts} +3 -1
- package/build/types/utils/getSortedRowModelSync.d.ts +2 -0
- package/build/types/utils.d.ts +16 -0
- package/build/umd/index.development.js +887 -493
- 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 +3 -1
- package/src/aggregationTypes.ts +1 -1
- package/src/core.tsx +53 -97
- package/src/features/Expanding.ts +19 -27
- package/src/features/Filters.ts +52 -99
- package/src/features/Grouping.ts +19 -21
- package/src/features/Pagination.ts +17 -20
- package/src/features/RowSelection.ts +5 -3
- package/src/features/Sorting.ts +19 -23
- package/src/index.tsx +8 -6
- package/src/types.ts +3 -1
- package/src/utils/getColumnFilteredRowModelAsync.ts +119 -0
- package/src/utils/getColumnFilteredRowModelSync.ts +99 -0
- package/src/utils/getCoreRowModelAsync.ts +105 -0
- package/src/utils/getCoreRowModelSync.ts +107 -0
- package/src/utils/getExpandedRowModel.ts +58 -0
- package/src/utils/getGlobalFilteredRowModelAsync.ts +97 -0
- package/src/utils/getGlobalFilteredRowModelSync.ts +76 -0
- package/src/utils/getGroupedRowModel.ts +191 -0
- package/src/utils/getPaginationRowModel.ts +45 -0
- package/src/utils/getSortedRowModelAsync.ts +201 -0
- package/src/utils/getSortedRowModelSync.ts +118 -0
- package/src/utils.tsx +189 -16
- package/build/cjs/utils/columnFilterRowsFn.js +0 -73
- package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/expandRowsFn.js +0 -37
- package/build/cjs/utils/expandRowsFn.js.map +0 -1
- package/build/cjs/utils/globalFilterRowsFn.js +0 -49
- 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/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/src/utils/columnFilterRowsFn.ts +0 -56
- package/src/utils/expandRowsFn.ts +0 -34
- package/src/utils/globalFilterRowsFn.ts +0 -39
- package/src/utils/groupRowsFn.ts +0 -174
- package/src/utils/paginateRowsFn.ts +0 -28
- package/src/utils/sortRowsFn.ts +0 -99
- package/src/utils/sortRowsQuicksortFn.ts +0 -174
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.36",
|
|
5
5
|
"description": "Hooks for building lightweight, fast and extendable datagrids for React",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/react-table#readme",
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"react",
|
|
17
|
+
"vue",
|
|
18
|
+
"solid",
|
|
17
19
|
"table",
|
|
18
20
|
"table-core",
|
|
19
21
|
"datagrid"
|
package/src/aggregationTypes.ts
CHANGED
package/src/core.tsx
CHANGED
|
@@ -46,6 +46,8 @@ import { RowSelection } from './features/RowSelection'
|
|
|
46
46
|
import { Sorting } from './features/Sorting'
|
|
47
47
|
import { Visibility } from './features/Visibility'
|
|
48
48
|
import { Headers } from './features/Headers'
|
|
49
|
+
import { mean } from './aggregationTypes'
|
|
50
|
+
import React from 'react'
|
|
49
51
|
|
|
50
52
|
const features: TableFeature[] = [
|
|
51
53
|
Headers,
|
|
@@ -61,12 +63,19 @@ const features: TableFeature[] = [
|
|
|
61
63
|
ColumnSizing,
|
|
62
64
|
]
|
|
63
65
|
|
|
66
|
+
export type CoreTableState = {
|
|
67
|
+
coreProgress: number
|
|
68
|
+
}
|
|
69
|
+
|
|
64
70
|
export type CoreOptions<TGenerics extends AnyGenerics> = {
|
|
65
71
|
data: TGenerics['Row'][]
|
|
66
72
|
columns: ColumnDef<TGenerics>[]
|
|
67
73
|
state: Partial<TableState>
|
|
68
74
|
onStateChange: (updater: Updater<TableState>) => void
|
|
69
75
|
render: TGenerics['Render']
|
|
76
|
+
getCoreRowModel: (
|
|
77
|
+
instance: TableInstance<TGenerics>
|
|
78
|
+
) => () => RowModel<TGenerics>
|
|
70
79
|
debugAll?: boolean
|
|
71
80
|
debugTable?: boolean
|
|
72
81
|
debugHeaders?: boolean
|
|
@@ -88,7 +97,7 @@ export type CoreOptions<TGenerics extends AnyGenerics> = {
|
|
|
88
97
|
defaultOptions: TableFeature,
|
|
89
98
|
options: Partial<Options<TGenerics>>
|
|
90
99
|
) => Options<TGenerics>
|
|
91
|
-
meta?: TGenerics['TableMeta']
|
|
100
|
+
meta?: TGenerics['TableMeta']
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
export type TableCore<TGenerics extends AnyGenerics> = {
|
|
@@ -96,6 +105,8 @@ export type TableCore<TGenerics extends AnyGenerics> = {
|
|
|
96
105
|
reset: () => void
|
|
97
106
|
options: RequiredKeys<Options<TGenerics>, 'state'>
|
|
98
107
|
setOptions: (newOptions: Updater<Options<TGenerics>>) => void
|
|
108
|
+
queue: (cb: () => void) => void
|
|
109
|
+
willUpdate: () => void
|
|
99
110
|
getRowId: (
|
|
100
111
|
_: TGenerics['Row'],
|
|
101
112
|
index: number,
|
|
@@ -129,6 +140,7 @@ export type TableCore<TGenerics extends AnyGenerics> = {
|
|
|
129
140
|
values: Record<string, any>
|
|
130
141
|
) => Row<TGenerics>
|
|
131
142
|
getCoreRowModel: () => RowModel<TGenerics>
|
|
143
|
+
_getCoreRowModel?: () => RowModel<TGenerics>
|
|
132
144
|
getRowModel: () => RowModel<TGenerics>
|
|
133
145
|
getRow: (id: string) => Row<TGenerics>
|
|
134
146
|
getCell: (rowId: string, columnId: string) => Cell<TGenerics>
|
|
@@ -151,6 +163,7 @@ export type TableCore<TGenerics extends AnyGenerics> = {
|
|
|
151
163
|
template: Renderable<TGenerics, TProps>,
|
|
152
164
|
props: TProps
|
|
153
165
|
) => string | null | ReturnType<UseRenderer<TGenerics>>
|
|
166
|
+
getOverallProgress: () => number
|
|
154
167
|
}
|
|
155
168
|
|
|
156
169
|
export type CoreRow<TGenerics extends AnyGenerics> = {
|
|
@@ -237,18 +250,40 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
|
|
|
237
250
|
|
|
238
251
|
instance.options = buildOptions(options)
|
|
239
252
|
|
|
253
|
+
const coreInitialState: CoreTableState = {
|
|
254
|
+
coreProgress: 1,
|
|
255
|
+
}
|
|
256
|
+
|
|
240
257
|
const initialState = {
|
|
258
|
+
...coreInitialState,
|
|
241
259
|
...features.reduce((obj, feature) => {
|
|
242
260
|
return Object.assign(obj, feature.getInitialState?.())
|
|
243
261
|
}, {}),
|
|
244
262
|
...(options.initialState ?? {}),
|
|
245
263
|
} as TableState
|
|
246
264
|
|
|
265
|
+
const queued: (() => void)[] = []
|
|
266
|
+
let queuedTimeout: NodeJS.Timeout
|
|
267
|
+
|
|
247
268
|
const finalInstance: TableInstance<TGenerics> = {
|
|
248
269
|
...instance,
|
|
249
270
|
...features.reduce((obj, feature) => {
|
|
250
271
|
return Object.assign(obj, feature.getInstance?.(instance))
|
|
251
272
|
}, {}),
|
|
273
|
+
queue: cb => {
|
|
274
|
+
queued.push(cb)
|
|
275
|
+
if (!queuedTimeout) {
|
|
276
|
+
queuedTimeout = setTimeout(() => {
|
|
277
|
+
instance.setState(old => ({ ...old }))
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
willUpdate: () => {
|
|
282
|
+
clearTimeout(queuedTimeout)
|
|
283
|
+
while (queued.length) {
|
|
284
|
+
queued.shift()!()
|
|
285
|
+
}
|
|
286
|
+
},
|
|
252
287
|
initialState,
|
|
253
288
|
reset: () => {
|
|
254
289
|
instance.setState(instance.initialState)
|
|
@@ -568,103 +603,13 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
|
|
|
568
603
|
return row as Row<TGenerics>
|
|
569
604
|
},
|
|
570
605
|
|
|
571
|
-
getCoreRowModel:
|
|
572
|
-
()
|
|
573
|
-
|
|
574
|
-
data
|
|
575
|
-
): {
|
|
576
|
-
rows: Row<TGenerics>[]
|
|
577
|
-
flatRows: Row<TGenerics>[]
|
|
578
|
-
rowsById: Record<string, Row<TGenerics>>
|
|
579
|
-
} => {
|
|
580
|
-
// Access the row model using initial columns
|
|
581
|
-
const rows: Row<TGenerics>[] = []
|
|
582
|
-
const flatRows: Row<TGenerics>[] = []
|
|
583
|
-
const rowsById: Record<string, Row<TGenerics>> = {}
|
|
584
|
-
|
|
585
|
-
const leafColumns = instance.getAllLeafColumns()
|
|
586
|
-
|
|
587
|
-
const accessRow = (
|
|
588
|
-
originalRow: TGenerics['Row'],
|
|
589
|
-
rowIndex: number,
|
|
590
|
-
depth = 0,
|
|
591
|
-
parentRows: Row<TGenerics>[],
|
|
592
|
-
parent?: Row<TGenerics>
|
|
593
|
-
) => {
|
|
594
|
-
const id = instance.getRowId(originalRow, rowIndex, parent)
|
|
595
|
-
|
|
596
|
-
if (!id) {
|
|
597
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
598
|
-
throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
const values: Record<string, any> = {}
|
|
603
|
-
|
|
604
|
-
for (let i = 0; i < leafColumns.length; i++) {
|
|
605
|
-
const column = leafColumns[i]
|
|
606
|
-
if (column && column.accessorFn) {
|
|
607
|
-
values[column.id] = column.accessorFn(originalRow, rowIndex)
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
// Make the row
|
|
612
|
-
const row = instance.createRow(
|
|
613
|
-
id,
|
|
614
|
-
originalRow,
|
|
615
|
-
rowIndex,
|
|
616
|
-
depth,
|
|
617
|
-
values
|
|
618
|
-
)
|
|
619
|
-
|
|
620
|
-
// Push instance row into the parentRows array
|
|
621
|
-
parentRows.push(row)
|
|
622
|
-
// Keep track of every row in a flat array
|
|
623
|
-
flatRows.push(row)
|
|
624
|
-
// Also keep track of every row by its ID
|
|
625
|
-
rowsById[id] = row
|
|
626
|
-
|
|
627
|
-
// Get the original subrows
|
|
628
|
-
if (instance.options.getSubRows) {
|
|
629
|
-
const originalSubRows = instance.options.getSubRows(
|
|
630
|
-
originalRow,
|
|
631
|
-
rowIndex
|
|
632
|
-
)
|
|
633
|
-
|
|
634
|
-
// Then recursively access them
|
|
635
|
-
if (originalSubRows?.length) {
|
|
636
|
-
row.originalSubRows = originalSubRows
|
|
637
|
-
const subRows: Row<TGenerics>[] = []
|
|
638
|
-
|
|
639
|
-
for (let i = 0; i < row.originalSubRows.length; i++) {
|
|
640
|
-
accessRow(
|
|
641
|
-
row.originalSubRows[i] as TGenerics['Row'],
|
|
642
|
-
i,
|
|
643
|
-
depth + 1,
|
|
644
|
-
subRows,
|
|
645
|
-
row
|
|
646
|
-
)
|
|
647
|
-
}
|
|
648
|
-
row.subRows = subRows
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
for (let i = 0; i < data.length; i++) {
|
|
654
|
-
accessRow(data[i] as TGenerics['Row'], i, 0, rows)
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
return { rows, flatRows, rowsById }
|
|
658
|
-
},
|
|
659
|
-
{
|
|
660
|
-
key: 'getRowModel',
|
|
661
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
662
|
-
onChange: () => {
|
|
663
|
-
instance._notifyFiltersReset()
|
|
664
|
-
instance._notifyRowSelectionReset()
|
|
665
|
-
},
|
|
606
|
+
getCoreRowModel: () => {
|
|
607
|
+
if (!instance._getCoreRowModel) {
|
|
608
|
+
instance._getCoreRowModel = instance.options.getCoreRowModel(instance)
|
|
666
609
|
}
|
|
667
|
-
|
|
610
|
+
|
|
611
|
+
return instance._getCoreRowModel()
|
|
612
|
+
},
|
|
668
613
|
|
|
669
614
|
// The final calls start at the bottom of the model,
|
|
670
615
|
// expanded rows, which then work their way up
|
|
@@ -775,6 +720,17 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
|
|
|
775
720
|
instance.getRightHeaderGroups()[0]?.headers.reduce((sum, header) => {
|
|
776
721
|
return sum + header.getWidth()
|
|
777
722
|
}, 0) ?? 0,
|
|
723
|
+
|
|
724
|
+
getOverallProgress: () => {
|
|
725
|
+
const { coreProgress, columnFiltersProgress, globalFilterProgress } =
|
|
726
|
+
instance.getState()
|
|
727
|
+
|
|
728
|
+
return mean(() =>
|
|
729
|
+
[coreProgress, columnFiltersProgress, globalFilterProgress].filter(
|
|
730
|
+
d => d < 1
|
|
731
|
+
)
|
|
732
|
+
) as number
|
|
733
|
+
},
|
|
778
734
|
}
|
|
779
735
|
|
|
780
736
|
instance = Object.assign(instance, finalInstance)
|
|
@@ -31,10 +31,9 @@ export type ExpandedOptions<TGenerics extends AnyGenerics> = {
|
|
|
31
31
|
onExpandedChange?: OnChangeFn<ExpandedState>
|
|
32
32
|
autoResetExpanded?: boolean
|
|
33
33
|
enableExpanded?: boolean
|
|
34
|
-
|
|
35
|
-
instance: TableInstance<TGenerics
|
|
36
|
-
|
|
37
|
-
) => RowModel<TGenerics>
|
|
34
|
+
getExpandedRowModel?: (
|
|
35
|
+
instance: TableInstance<TGenerics>
|
|
36
|
+
) => () => RowModel<TGenerics>
|
|
38
37
|
expandSubRows?: boolean
|
|
39
38
|
defaultCanExpand?: boolean
|
|
40
39
|
getIsRowExpanded?: (row: Row<TGenerics>) => boolean
|
|
@@ -66,6 +65,7 @@ export type ExpandedInstance<TGenerics extends AnyGenerics> = {
|
|
|
66
65
|
getIsAllRowsExpanded: () => boolean
|
|
67
66
|
getExpandedDepth: () => number
|
|
68
67
|
getExpandedRowModel: () => RowModel<TGenerics>
|
|
68
|
+
_getExpandedRowModel?: () => RowModel<TGenerics>
|
|
69
69
|
getPreExpandedRowModel: () => RowModel<TGenerics>
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -96,6 +96,8 @@ export const Expanding = {
|
|
|
96
96
|
|
|
97
97
|
return {
|
|
98
98
|
_notifyExpandedReset: () => {
|
|
99
|
+
instance._notifyPageIndexReset()
|
|
100
|
+
|
|
99
101
|
if (!registered) {
|
|
100
102
|
registered = true
|
|
101
103
|
return
|
|
@@ -269,32 +271,22 @@ export const Expanding = {
|
|
|
269
271
|
|
|
270
272
|
return maxDepth
|
|
271
273
|
},
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
instance.
|
|
276
|
-
instance.options.
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
!expandRowsFn ||
|
|
282
|
-
// Do not expand if rows are not included in pagination
|
|
283
|
-
!paginateExpandedRows ||
|
|
284
|
-
(expanded !== true && !Object.keys(expanded ?? {}).length)
|
|
285
|
-
) {
|
|
286
|
-
return rowModel
|
|
287
|
-
}
|
|
274
|
+
getPreExpandedRowModel: () => instance.getGroupedRowModel(),
|
|
275
|
+
getExpandedRowModel: () => {
|
|
276
|
+
if (
|
|
277
|
+
!instance._getExpandedRowModel &&
|
|
278
|
+
instance.options.getExpandedRowModel
|
|
279
|
+
) {
|
|
280
|
+
instance._getExpandedRowModel =
|
|
281
|
+
instance.options.getExpandedRowModel(instance)
|
|
282
|
+
}
|
|
288
283
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
{
|
|
292
|
-
key: 'getExpandedRowModel',
|
|
293
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
284
|
+
if (!instance._getExpandedRowModel) {
|
|
285
|
+
return instance.getPreExpandedRowModel()
|
|
294
286
|
}
|
|
295
|
-
),
|
|
296
287
|
|
|
297
|
-
|
|
288
|
+
return instance._getExpandedRowModel()
|
|
289
|
+
},
|
|
298
290
|
}
|
|
299
291
|
},
|
|
300
292
|
|
package/src/features/Filters.ts
CHANGED
|
@@ -42,6 +42,8 @@ export type CustomFilterTypes<TGenerics extends AnyGenerics> = Record<
|
|
|
42
42
|
export type FiltersTableState = {
|
|
43
43
|
columnFilters: ColumnFiltersState
|
|
44
44
|
globalFilter: any
|
|
45
|
+
columnFiltersProgress: number
|
|
46
|
+
globalFilterProgress: number
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
export type FilterType<TGenerics extends AnyGenerics> =
|
|
@@ -81,20 +83,18 @@ export type FiltersOptions<TGenerics extends AnyGenerics> = {
|
|
|
81
83
|
onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>
|
|
82
84
|
autoResetColumnFilters?: boolean
|
|
83
85
|
enableColumnFilters?: boolean
|
|
84
|
-
|
|
85
|
-
instance: TableInstance<TGenerics
|
|
86
|
-
|
|
87
|
-
) => RowModel<TGenerics>
|
|
86
|
+
getColumnFilteredRowModel?: (
|
|
87
|
+
instance: TableInstance<TGenerics>
|
|
88
|
+
) => () => RowModel<TGenerics>
|
|
88
89
|
// Global
|
|
89
90
|
globalFilterType?: FilterType<TGenerics>
|
|
90
91
|
onGlobalFilterChange?: OnChangeFn<any>
|
|
91
92
|
enableGlobalFilters?: boolean
|
|
92
93
|
autoResetGlobalFilter?: boolean
|
|
93
94
|
enableGlobalFilter?: boolean
|
|
94
|
-
|
|
95
|
-
instance: TableInstance<TGenerics
|
|
96
|
-
|
|
97
|
-
) => RowModel<TGenerics>
|
|
95
|
+
getGlobalFilteredRowModel?: (
|
|
96
|
+
instance: TableInstance<TGenerics>
|
|
97
|
+
) => () => RowModel<TGenerics>
|
|
98
98
|
getColumnCanGlobalFilterFn?: (column: Column<TGenerics>) => boolean
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -120,6 +120,7 @@ export type FiltersInstance<TGenerics extends AnyGenerics> = {
|
|
|
120
120
|
// Column Filters
|
|
121
121
|
getPreColumnFilteredRowModel: () => RowModel<TGenerics>
|
|
122
122
|
getColumnFilteredRowModel: () => RowModel<TGenerics>
|
|
123
|
+
_getColumnFilteredRowModel?: () => RowModel<TGenerics>
|
|
123
124
|
|
|
124
125
|
// Global Filters
|
|
125
126
|
setGlobalFilter: (updater: Updater<any>) => void
|
|
@@ -129,6 +130,7 @@ export type FiltersInstance<TGenerics extends AnyGenerics> = {
|
|
|
129
130
|
getColumnCanGlobalFilter: (columnId: string) => boolean
|
|
130
131
|
getPreGlobalFilteredRowModel: () => RowModel<TGenerics>
|
|
131
132
|
getGlobalFilteredRowModel: () => RowModel<TGenerics>
|
|
133
|
+
_getGlobalFilteredRowModel?: () => RowModel<TGenerics>
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
//
|
|
@@ -146,6 +148,8 @@ export const Filters = {
|
|
|
146
148
|
return {
|
|
147
149
|
columnFilters: [],
|
|
148
150
|
globalFilter: undefined,
|
|
151
|
+
columnFiltersProgress: 1,
|
|
152
|
+
globalFilterProgress: 1,
|
|
149
153
|
}
|
|
150
154
|
},
|
|
151
155
|
|
|
@@ -235,6 +239,8 @@ export const Filters = {
|
|
|
235
239
|
|
|
236
240
|
return {
|
|
237
241
|
_notifyFiltersReset: () => {
|
|
242
|
+
instance._notifySortingReset()
|
|
243
|
+
|
|
238
244
|
if (!registered) {
|
|
239
245
|
registered = true
|
|
240
246
|
return
|
|
@@ -244,15 +250,18 @@ export const Filters = {
|
|
|
244
250
|
return
|
|
245
251
|
}
|
|
246
252
|
|
|
247
|
-
if (
|
|
248
|
-
instance.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
253
|
+
if (
|
|
254
|
+
instance.options.autoResetAll === true ||
|
|
255
|
+
instance.options.autoResetColumnFilters
|
|
256
|
+
) {
|
|
257
|
+
instance.resetColumnFilters()
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (
|
|
261
|
+
instance.options.autoResetAll === true ||
|
|
262
|
+
instance.options.autoResetGlobalFilter
|
|
263
|
+
) {
|
|
264
|
+
instance.resetGlobalFilter()
|
|
256
265
|
}
|
|
257
266
|
},
|
|
258
267
|
getColumnAutoFilterFn: columnId => {
|
|
@@ -462,93 +471,37 @@ export const Filters = {
|
|
|
462
471
|
|
|
463
472
|
getPreFilteredRowModel: () => instance.getCoreRowModel(),
|
|
464
473
|
getPreColumnFilteredRowModel: () => instance.getCoreRowModel(),
|
|
465
|
-
getColumnFilteredRowModel:
|
|
466
|
-
(
|
|
467
|
-
instance.
|
|
468
|
-
instance.
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
const columnFilteredRowModel = (() => {
|
|
473
|
-
if (!columnFilters?.length || !columnFiltersFn) {
|
|
474
|
-
return rowModel
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
return columnFiltersFn(instance as any, rowModel)
|
|
478
|
-
})()
|
|
479
|
-
|
|
480
|
-
// Now that each filtered column has it's partially filtered rows,
|
|
481
|
-
// lets assign the final filtered rows to all of the other columns
|
|
482
|
-
const nonFilteredColumns = instance
|
|
483
|
-
.getAllLeafColumns()
|
|
484
|
-
.filter(
|
|
485
|
-
column =>
|
|
486
|
-
!instance
|
|
487
|
-
.getState()
|
|
488
|
-
.columnFilters?.find(d => d.id === column.id)
|
|
489
|
-
)
|
|
490
|
-
|
|
491
|
-
// This essentially enables faceted filter options to be built easily
|
|
492
|
-
// using every column's preFilteredRows value
|
|
493
|
-
|
|
494
|
-
nonFilteredColumns.forEach(column => {
|
|
495
|
-
column.getPreFilteredRows = () => columnFilteredRowModel.rows
|
|
496
|
-
})
|
|
497
|
-
|
|
498
|
-
return columnFilteredRowModel
|
|
499
|
-
},
|
|
500
|
-
{
|
|
501
|
-
key: 'getColumnFilteredRowModel',
|
|
502
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
474
|
+
getColumnFilteredRowModel: () => {
|
|
475
|
+
if (
|
|
476
|
+
!instance._getColumnFilteredRowModel &&
|
|
477
|
+
instance.options.getColumnFilteredRowModel
|
|
478
|
+
) {
|
|
479
|
+
instance._getColumnFilteredRowModel =
|
|
480
|
+
instance.options.getColumnFilteredRowModel(instance)
|
|
503
481
|
}
|
|
504
|
-
),
|
|
505
|
-
getPreGlobalFilteredRowModel: () => instance.getColumnFilteredRowModel(),
|
|
506
|
-
getGlobalFilteredRowModel: memo(
|
|
507
|
-
() => [
|
|
508
|
-
instance.getState().globalFilter,
|
|
509
|
-
instance.getColumnFilteredRowModel(),
|
|
510
|
-
instance.options.globalFilterRowsFn,
|
|
511
|
-
],
|
|
512
|
-
(globalFilterValue, columnFilteredRowModel, globalFiltersFn) => {
|
|
513
|
-
const globalFilteredRowModel = (() => {
|
|
514
|
-
if (!globalFiltersFn || !globalFilterValue) {
|
|
515
|
-
return columnFilteredRowModel
|
|
516
|
-
}
|
|
517
482
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
)
|
|
522
|
-
})()
|
|
523
|
-
|
|
524
|
-
// Now that each filtered column has it's partially filtered rows,
|
|
525
|
-
// lets assign the final filtered rows to all of the other columns
|
|
526
|
-
const nonFilteredColumns = instance
|
|
527
|
-
.getAllLeafColumns()
|
|
528
|
-
.filter(
|
|
529
|
-
column =>
|
|
530
|
-
!instance
|
|
531
|
-
.getState()
|
|
532
|
-
.columnFilters?.find(d => d.id === column.id)
|
|
533
|
-
)
|
|
534
|
-
|
|
535
|
-
// This essentially enables faceted filter options to be built easily
|
|
536
|
-
// using every column's preFilteredRows value
|
|
483
|
+
if (!instance._getColumnFilteredRowModel) {
|
|
484
|
+
return instance.getPreColumnFilteredRowModel()
|
|
485
|
+
}
|
|
537
486
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
487
|
+
return instance._getColumnFilteredRowModel()
|
|
488
|
+
},
|
|
489
|
+
getPreGlobalFilteredRowModel: () => instance.getColumnFilteredRowModel(),
|
|
490
|
+
getGlobalFilteredRowModel: () => {
|
|
491
|
+
if (
|
|
492
|
+
!instance._getGlobalFilteredRowModel &&
|
|
493
|
+
instance.options.getGlobalFilteredRowModel
|
|
494
|
+
) {
|
|
495
|
+
instance._getGlobalFilteredRowModel =
|
|
496
|
+
instance.options.getGlobalFilteredRowModel(instance)
|
|
497
|
+
}
|
|
541
498
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
{
|
|
545
|
-
key: 'getGlobalFilteredRowModel',
|
|
546
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
547
|
-
onChange: () => {
|
|
548
|
-
instance._notifySortingReset()
|
|
549
|
-
},
|
|
499
|
+
if (!instance._getGlobalFilteredRowModel) {
|
|
500
|
+
return instance.getPreGlobalFilteredRowModel()
|
|
550
501
|
}
|
|
551
|
-
|
|
502
|
+
|
|
503
|
+
return instance._getGlobalFilteredRowModel()
|
|
504
|
+
},
|
|
552
505
|
}
|
|
553
506
|
},
|
|
554
507
|
}
|
package/src/features/Grouping.ts
CHANGED
|
@@ -99,10 +99,9 @@ export type GroupingOptions<TGenerics extends AnyGenerics> = {
|
|
|
99
99
|
autoResetGrouping?: boolean
|
|
100
100
|
enableGrouping?: boolean
|
|
101
101
|
enableGroupingRemoval?: boolean
|
|
102
|
-
|
|
103
|
-
instance: TableInstance<TGenerics
|
|
104
|
-
|
|
105
|
-
) => RowModel<TGenerics>
|
|
102
|
+
getGroupedRowModel?: (
|
|
103
|
+
instance: TableInstance<TGenerics>
|
|
104
|
+
) => () => RowModel<TGenerics>
|
|
106
105
|
|
|
107
106
|
groupedColumnMode?: false | 'reorder' | 'remove'
|
|
108
107
|
}
|
|
@@ -135,6 +134,7 @@ export type GroupingInstance<TGenerics extends AnyGenerics> = {
|
|
|
135
134
|
getRowIsGrouped: (rowId: string) => boolean
|
|
136
135
|
getPreGroupedRowModel: () => RowModel<TGenerics>
|
|
137
136
|
getGroupedRowModel: () => RowModel<TGenerics>
|
|
137
|
+
_getGroupedRowModel?: () => RowModel<TGenerics>
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
//
|
|
@@ -186,6 +186,8 @@ export const Grouping = {
|
|
|
186
186
|
|
|
187
187
|
return {
|
|
188
188
|
_notifyGroupingReset: () => {
|
|
189
|
+
instance._notifyExpandedReset()
|
|
190
|
+
|
|
189
191
|
if (!registered) {
|
|
190
192
|
registered = true
|
|
191
193
|
return
|
|
@@ -300,25 +302,21 @@ export const Grouping = {
|
|
|
300
302
|
getRowIsGrouped: rowId => !!instance.getRow(rowId)?.groupingColumnId,
|
|
301
303
|
|
|
302
304
|
getPreGroupedRowModel: () => instance.getSortedRowModel(),
|
|
303
|
-
getGroupedRowModel:
|
|
304
|
-
(
|
|
305
|
-
instance.
|
|
306
|
-
instance.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
return rowModel
|
|
312
|
-
}
|
|
305
|
+
getGroupedRowModel: () => {
|
|
306
|
+
if (
|
|
307
|
+
!instance._getGroupedRowModel &&
|
|
308
|
+
instance.options.getGroupedRowModel
|
|
309
|
+
) {
|
|
310
|
+
instance._getGroupedRowModel =
|
|
311
|
+
instance.options.getGroupedRowModel(instance)
|
|
312
|
+
}
|
|
313
313
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
{
|
|
317
|
-
key: 'getGroupedRowModel',
|
|
318
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
319
|
-
onChange: () => instance._notifyExpandedReset(),
|
|
314
|
+
if (!instance._getGroupedRowModel) {
|
|
315
|
+
return instance.getPreGroupedRowModel()
|
|
320
316
|
}
|
|
321
|
-
|
|
317
|
+
|
|
318
|
+
return instance._getGroupedRowModel()
|
|
319
|
+
},
|
|
322
320
|
}
|
|
323
321
|
},
|
|
324
322
|
|
|
@@ -21,10 +21,9 @@ export type PaginationTableState = {
|
|
|
21
21
|
export type PaginationOptions<TGenerics extends AnyGenerics> = {
|
|
22
22
|
onPaginationChange?: OnChangeFn<PaginationState>
|
|
23
23
|
autoResetPageIndex?: boolean
|
|
24
|
-
|
|
25
|
-
instance: TableInstance<TGenerics
|
|
26
|
-
|
|
27
|
-
) => RowModel<TGenerics>
|
|
24
|
+
getPaginationRowModel?: (
|
|
25
|
+
instance: TableInstance<TGenerics>
|
|
26
|
+
) => () => RowModel<TGenerics>
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
export type PaginationDefaultOptions = {
|
|
@@ -48,6 +47,7 @@ export type PaginationInstance<TGenerics extends AnyGenerics> = {
|
|
|
48
47
|
nextPage: () => void
|
|
49
48
|
getPrePaginationRowModel: () => RowModel<TGenerics>
|
|
50
49
|
getPaginationRowModel: () => RowModel<TGenerics>
|
|
50
|
+
_getPaginationRowModel?: () => RowModel<TGenerics>
|
|
51
51
|
getPageCount: () => number
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -213,24 +213,21 @@ export const Pagination = {
|
|
|
213
213
|
},
|
|
214
214
|
|
|
215
215
|
getPrePaginationRowModel: () => instance.getExpandedRowModel(),
|
|
216
|
-
getPaginationRowModel:
|
|
217
|
-
(
|
|
218
|
-
instance.
|
|
219
|
-
instance.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return rowModel
|
|
225
|
-
}
|
|
216
|
+
getPaginationRowModel: () => {
|
|
217
|
+
if (
|
|
218
|
+
!instance._getPaginationRowModel &&
|
|
219
|
+
instance.options.getPaginationRowModel
|
|
220
|
+
) {
|
|
221
|
+
instance._getPaginationRowModel =
|
|
222
|
+
instance.options.getPaginationRowModel(instance)
|
|
223
|
+
}
|
|
226
224
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
{
|
|
230
|
-
key: 'getPaginationRowModel',
|
|
231
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
225
|
+
if (!instance._getPaginationRowModel) {
|
|
226
|
+
return instance.getPrePaginationRowModel()
|
|
232
227
|
}
|
|
233
|
-
|
|
228
|
+
|
|
229
|
+
return instance._getPaginationRowModel()
|
|
230
|
+
},
|
|
234
231
|
|
|
235
232
|
getPageCount: () => {
|
|
236
233
|
const { pageCount } = instance.getState().pagination
|