@tanstack/table-core 8.0.0-alpha.27 → 8.0.0-alpha.32
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 +29 -79
- 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 +14 -18
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +29 -82
- 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 +10 -17
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +11 -17
- 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 +113 -0
- package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -0
- package/build/cjs/utils/getCoreRowModelAsync.js +125 -0
- package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -0
- package/build/cjs/utils/getCoreRowModelSync.js +102 -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 +89 -0
- package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -0
- package/build/cjs/utils/getGroupedRowModel.js +174 -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 +116 -0
- package/build/cjs/utils/getSortedRowModelSync.js.map +1 -0
- package/build/cjs/utils.js +159 -21
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +857 -505
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +406 -312
- package/build/types/aggregationTypes.d.ts +1 -1
- package/build/types/core.d.ts +9 -1
- package/build/types/createTable.d.ts +2 -4
- 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 +3 -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 +872 -513
- 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/aggregationTypes.ts +1 -1
- package/src/core.tsx +46 -99
- package/src/createTable.tsx +2 -6
- package/src/features/Expanding.ts +21 -29
- package/src/features/Filters.ts +53 -100
- package/src/features/Grouping.ts +19 -21
- package/src/features/Pagination.ts +19 -28
- package/src/features/Sorting.ts +20 -24
- package/src/index.tsx +8 -6
- package/src/types.ts +4 -1
- package/src/utils/getColumnFilteredRowModelAsync.ts +117 -0
- package/src/utils/getColumnFilteredRowModelSync.ts +97 -0
- package/src/utils/getCoreRowModelAsync.ts +103 -0
- package/src/utils/getCoreRowModelSync.ts +105 -0
- package/src/utils/getExpandedRowModel.ts +58 -0
- package/src/utils/getGlobalFilteredRowModelAsync.ts +95 -0
- package/src/utils/getGlobalFilteredRowModelSync.ts +74 -0
- package/src/utils/getGroupedRowModel.ts +187 -0
- package/src/utils/getPaginationRowModel.ts +45 -0
- package/src/utils/getSortedRowModelAsync.ts +199 -0
- package/src/utils/getSortedRowModelSync.ts +116 -0
- package/src/utils.tsx +193 -22
- 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
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { TableInstance, RowModel, AnyGenerics } from '../types'
|
|
2
|
-
import { expandRowsFn } from './expandRowsFn'
|
|
3
|
-
|
|
4
|
-
export function paginateRowsFn<TGenerics extends AnyGenerics>(
|
|
5
|
-
instance: TableInstance<TGenerics>,
|
|
6
|
-
rowModel: RowModel<TGenerics>
|
|
7
|
-
): RowModel<TGenerics> {
|
|
8
|
-
const { pageSize, pageIndex } = instance.getState().pagination
|
|
9
|
-
let { rows, flatRows, rowsById } = rowModel
|
|
10
|
-
const pageStart = pageSize * pageIndex
|
|
11
|
-
const pageEnd = pageStart + pageSize
|
|
12
|
-
|
|
13
|
-
rows = rows.slice(pageStart, pageEnd)
|
|
14
|
-
|
|
15
|
-
if (!instance.options.paginateExpandedRows) {
|
|
16
|
-
return expandRowsFn(instance, {
|
|
17
|
-
rows,
|
|
18
|
-
flatRows,
|
|
19
|
-
rowsById,
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
rows,
|
|
25
|
-
flatRows,
|
|
26
|
-
rowsById,
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/utils/sortRowsFn.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { TableInstance, Row, RowModel, AnyGenerics } from '../types'
|
|
2
|
-
import { SortingFn } from '../features/Sorting'
|
|
3
|
-
|
|
4
|
-
export function sortRowsFn<TGenerics extends AnyGenerics>(
|
|
5
|
-
instance: TableInstance<TGenerics>,
|
|
6
|
-
rowModel: RowModel<TGenerics>
|
|
7
|
-
): RowModel<TGenerics> {
|
|
8
|
-
const sortingState = instance.getState().sorting
|
|
9
|
-
|
|
10
|
-
const sortedFlatRows: Row<TGenerics>[] = []
|
|
11
|
-
|
|
12
|
-
// Filter out sortings that correspond to non existing columns
|
|
13
|
-
const availableSorting = sortingState.filter(sort =>
|
|
14
|
-
instance.getColumnCanSort(sort.id)
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
const columnInfoById: Record<
|
|
18
|
-
string,
|
|
19
|
-
{
|
|
20
|
-
sortUndefined?: false | -1 | 1
|
|
21
|
-
invertSorting?: boolean
|
|
22
|
-
sortingFn: SortingFn<TGenerics>
|
|
23
|
-
}
|
|
24
|
-
> = {}
|
|
25
|
-
|
|
26
|
-
availableSorting.forEach(sortEntry => {
|
|
27
|
-
const column = instance.getColumn(sortEntry.id)!
|
|
28
|
-
|
|
29
|
-
columnInfoById[sortEntry.id] = {
|
|
30
|
-
sortUndefined: column.sortUndefined,
|
|
31
|
-
invertSorting: column.invertSorting,
|
|
32
|
-
sortingFn: instance.getColumnSortingFn(sortEntry.id)!,
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const sortData = (rows: Row<TGenerics>[]) => {
|
|
37
|
-
// This will also perform a stable sorting using the row index
|
|
38
|
-
// if needed.
|
|
39
|
-
const sortedData = rows.slice()
|
|
40
|
-
|
|
41
|
-
sortedData.sort((rowA, rowB) => {
|
|
42
|
-
for (let i = 0; i < availableSorting.length; i += 1) {
|
|
43
|
-
const sortEntry = availableSorting[i]!
|
|
44
|
-
const columnInfo = columnInfoById[sortEntry.id]!
|
|
45
|
-
const isDesc = sortEntry?.desc ?? false
|
|
46
|
-
|
|
47
|
-
if (columnInfo.sortUndefined) {
|
|
48
|
-
const aValue = rowA.values[sortEntry.id]
|
|
49
|
-
const bValue = rowB.values[sortEntry.id]
|
|
50
|
-
|
|
51
|
-
const aUndefined = typeof aValue === 'undefined'
|
|
52
|
-
const bUndefined = typeof bValue === 'undefined'
|
|
53
|
-
|
|
54
|
-
if (aUndefined || bUndefined) {
|
|
55
|
-
return aUndefined && bUndefined
|
|
56
|
-
? 0
|
|
57
|
-
: aUndefined
|
|
58
|
-
? columnInfo.sortUndefined
|
|
59
|
-
: -columnInfo.sortUndefined
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// This function should always return in ascending order
|
|
64
|
-
let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)
|
|
65
|
-
|
|
66
|
-
if (sortInt !== 0) {
|
|
67
|
-
if (isDesc) {
|
|
68
|
-
sortInt *= -1
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (columnInfo.invertSorting) {
|
|
72
|
-
sortInt *= -1
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return sortInt
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return rowA.index - rowB.index
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
// If there are sub-rows, sort them
|
|
83
|
-
sortedData.forEach(row => {
|
|
84
|
-
sortedFlatRows.push(row)
|
|
85
|
-
if (!row.subRows || row.subRows.length <= 1) {
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
row.subRows = sortData(row.subRows)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
return sortedData
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
rows: sortData(rowModel.rows),
|
|
96
|
-
flatRows: sortedFlatRows,
|
|
97
|
-
rowsById: rowModel.rowsById,
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { TableInstance, Row, RowModel, AnyGenerics } from '../types'
|
|
2
|
-
import { SortingFn } from '../features/Sorting'
|
|
3
|
-
|
|
4
|
-
export function sortRowsFn<TGenerics extends AnyGenerics>(
|
|
5
|
-
instance: TableInstance<TGenerics>,
|
|
6
|
-
rowModel: RowModel<TGenerics>
|
|
7
|
-
): RowModel<TGenerics> {
|
|
8
|
-
// window.tanner = []
|
|
9
|
-
|
|
10
|
-
const sortingState = instance.getState().sorting
|
|
11
|
-
|
|
12
|
-
const sortedFlatRows: Row<TGenerics>[] = []
|
|
13
|
-
|
|
14
|
-
// Filter out sortings that correspond to non existing columns
|
|
15
|
-
const availableSorting = sortingState.filter(sort =>
|
|
16
|
-
instance.getColumnCanSort(sort.id)
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
const sorters = availableSorting.map(columnSorting => {
|
|
20
|
-
const column = instance.getColumn(columnSorting.id)!
|
|
21
|
-
const sortingFn = instance.getColumnSortingFn(columnSorting.id)!
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
id: columnSorting.id,
|
|
25
|
-
compare: (rowA: Row<TGenerics>, rowB: Row<TGenerics>) =>
|
|
26
|
-
sortingFn(rowA, rowB, columnSorting.id),
|
|
27
|
-
desc: columnSorting.desc,
|
|
28
|
-
invertSorting: column.invertSorting,
|
|
29
|
-
sortUndefined: column.sortUndefined,
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const sortData = (rows: Row<TGenerics>[]) => {
|
|
34
|
-
// This will also perform a stable sorting using the row index
|
|
35
|
-
// if needed.
|
|
36
|
-
|
|
37
|
-
const sortedData = quicksort(rows, sorters)
|
|
38
|
-
|
|
39
|
-
// If there are sub-rows, sort them
|
|
40
|
-
sortedData.forEach(row => {
|
|
41
|
-
sortedFlatRows.push(row)
|
|
42
|
-
if (!row.subRows || row.subRows.length <= 1) {
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
row.subRows = sortData(row.subRows)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return sortedData
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
rows: sortData(rowModel.rows),
|
|
53
|
-
flatRows: sortedFlatRows,
|
|
54
|
-
rowsById: rowModel.rowsById,
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
type Sorter<TGenerics extends AnyGenerics> = {
|
|
59
|
-
id: string
|
|
60
|
-
compare: (a: Row<TGenerics>, b: Row<TGenerics>) => number
|
|
61
|
-
desc?: boolean
|
|
62
|
-
sortUndefined?: false | -1 | 1
|
|
63
|
-
invertSorting?: boolean
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function quicksort<TGenerics extends AnyGenerics>(
|
|
67
|
-
rows: Row<TGenerics>[],
|
|
68
|
-
sorters: Sorter<TGenerics>[]
|
|
69
|
-
): Row<TGenerics>[] {
|
|
70
|
-
if (!rows.length) {
|
|
71
|
-
return rows
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Copy the rows so we can mutate the order
|
|
75
|
-
rows = rows.slice()
|
|
76
|
-
|
|
77
|
-
// Start the quicksort recursion
|
|
78
|
-
recurse(0, rows.length - 1)
|
|
79
|
-
|
|
80
|
-
// Return the rows
|
|
81
|
-
return rows
|
|
82
|
-
|
|
83
|
-
function recurse(start: number, end: number) {
|
|
84
|
-
const pivotIndex = pivot(start, end)
|
|
85
|
-
|
|
86
|
-
if (start < pivotIndex - 1) {
|
|
87
|
-
recurse(start, pivotIndex - 1)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (pivotIndex < end) {
|
|
91
|
-
recurse(pivotIndex + 1, end)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function pivot(start: number, end: number) {
|
|
96
|
-
const pivotIndex = Math.floor((start + end) / 2)
|
|
97
|
-
let i = start
|
|
98
|
-
let j = end
|
|
99
|
-
|
|
100
|
-
const compare = (a: number, b: number) => {
|
|
101
|
-
const rowA = rows[a]
|
|
102
|
-
const rowB = rows[b]
|
|
103
|
-
|
|
104
|
-
for (let i = 0; i < sorters.length; i += 1) {
|
|
105
|
-
const sorter = sorters[i]!
|
|
106
|
-
const isDesc = sorter?.desc ?? false
|
|
107
|
-
|
|
108
|
-
if (sorter.sortUndefined) {
|
|
109
|
-
const aValue = rowA.values[sorter.id]
|
|
110
|
-
const bValue = rowB.values[sorter.id]
|
|
111
|
-
|
|
112
|
-
const aUndefined = typeof aValue === 'undefined'
|
|
113
|
-
const bUndefined = typeof bValue === 'undefined'
|
|
114
|
-
|
|
115
|
-
if (aUndefined || bUndefined) {
|
|
116
|
-
if (aUndefined !== bUndefined) {
|
|
117
|
-
return aUndefined ? sorter.sortUndefined : -sorter.sortUndefined
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// This function should always return in ascending order
|
|
123
|
-
let sortInt = sorter.compare(rowA, rowB)
|
|
124
|
-
|
|
125
|
-
if (i > 0) {
|
|
126
|
-
// window.tanner.push([
|
|
127
|
-
// sorter.id,
|
|
128
|
-
// rowA.values[sorter.id],
|
|
129
|
-
// rowB.values[sorter.id],
|
|
130
|
-
// sortInt,
|
|
131
|
-
// ])
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (sortInt !== 0) {
|
|
135
|
-
if (isDesc) {
|
|
136
|
-
sortInt *= -1
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (sorter.invertSorting) {
|
|
140
|
-
sortInt *= -1
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return sortInt
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return rowA.index < rowB.index ? -1 : 1
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
while (i <= j) {
|
|
151
|
-
while (compare(i, pivotIndex) < 0) {
|
|
152
|
-
i++
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
while (compare(pivotIndex, j) < 0) {
|
|
156
|
-
j--
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (i <= j) {
|
|
160
|
-
swap(rows, i, j)
|
|
161
|
-
i++
|
|
162
|
-
j--
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return i
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function swap<T>(arr: T[], a: number, b: number) {
|
|
170
|
-
const t = arr[a]
|
|
171
|
-
arr[a] = arr[b]
|
|
172
|
-
arr[b] = t
|
|
173
|
-
}
|
|
174
|
-
}
|