@tanstack/table-core 8.0.0-alpha.64 → 8.0.0-alpha.68
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/aggregationFns.js +25 -37
- package/build/cjs/aggregationFns.js.map +1 -1
- package/build/cjs/core.js +167 -47
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js +24 -40
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +29 -35
- package/build/cjs/features/Cells.js.map +1 -1
- package/build/cjs/features/ColumnSizing.js +126 -218
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +59 -86
- package/build/cjs/features/Columns.js.map +1 -1
- package/build/cjs/features/Expanding.js +78 -125
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +143 -218
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +70 -116
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +125 -205
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +31 -43
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +64 -72
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +96 -177
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +134 -205
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +32 -22
- package/build/cjs/features/Rows.js.map +1 -1
- package/build/cjs/features/Sorting.js +62 -131
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +53 -120
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js +52 -133
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/index.js +13 -13
- package/build/cjs/sortingFns.js +21 -21
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +56 -41
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +98 -0
- package/build/cjs/utils/getCoreRowModel.js.map +1 -0
- package/build/cjs/utils/getExpandedRowModel.js +18 -22
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +48 -0
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
- package/build/cjs/utils/getFacetedRowModel.js +50 -0
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
- package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
- package/build/cjs/utils/getFilteredRowModel.js +130 -0
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +126 -136
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +39 -39
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +112 -0
- package/build/cjs/utils/getSortedRowModel.js.map +1 -0
- package/build/cjs/utils.js +36 -211
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +1970 -2956
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +390 -482
- package/build/types/core.d.ts +3 -5
- package/build/types/features/Cells.d.ts +1 -1
- package/build/types/features/ColumnSizing.d.ts +2 -13
- package/build/types/features/Columns.d.ts +1 -1
- package/build/types/features/Expanding.d.ts +1 -6
- package/build/types/features/Filters.d.ts +42 -30
- package/build/types/features/Grouping.d.ts +4 -10
- package/build/types/features/Pinning.d.ts +0 -4
- package/build/types/features/RowSelection.d.ts +1 -7
- package/build/types/features/Rows.d.ts +4 -3
- package/build/types/features/Sorting.d.ts +3 -14
- package/build/types/features/Visibility.d.ts +0 -4
- package/build/types/filterFns.d.ts +10 -52
- package/build/types/index.d.ts +6 -5
- package/build/types/types.d.ts +5 -17
- package/build/types/utils/filterRowsUtils.d.ts +3 -2
- package/build/types/utils/getCoreRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
- package/build/types/utils/getFacetedRowModel.d.ts +2 -0
- package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
- package/build/types/utils/{getCoreRowModelSync.d.ts → getFilteredRowModel.d.ts} +1 -1
- package/build/types/utils/getGroupedRowModel.d.ts +1 -1
- package/build/types/utils/getSortedRowModel.d.ts +2 -0
- package/build/types/utils.d.ts +2 -18
- package/build/umd/index.development.js +1948 -2935
- 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 +2 -1
- package/src/core.ts +197 -46
- package/src/features/Cells.ts +10 -12
- package/src/features/ColumnSizing.ts +72 -129
- package/src/features/Columns.ts +16 -15
- package/src/features/Expanding.ts +58 -105
- package/src/features/Filters.ts +223 -226
- package/src/features/Grouping.ts +51 -79
- package/src/features/Headers.ts +18 -40
- package/src/features/Ordering.ts +1 -1
- package/src/features/Pagination.ts +1 -1
- package/src/features/Pinning.ts +73 -92
- package/src/features/RowSelection.ts +71 -120
- package/src/features/Rows.ts +21 -6
- package/src/features/Sorting.ts +39 -99
- package/src/features/Visibility.ts +21 -50
- package/src/filterFns.ts +74 -147
- package/src/index.ts +12 -5
- package/src/sortingFns.ts +11 -11
- package/src/types.ts +5 -18
- package/src/utils/filterRowsUtils.ts +59 -56
- package/src/utils/{getCoreRowModelSync.ts → getCoreRowModel.ts} +3 -9
- package/src/utils/getExpandedRowModel.ts +2 -2
- package/src/utils/getFacetedMinMaxValues.ts +37 -0
- package/src/utils/getFacetedRowModel.ts +50 -0
- package/src/utils/getFacetedUniqueValues.ts +37 -0
- package/src/utils/getFilteredRowModel.ts +150 -0
- package/src/utils/getGroupedRowModel.ts +53 -62
- package/src/utils/getPaginationRowModel.ts +1 -1
- package/src/utils/{getSortedRowModelSync.ts → getSortedRowModel.ts} +7 -7
- package/src/utils.ts +29 -239
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/utils/getColumnFilteredRowModelSync.js +0 -115
- package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +0 -1
- package/build/cjs/utils/getCoreRowModelAsync.js +0 -125
- package/build/cjs/utils/getCoreRowModelAsync.js.map +0 -1
- package/build/cjs/utils/getCoreRowModelSync.js +0 -102
- package/build/cjs/utils/getCoreRowModelSync.js.map +0 -1
- package/build/cjs/utils/getGlobalFilteredRowModelSync.js +0 -91
- package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +0 -1
- package/build/cjs/utils/getSortedRowModelSync.js +0 -118
- package/build/cjs/utils/getSortedRowModelSync.js.map +0 -1
- package/build/types/utils/getColumnFilteredRowModelAsync.d.ts +0 -4
- package/build/types/utils/getColumnFilteredRowModelSync.d.ts +0 -2
- package/build/types/utils/getCoreRowModelAsync.d.ts +0 -4
- package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +0 -4
- package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +0 -2
- package/build/types/utils/getSortedRowModelAsync.d.ts +0 -13
- package/build/types/utils/getSortedRowModelSync.d.ts +0 -2
- package/src/utils/getColumnFilteredRowModelAsync.ts +0 -118
- package/src/utils/getColumnFilteredRowModelSync.ts +0 -102
- package/src/utils/getCoreRowModelAsync.ts +0 -104
- package/src/utils/getGlobalFilteredRowModelAsync.ts +0 -96
- package/src/utils/getGlobalFilteredRowModelSync.ts +0 -79
- package/src/utils/getSortedRowModelAsync.ts +0 -200
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { TableInstance, RowModel, TableGenerics, Row } from '../types'
|
|
2
|
-
import { incrementalMemo } from '../utils'
|
|
3
|
-
|
|
4
|
-
export function getColumnFilteredRowModelAsync<
|
|
5
|
-
TGenerics extends TableGenerics
|
|
6
|
-
>(opts?: {
|
|
7
|
-
initialSync?: boolean
|
|
8
|
-
}): (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics> {
|
|
9
|
-
return instance =>
|
|
10
|
-
incrementalMemo(
|
|
11
|
-
() => [
|
|
12
|
-
instance.getState().columnFilters,
|
|
13
|
-
instance.getPreColumnFilteredRowModel(),
|
|
14
|
-
],
|
|
15
|
-
(_sorting, rowModel): RowModel<TGenerics> => {
|
|
16
|
-
return {
|
|
17
|
-
rows: rowModel.rows.slice(),
|
|
18
|
-
flatRows: [],
|
|
19
|
-
rowsById: rowModel.rowsById,
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
(columnFilters, rowModel) => rowModelRef => scheduleTask => {
|
|
23
|
-
// TODO: Figure out how to do scheduled filtering
|
|
24
|
-
// The trick will be batching those tasks in a way
|
|
25
|
-
// that makes them fast. JS work loops don't tend to do well with
|
|
26
|
-
// a high number of tasks that do one thing. Instead, shoot for each
|
|
27
|
-
// task to have a few thousand opts (or whatever amount is generally
|
|
28
|
-
// fast for most devices).
|
|
29
|
-
throw new Error('')
|
|
30
|
-
|
|
31
|
-
// if (!rowModel.rows.length || !columnFilters) {
|
|
32
|
-
// rowModelRef.current = rowModel
|
|
33
|
-
// } else {
|
|
34
|
-
// const filterFromLeafRows = instance.options.filterFromLeafRows
|
|
35
|
-
|
|
36
|
-
// const filterRows = (
|
|
37
|
-
// rowsToFilter: Row<TGenerics>[],
|
|
38
|
-
// depth: number
|
|
39
|
-
// ) => {
|
|
40
|
-
// for (let i = 0; i < columnFilters.length; i++) {
|
|
41
|
-
// const { id: columnId, value: filterValue } = columnFilters[i]
|
|
42
|
-
// // Find the columnFilters column
|
|
43
|
-
// const column = instance.getColumn(columnId)
|
|
44
|
-
|
|
45
|
-
// if (!column) {
|
|
46
|
-
// if (process.env.NODE_ENV !== 'production') {
|
|
47
|
-
// console.warn(
|
|
48
|
-
// `Table: Could not find a column with id: ${columnId}`
|
|
49
|
-
// )
|
|
50
|
-
// }
|
|
51
|
-
// throw new Error()
|
|
52
|
-
// }
|
|
53
|
-
|
|
54
|
-
// if (depth === 0) {
|
|
55
|
-
// const preFilteredRows = [...rowsToFilter]
|
|
56
|
-
// column.getPreFilteredRows = () => preFilteredRows
|
|
57
|
-
// }
|
|
58
|
-
|
|
59
|
-
// const filterFn = instance.getColumnFilterFn(column.id)
|
|
60
|
-
|
|
61
|
-
// if (!filterFn) {
|
|
62
|
-
// if (process.env.NODE_ENV !== 'production') {
|
|
63
|
-
// console.warn(
|
|
64
|
-
// `Could not find a valid 'column.filterFn' for column with the ID: ${column.id}.`
|
|
65
|
-
// )
|
|
66
|
-
// }
|
|
67
|
-
// continue
|
|
68
|
-
// }
|
|
69
|
-
|
|
70
|
-
// // Pass the rows, id, filterValue and column to the filterFn
|
|
71
|
-
// // to get the filtered rows back
|
|
72
|
-
// rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue)
|
|
73
|
-
// }
|
|
74
|
-
|
|
75
|
-
// return rowsToFilter
|
|
76
|
-
// }
|
|
77
|
-
|
|
78
|
-
// if (filterFromLeafRows) {
|
|
79
|
-
// return filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
|
|
80
|
-
// }
|
|
81
|
-
|
|
82
|
-
// return filterRowModelFromRoot(rowModel.rows, filterRows, instance)
|
|
83
|
-
// }
|
|
84
|
-
|
|
85
|
-
// // Now that each filtered column has it's partially filtered rows,
|
|
86
|
-
// // lets assign the final filtered rows to all of the other columns
|
|
87
|
-
// const nonFilteredColumns = instance
|
|
88
|
-
// .getAllLeafColumns()
|
|
89
|
-
// .filter(
|
|
90
|
-
// column =>
|
|
91
|
-
// !instance.getState().columnFilters?.find(d => d.id === column.id)
|
|
92
|
-
// )
|
|
93
|
-
|
|
94
|
-
// // This essentially enables faceted filter options to be built easily
|
|
95
|
-
// // using every column's preFilteredRows value
|
|
96
|
-
|
|
97
|
-
// nonFilteredColumns.forEach(column => {
|
|
98
|
-
// column.getPreFilteredRows = () => rowModelRef.current.rows
|
|
99
|
-
// })
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
key: 'getColumnFilteredRowModelAsync',
|
|
103
|
-
initialSync: opts?.initialSync,
|
|
104
|
-
onProgress: progress => {
|
|
105
|
-
instance.setState(old => ({
|
|
106
|
-
...old,
|
|
107
|
-
columnFiltersProgress: progress,
|
|
108
|
-
}))
|
|
109
|
-
},
|
|
110
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
111
|
-
onChange: () => {
|
|
112
|
-
instance.queue(() => {
|
|
113
|
-
instance._autoResetPageIndex()
|
|
114
|
-
})
|
|
115
|
-
},
|
|
116
|
-
}
|
|
117
|
-
)
|
|
118
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { TableInstance, RowModel, TableGenerics, Row } from '../types'
|
|
2
|
-
import { memo } from '../utils'
|
|
3
|
-
import {
|
|
4
|
-
filterRowModelFromLeafs,
|
|
5
|
-
filterRowModelFromRoot,
|
|
6
|
-
} from './filterRowsUtils'
|
|
7
|
-
|
|
8
|
-
export function getColumnFilteredRowModelSync<
|
|
9
|
-
TGenerics extends TableGenerics
|
|
10
|
-
>(): (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics> {
|
|
11
|
-
return instance =>
|
|
12
|
-
memo(
|
|
13
|
-
() => [
|
|
14
|
-
instance.getState().columnFilters,
|
|
15
|
-
instance.getPreColumnFilteredRowModel(),
|
|
16
|
-
],
|
|
17
|
-
(columnFilters, rowModel) => {
|
|
18
|
-
const columnFilteredRowModel: RowModel<TGenerics> = (() => {
|
|
19
|
-
if (!rowModel.rows.length || !columnFilters?.length) {
|
|
20
|
-
return rowModel
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const filterFromLeafRows = instance.options.filterFromLeafRows
|
|
24
|
-
|
|
25
|
-
const filterRows = (
|
|
26
|
-
rowsToFilter: Row<TGenerics>[],
|
|
27
|
-
depth: number
|
|
28
|
-
) => {
|
|
29
|
-
for (let i = 0; i < columnFilters.length; i++) {
|
|
30
|
-
const { id: columnId, value: filterValue } = columnFilters[i]
|
|
31
|
-
// Find the columnFilters column
|
|
32
|
-
const column = instance.getColumn(columnId)
|
|
33
|
-
|
|
34
|
-
if (!column) {
|
|
35
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
36
|
-
console.warn(
|
|
37
|
-
`Table: Could not find a column with id: ${columnId}`
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
throw new Error()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (depth === 0) {
|
|
44
|
-
const preFilteredRows = [...rowsToFilter]
|
|
45
|
-
column.getPreFilteredRows = () => preFilteredRows
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const filterFn = instance.getColumnFilterFn(column.id)
|
|
49
|
-
|
|
50
|
-
if (!filterFn) {
|
|
51
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
52
|
-
console.warn(
|
|
53
|
-
`Could not find a valid 'column.filterFn' for column with the ID: ${column.id}.`
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
continue
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Pass the rows, id, filterValue and column to the filterFn
|
|
60
|
-
// to get the filtered rows back
|
|
61
|
-
rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return rowsToFilter
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (filterFromLeafRows) {
|
|
68
|
-
return filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return filterRowModelFromRoot(rowModel.rows, filterRows, instance)
|
|
72
|
-
})()
|
|
73
|
-
|
|
74
|
-
// Now that each filtered column has it's partially filtered rows,
|
|
75
|
-
// lets assign the final filtered rows to all of the other columns
|
|
76
|
-
const nonFilteredColumns = instance
|
|
77
|
-
.getAllLeafColumns()
|
|
78
|
-
.filter(
|
|
79
|
-
column =>
|
|
80
|
-
!instance.getState().columnFilters?.find(d => d.id === column.id)
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
// This essentially enables faceted filter options to be built easily
|
|
84
|
-
// using every column's preFilteredRows value
|
|
85
|
-
|
|
86
|
-
nonFilteredColumns.forEach(column => {
|
|
87
|
-
column.getPreFilteredRows = () => columnFilteredRowModel.rows
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
return columnFilteredRowModel
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
key: 'getColumnFilteredRowModelSync',
|
|
94
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
95
|
-
onChange: () => {
|
|
96
|
-
instance.queue(() => {
|
|
97
|
-
instance._autoResetPageIndex()
|
|
98
|
-
})
|
|
99
|
-
},
|
|
100
|
-
}
|
|
101
|
-
)
|
|
102
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { TableInstance, Row, RowModel, TableGenerics } from '../types'
|
|
2
|
-
import { getBatchGroups, incrementalMemo } from '../utils'
|
|
3
|
-
|
|
4
|
-
export function getCoreRowModelAsync<TGenerics extends TableGenerics>(opts?: {
|
|
5
|
-
initialSync: boolean
|
|
6
|
-
}): (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics> {
|
|
7
|
-
return instance =>
|
|
8
|
-
incrementalMemo(
|
|
9
|
-
() => [instance.options.data, instance.getAllLeafColumns()],
|
|
10
|
-
() => {
|
|
11
|
-
const rows: Row<TGenerics>[] = []
|
|
12
|
-
const flatRows: Row<TGenerics>[] = []
|
|
13
|
-
const rowsById: Record<string, Row<TGenerics>> = {}
|
|
14
|
-
|
|
15
|
-
return { rows, flatRows, rowsById }
|
|
16
|
-
},
|
|
17
|
-
(data, leafColumns) => rowModelRef => scheduleTask => {
|
|
18
|
-
const accessRows = (
|
|
19
|
-
originalRows: TGenerics['Row'][],
|
|
20
|
-
depth = 0,
|
|
21
|
-
parent?: Row<TGenerics>
|
|
22
|
-
) => {
|
|
23
|
-
const batchGroups = getBatchGroups(originalRows, 2000)
|
|
24
|
-
|
|
25
|
-
for (let i = 0; i < batchGroups.length; i++) {
|
|
26
|
-
const batchGroup = batchGroups[i]
|
|
27
|
-
scheduleTask(() => {
|
|
28
|
-
for (let i = 0; i < batchGroup.items.length; i++) {
|
|
29
|
-
const originalRow = batchGroup.items[i]
|
|
30
|
-
const rowIndex = batchGroup.start + i
|
|
31
|
-
const id = instance.getRowId(originalRow, rowIndex, parent)
|
|
32
|
-
|
|
33
|
-
if (!id) {
|
|
34
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
35
|
-
throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const values: Record<string, any> = {}
|
|
40
|
-
|
|
41
|
-
for (let i = 0; i < leafColumns.length; i++) {
|
|
42
|
-
const column = leafColumns[i]
|
|
43
|
-
if (column && column.accessorFn) {
|
|
44
|
-
values[column.id] = column.accessorFn(originalRow, rowIndex)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Make the row
|
|
49
|
-
const row = instance.createRow(
|
|
50
|
-
id,
|
|
51
|
-
originalRow,
|
|
52
|
-
rowIndex,
|
|
53
|
-
depth,
|
|
54
|
-
values
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
// Push instance row into the parentRows array
|
|
58
|
-
if (parent) {
|
|
59
|
-
parent.subRows.push(row)
|
|
60
|
-
} else {
|
|
61
|
-
rowModelRef.current.rows.push(row)
|
|
62
|
-
}
|
|
63
|
-
// Keep track of every row in a flat array
|
|
64
|
-
rowModelRef.current.flatRows.push(row)
|
|
65
|
-
// Also keep track of every row by its ID
|
|
66
|
-
rowModelRef.current.rowsById[id] = row
|
|
67
|
-
|
|
68
|
-
// Get the original subrows
|
|
69
|
-
if (instance.options.getSubRows) {
|
|
70
|
-
const originalSubRows = instance.options.getSubRows(
|
|
71
|
-
originalRow,
|
|
72
|
-
rowIndex
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
// Then recursively access them
|
|
76
|
-
if (originalSubRows?.length) {
|
|
77
|
-
row.originalSubRows = originalSubRows
|
|
78
|
-
row.subRows = []
|
|
79
|
-
|
|
80
|
-
accessRows(row.originalSubRows, depth + 1, row)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
accessRows(data)
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
key: 'getRowModel',
|
|
92
|
-
initialSync: opts?.initialSync,
|
|
93
|
-
onProgress: progress => {
|
|
94
|
-
instance.setState(old => ({ ...old, coreProgress: progress }))
|
|
95
|
-
},
|
|
96
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
97
|
-
onChange: () => {
|
|
98
|
-
instance.queue(() => {
|
|
99
|
-
instance._autoResetPageIndex()
|
|
100
|
-
})
|
|
101
|
-
},
|
|
102
|
-
}
|
|
103
|
-
)
|
|
104
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { TableInstance, RowModel, TableGenerics } from '../types'
|
|
2
|
-
import { incrementalMemo } from '../utils'
|
|
3
|
-
|
|
4
|
-
export function getGlobalFilteredRowModelAsync<
|
|
5
|
-
TGenerics extends TableGenerics
|
|
6
|
-
>(opts?: {
|
|
7
|
-
initialSync?: boolean
|
|
8
|
-
}): (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics> {
|
|
9
|
-
return instance =>
|
|
10
|
-
incrementalMemo(
|
|
11
|
-
() => [
|
|
12
|
-
instance.getState().globalFilter,
|
|
13
|
-
instance.getPreGlobalFilteredRowModel(),
|
|
14
|
-
],
|
|
15
|
-
(_globalFilter, rowModel): RowModel<TGenerics> => {
|
|
16
|
-
return {
|
|
17
|
-
rows: rowModel.rows.slice(),
|
|
18
|
-
flatRows: [],
|
|
19
|
-
rowsById: rowModel.rowsById,
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
(globalFilter, rowModel) => rowModelRef => scheduleTask => {
|
|
23
|
-
// TODO: Figure out how to do scheduled filtering
|
|
24
|
-
// The trick will be batching those tasks in a way
|
|
25
|
-
// that makes them fast. JS work loops don't tend to do well with
|
|
26
|
-
// a high number of tasks that do one thing. Instead, shoot for each
|
|
27
|
-
// task to have a few thousand opts (or whatever amount is generally
|
|
28
|
-
// fast for most devices).
|
|
29
|
-
throw new Error('')
|
|
30
|
-
|
|
31
|
-
// const globalFilteredRowModel: RowModel<TGenerics> = (() => {
|
|
32
|
-
// if (!rowModel.rows.length || !globalFilter) {
|
|
33
|
-
// return rowModel
|
|
34
|
-
// }
|
|
35
|
-
|
|
36
|
-
// const filterFromLeafRows = instance.options.filterFromLeafRows
|
|
37
|
-
|
|
38
|
-
// const filterFn = instance.getGlobalFilterFn()
|
|
39
|
-
|
|
40
|
-
// if (!filterFn) {
|
|
41
|
-
// if (process.env.NODE_ENV !== 'production') {
|
|
42
|
-
// console.warn(`Could not find a valid 'globalFilterType'`)
|
|
43
|
-
// }
|
|
44
|
-
// return rowModel
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
|
-
// const filterableColumns = instance
|
|
48
|
-
// .getAllLeafColumns()
|
|
49
|
-
// .filter(column => column.getCanGlobalFilter())
|
|
50
|
-
|
|
51
|
-
// const filterableColumnIds = filterableColumns.map(d => d.id)
|
|
52
|
-
|
|
53
|
-
// const filterRows = (rows: Row<TGenerics>[]) => {
|
|
54
|
-
// return filterFn(rows, filterableColumnIds, globalFilter)
|
|
55
|
-
// }
|
|
56
|
-
|
|
57
|
-
// if (filterFromLeafRows) {
|
|
58
|
-
// return filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
|
|
59
|
-
// }
|
|
60
|
-
|
|
61
|
-
// return filterRowModelFromRoot(rowModel.rows, filterRows, instance)
|
|
62
|
-
// })()
|
|
63
|
-
|
|
64
|
-
// // Now that each filtered column has it's partially filtered rows,
|
|
65
|
-
// // lets assign the final filtered rows to all of the other columns
|
|
66
|
-
// const nonFilteredColumns = instance
|
|
67
|
-
// .getAllLeafColumns()
|
|
68
|
-
// .filter(
|
|
69
|
-
// column =>
|
|
70
|
-
// !instance.getState().columnFilters?.find(d => d.id === column.id)
|
|
71
|
-
// )
|
|
72
|
-
|
|
73
|
-
// // This essentially enables faceted filter options to be built easily
|
|
74
|
-
// // using every column's preFilteredRows value
|
|
75
|
-
|
|
76
|
-
// nonFilteredColumns.forEach(column => {
|
|
77
|
-
// column.getPreFilteredRows = () => globalFilteredRowModel.rows
|
|
78
|
-
// })
|
|
79
|
-
|
|
80
|
-
// return globalFilteredRowModel
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
key: 'getGlobalFilteredRowModelAsync',
|
|
84
|
-
initialSync: opts?.initialSync,
|
|
85
|
-
onProgress: progress => {
|
|
86
|
-
instance.setState(old => ({ ...old, globalFilterProgress: progress }))
|
|
87
|
-
},
|
|
88
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
89
|
-
onChange: () => {
|
|
90
|
-
instance.queue(() => {
|
|
91
|
-
instance._autoResetPageIndex()
|
|
92
|
-
})
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
)
|
|
96
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { TableInstance, RowModel, TableGenerics, Row } from '../types'
|
|
2
|
-
import { memo } from '../utils'
|
|
3
|
-
import {
|
|
4
|
-
filterRowModelFromLeafs,
|
|
5
|
-
filterRowModelFromRoot,
|
|
6
|
-
} from './filterRowsUtils'
|
|
7
|
-
|
|
8
|
-
export function getGlobalFilteredRowModelSync<
|
|
9
|
-
TGenerics extends TableGenerics
|
|
10
|
-
>(): (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics> {
|
|
11
|
-
return instance =>
|
|
12
|
-
memo(
|
|
13
|
-
() => [
|
|
14
|
-
instance.getState().globalFilter,
|
|
15
|
-
instance.getPreGlobalFilteredRowModel(),
|
|
16
|
-
],
|
|
17
|
-
(globalFilter, rowModel) => {
|
|
18
|
-
const globalFilteredRowModel: RowModel<TGenerics> = (() => {
|
|
19
|
-
if (!rowModel.rows.length || !globalFilter) {
|
|
20
|
-
return rowModel
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const filterFromLeafRows = instance.options.filterFromLeafRows
|
|
24
|
-
|
|
25
|
-
const filterFn = instance.getGlobalFilterFn()
|
|
26
|
-
|
|
27
|
-
if (!filterFn) {
|
|
28
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
29
|
-
console.warn(`Could not find a valid 'globalFilterType'`)
|
|
30
|
-
}
|
|
31
|
-
return rowModel
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const filterableColumns = instance
|
|
35
|
-
.getAllLeafColumns()
|
|
36
|
-
.filter(column => column.getCanGlobalFilter())
|
|
37
|
-
|
|
38
|
-
const filterableColumnIds = filterableColumns.map(d => d.id)
|
|
39
|
-
|
|
40
|
-
const filterRows = (rows: Row<TGenerics>[]) => {
|
|
41
|
-
return filterFn(rows, filterableColumnIds, globalFilter)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (filterFromLeafRows) {
|
|
45
|
-
return filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return filterRowModelFromRoot(rowModel.rows, filterRows, instance)
|
|
49
|
-
})()
|
|
50
|
-
|
|
51
|
-
// Now that each filtered column has it's partially filtered rows,
|
|
52
|
-
// lets assign the final filtered rows to all of the other columns
|
|
53
|
-
const nonFilteredColumns = instance
|
|
54
|
-
.getAllLeafColumns()
|
|
55
|
-
.filter(
|
|
56
|
-
column =>
|
|
57
|
-
!instance.getState().columnFilters?.find(d => d.id === column.id)
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
// This essentially enables faceted filter options to be built easily
|
|
61
|
-
// using every column's preFilteredRows value
|
|
62
|
-
|
|
63
|
-
nonFilteredColumns.forEach(column => {
|
|
64
|
-
column.getPreFilteredRows = () => globalFilteredRowModel.rows
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
return globalFilteredRowModel
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
key: 'getGlobalFilteredRowModelSync',
|
|
71
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
72
|
-
onChange: () => {
|
|
73
|
-
instance.queue(() => {
|
|
74
|
-
instance._autoResetPageIndex()
|
|
75
|
-
})
|
|
76
|
-
},
|
|
77
|
-
}
|
|
78
|
-
)
|
|
79
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { TableInstance, Row, RowModel, TableGenerics } from '../types'
|
|
2
|
-
import { incrementalMemo, memo } from '../utils'
|
|
3
|
-
|
|
4
|
-
export function getSortedRowModelSync<TGenerics extends TableGenerics>(opts?: {
|
|
5
|
-
initialSync?: boolean
|
|
6
|
-
}): (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics> {
|
|
7
|
-
return instance =>
|
|
8
|
-
incrementalMemo(
|
|
9
|
-
() => [instance.getState().sorting, instance.getPreSortedRowModel()],
|
|
10
|
-
(_sorting, rowModel): RowModel<TGenerics> => {
|
|
11
|
-
return {
|
|
12
|
-
rows: rowModel.rows.slice(),
|
|
13
|
-
flatRows: [],
|
|
14
|
-
rowsById: rowModel.rowsById,
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
(sorting, rowModel) => rowModelRef => scheduleTask => {
|
|
18
|
-
// TODO: Figure out how to do async sorting
|
|
19
|
-
// We probably need to use a sorting algo that is "divide and
|
|
20
|
-
// conquer", since that will probably distribute the easiest into
|
|
21
|
-
// separate tasks. The trick will be batching those tasks in a way
|
|
22
|
-
// that makes them fast. JS work loops don't tend to do well with
|
|
23
|
-
// a high number of tasks that do one thing. Instead, shoot for each
|
|
24
|
-
// task to have a few thousand opts (or whatever amount is generally
|
|
25
|
-
// fast for most devices).
|
|
26
|
-
|
|
27
|
-
throw new Error()
|
|
28
|
-
|
|
29
|
-
// if (!rowModel.rows.length || !sorting?.length) {
|
|
30
|
-
// rowModelRef.current = rowModel
|
|
31
|
-
// return
|
|
32
|
-
// }
|
|
33
|
-
|
|
34
|
-
// const sortingState = instance.getState().sorting
|
|
35
|
-
|
|
36
|
-
// const sortedFlatRows: Row<TGenerics>[] = []
|
|
37
|
-
|
|
38
|
-
// // Filter out sortings that correspond to non existing columns
|
|
39
|
-
// const availableSorting = sortingState.filter(sort =>
|
|
40
|
-
// instance.getColumnCanSort(sort.id)
|
|
41
|
-
// )
|
|
42
|
-
|
|
43
|
-
// const sorters = availableSorting.map(columnSorting => {
|
|
44
|
-
// const column = instance.getColumn(columnSorting.id)!
|
|
45
|
-
// const sortingFn = instance.getColumnSortingFn(columnSorting.id)!
|
|
46
|
-
|
|
47
|
-
// return {
|
|
48
|
-
// id: columnSorting.id,
|
|
49
|
-
// compare: (rowA: Row<TGenerics>, rowB: Row<TGenerics>) =>
|
|
50
|
-
// sortingFn(rowA, rowB, columnSorting.id),
|
|
51
|
-
// desc: columnSorting.desc,
|
|
52
|
-
// invertSorting: column.invertSorting,
|
|
53
|
-
// sortUndefined: column.sortUndefined,
|
|
54
|
-
// }
|
|
55
|
-
// })
|
|
56
|
-
|
|
57
|
-
// const sortData = (rows: Row<TGenerics>[]) => {
|
|
58
|
-
// // This will also perform a stable sorting using the row index
|
|
59
|
-
// // if needed.
|
|
60
|
-
|
|
61
|
-
// const sortedData = quicksort(rows, sorters)
|
|
62
|
-
|
|
63
|
-
// // If there are sub-rows, sort them
|
|
64
|
-
// sortedData.forEach(row => {
|
|
65
|
-
// rowModelRef.current.flatRows.push(row)
|
|
66
|
-
// if (!row.subRows || row.subRows.length <= 1) {
|
|
67
|
-
// return
|
|
68
|
-
// }
|
|
69
|
-
// row.subRows = sortData(row.subRows)
|
|
70
|
-
// })
|
|
71
|
-
|
|
72
|
-
// return sortedData
|
|
73
|
-
// }
|
|
74
|
-
|
|
75
|
-
// sortData(rowModelRef.current.rows)
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
key: 'getSortedRowModel',
|
|
79
|
-
initialSync: opts?.initialSync,
|
|
80
|
-
onProgress: progress => {
|
|
81
|
-
instance.setState(old => ({ ...old, sortingProgress: progress }))
|
|
82
|
-
},
|
|
83
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
84
|
-
onChange: () => {
|
|
85
|
-
instance.queue(() => {
|
|
86
|
-
instance._autoResetPageIndex()
|
|
87
|
-
})
|
|
88
|
-
},
|
|
89
|
-
}
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
type Sorter<TGenerics extends TableGenerics> = {
|
|
94
|
-
id: string
|
|
95
|
-
compare: (a: Row<TGenerics>, b: Row<TGenerics>) => number
|
|
96
|
-
desc?: boolean
|
|
97
|
-
sortUndefined?: false | -1 | 1
|
|
98
|
-
invertSorting?: boolean
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function quicksort<TGenerics extends TableGenerics>(
|
|
102
|
-
rows: Row<TGenerics>[],
|
|
103
|
-
sorters: Sorter<TGenerics>[]
|
|
104
|
-
): Row<TGenerics>[] {
|
|
105
|
-
if (!rows.length) {
|
|
106
|
-
return rows
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Copy the rows so we can mutate the order
|
|
110
|
-
rows = rows.slice()
|
|
111
|
-
|
|
112
|
-
// Start the quicksort recursion
|
|
113
|
-
recurse(0, rows.length - 1)
|
|
114
|
-
|
|
115
|
-
// Return the rows
|
|
116
|
-
return rows
|
|
117
|
-
|
|
118
|
-
function recurse(start: number, end: number) {
|
|
119
|
-
const pivotIndex = pivot(start, end)
|
|
120
|
-
|
|
121
|
-
if (start < pivotIndex - 1) {
|
|
122
|
-
recurse(start, pivotIndex - 1)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (pivotIndex < end) {
|
|
126
|
-
recurse(pivotIndex + 1, end)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function pivot(start: number, end: number) {
|
|
131
|
-
const pivotIndex = Math.floor((start + end) / 2)
|
|
132
|
-
let i = start
|
|
133
|
-
let j = end
|
|
134
|
-
|
|
135
|
-
const compare = (a: number, b: number) => {
|
|
136
|
-
const rowA = rows[a]
|
|
137
|
-
const rowB = rows[b]
|
|
138
|
-
|
|
139
|
-
for (let i = 0; i < sorters.length; i += 1) {
|
|
140
|
-
const sorter = sorters[i]!
|
|
141
|
-
const isDesc = sorter?.desc ?? false
|
|
142
|
-
|
|
143
|
-
if (sorter.sortUndefined) {
|
|
144
|
-
const aValue = rowA.values[sorter.id]
|
|
145
|
-
const bValue = rowB.values[sorter.id]
|
|
146
|
-
|
|
147
|
-
const aUndefined = typeof aValue === 'undefined'
|
|
148
|
-
const bUndefined = typeof bValue === 'undefined'
|
|
149
|
-
|
|
150
|
-
if (aUndefined || bUndefined) {
|
|
151
|
-
if (aUndefined !== bUndefined) {
|
|
152
|
-
return aUndefined ? sorter.sortUndefined : -sorter.sortUndefined
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// This function should always return in ascending order
|
|
158
|
-
let sortInt = sorter.compare(rowA, rowB)
|
|
159
|
-
|
|
160
|
-
if (sortInt !== 0) {
|
|
161
|
-
if (isDesc) {
|
|
162
|
-
sortInt *= -1
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (sorter.invertSorting) {
|
|
166
|
-
sortInt *= -1
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return sortInt
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return rowA.index < rowB.index ? -1 : 1
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
while (i <= j) {
|
|
177
|
-
while (compare(i, pivotIndex) < 0) {
|
|
178
|
-
i++
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
while (compare(pivotIndex, j) < 0) {
|
|
182
|
-
j--
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (i <= j) {
|
|
186
|
-
swap(rows, i, j)
|
|
187
|
-
i++
|
|
188
|
-
j--
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return i
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function swap<T>(arr: T[], a: number, b: number) {
|
|
196
|
-
const t = arr[a]
|
|
197
|
-
arr[a] = arr[b]
|
|
198
|
-
arr[b] = t
|
|
199
|
-
}
|
|
200
|
-
}
|