@tanstack/react-table 8.0.0-alpha.9 → 8.0.0-beta.0
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/react-table/src/index.js +139 -0
- package/build/cjs/react-table/src/index.js.map +1 -0
- package/build/cjs/table-core/build/esm/index.js +3867 -0
- package/build/cjs/table-core/build/esm/index.js.map +1 -0
- package/build/esm/index.js +3196 -4117
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +24 -813
- package/build/types/index.d.ts +16 -9
- package/build/umd/index.development.js +3234 -4125
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +11 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +10 -6
- package/src/index.tsx +111 -9
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/aggregationTypes.js +0 -130
- package/build/cjs/aggregationTypes.js.map +0 -1
- package/build/cjs/core.js +0 -545
- package/build/cjs/core.js.map +0 -1
- package/build/cjs/createTable.js +0 -122
- package/build/cjs/createTable.js.map +0 -1
- package/build/cjs/features/ColumnSizing.js +0 -318
- package/build/cjs/features/ColumnSizing.js.map +0 -1
- package/build/cjs/features/Expanding.js +0 -239
- package/build/cjs/features/Expanding.js.map +0 -1
- package/build/cjs/features/Filters.js +0 -414
- package/build/cjs/features/Filters.js.map +0 -1
- package/build/cjs/features/Grouping.js +0 -232
- package/build/cjs/features/Grouping.js.map +0 -1
- package/build/cjs/features/Headers.js +0 -629
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/features/Ordering.js +0 -86
- package/build/cjs/features/Ordering.js.map +0 -1
- package/build/cjs/features/Pagination.js +0 -193
- package/build/cjs/features/Pagination.js.map +0 -1
- package/build/cjs/features/Pinning.js +0 -149
- package/build/cjs/features/Pinning.js.map +0 -1
- package/build/cjs/features/RowSelection.js +0 -526
- package/build/cjs/features/RowSelection.js.map +0 -1
- package/build/cjs/features/Sorting.js +0 -315
- package/build/cjs/features/Sorting.js.map +0 -1
- package/build/cjs/features/Visibility.js +0 -174
- package/build/cjs/features/Visibility.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/index.js +0 -44
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/sortTypes.js +0 -122
- package/build/cjs/sortTypes.js.map +0 -1
- package/build/cjs/types.js +0 -22
- package/build/cjs/types.js.map +0 -1
- package/build/cjs/utils/columnFilterRowsFn.js +0 -131
- package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/expandRowsFn.js +0 -38
- package/build/cjs/utils/expandRowsFn.js.map +0 -1
- package/build/cjs/utils/globalFilterRowsFn.js +0 -101
- 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/cjs/utils.js +0 -167
- package/build/cjs/utils.js.map +0 -1
- package/build/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -105
- package/build/types/createTable.d.ts +0 -42
- package/build/types/features/ColumnSizing.d.ts +0 -73
- package/build/types/features/Expanding.d.ts +0 -48
- package/build/types/features/Filters.d.ts +0 -90
- package/build/types/features/Grouping.d.ts +0 -83
- package/build/types/features/Headers.d.ts +0 -41
- package/build/types/features/Ordering.d.ts +0 -19
- package/build/types/features/Pagination.d.ts +0 -39
- package/build/types/features/Pinning.d.ts +0 -39
- package/build/types/features/RowSelection.d.ts +0 -58
- package/build/types/features/Sorting.d.ts +0 -79
- package/build/types/features/Visibility.d.ts +0 -47
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- package/build/types/types.d.ts +0 -138
- 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/build/types/utils.d.ts +0 -23
- package/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -763
- package/src/createTable.tsx +0 -186
- package/src/features/ColumnSizing.ts +0 -424
- package/src/features/Expanding.ts +0 -318
- package/src/features/Filters.ts +0 -560
- package/src/features/Grouping.ts +0 -361
- package/src/features/Headers.ts +0 -729
- package/src/features/Ordering.ts +0 -110
- package/src/features/Pagination.ts +0 -250
- package/src/features/Pinning.ts +0 -174
- package/src/features/RowSelection.ts +0 -651
- package/src/features/Sorting.ts +0 -453
- package/src/features/Visibility.ts +0 -238
- package/src/filterTypes.ts +0 -188
- package/src/sortTypes.ts +0 -147
- package/src/types.ts +0 -311
- package/src/utils/columnFilterRowsFn.ts +0 -113
- package/src/utils/expandRowsFn.ts +0 -30
- package/src/utils/globalFilterRowsFn.ts +0 -89
- package/src/utils/groupRowsFn.ts +0 -170
- package/src/utils/paginateRowsFn.ts +0 -28
- package/src/utils/sortRowsFn.ts +0 -95
- package/src/utils.tsx +0 -221
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
|
|
2
|
-
|
|
3
|
-
export function columnFilterRowsFn<TGenerics extends PartialGenerics>(
|
|
4
|
-
instance: TableInstance<TGenerics>,
|
|
5
|
-
rowModel: RowModel<TGenerics>
|
|
6
|
-
): RowModel<TGenerics> {
|
|
7
|
-
const columnFilters = instance.getState().columnFilters
|
|
8
|
-
|
|
9
|
-
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
10
|
-
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
11
|
-
|
|
12
|
-
const filterFromChildrenUp = instance.options.filterFromChildrenUp
|
|
13
|
-
|
|
14
|
-
const filterRows = (rowsToFilter: Row<TGenerics>[], depth: number) => {
|
|
15
|
-
columnFilters.forEach(({ id: columnId, value: filterValue }) => {
|
|
16
|
-
// Find the columnFilters column
|
|
17
|
-
const column = instance.getColumn(columnId)
|
|
18
|
-
|
|
19
|
-
if (!column) {
|
|
20
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
21
|
-
console.warn(
|
|
22
|
-
`React-Table: Could not find a column with id: ${columnId}`
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
throw new Error()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (depth === 0) {
|
|
29
|
-
const preFilteredRows = [...rowsToFilter]
|
|
30
|
-
column.getPreFilteredRows = () => preFilteredRows
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const filterFn = instance.getColumnFilterFn(column.id)
|
|
34
|
-
|
|
35
|
-
if (!filterFn) {
|
|
36
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
37
|
-
console.warn(
|
|
38
|
-
`Could not find a valid 'column.filterType' for column with the ID: ${column.id}.`
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Pass the rows, id, filterValue and column to the filterFn
|
|
45
|
-
// to get the filtered rows back
|
|
46
|
-
rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
return rowsToFilter
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (filterFromChildrenUp) {
|
|
53
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
54
|
-
// Filter from children up
|
|
55
|
-
rowsToFilter = rowsToFilter.filter(row => {
|
|
56
|
-
if (!row.subRows?.length) {
|
|
57
|
-
return true
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
61
|
-
|
|
62
|
-
return row.subRows.length
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
rowsToFilter = filterRows(rowsToFilter, depth)
|
|
66
|
-
|
|
67
|
-
// Apply the filter to any subRows
|
|
68
|
-
rowsToFilter.forEach(row => {
|
|
69
|
-
newFilteredFlatRows.push(row)
|
|
70
|
-
newFilteredRowsById[row.id] = row
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return rowsToFilter
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
78
|
-
flatRows: newFilteredFlatRows,
|
|
79
|
-
rowsById: newFilteredRowsById,
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Filters top level and nested rows
|
|
84
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
85
|
-
// Filter from parents downward
|
|
86
|
-
rowsToFilter = filterRows(rowsToFilter, depth)
|
|
87
|
-
|
|
88
|
-
// Apply the filter to any subRows
|
|
89
|
-
// We technically could do this recursively in the above loop,
|
|
90
|
-
// but that would severely hinder the API for the user, since they
|
|
91
|
-
// would be required to do that recursion in some scenarios
|
|
92
|
-
rowsToFilter.forEach(row => {
|
|
93
|
-
newFilteredFlatRows.push(row)
|
|
94
|
-
newFilteredRowsById[row.id] = row
|
|
95
|
-
|
|
96
|
-
if (!filterFromChildrenUp) {
|
|
97
|
-
if (!row.subRows?.length) {
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
return rowsToFilter
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
110
|
-
flatRows: newFilteredFlatRows,
|
|
111
|
-
rowsById: newFilteredRowsById,
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
|
|
2
|
-
|
|
3
|
-
export function expandRowsFn<TGenerics extends PartialGenerics>(
|
|
4
|
-
instance: TableInstance<TGenerics>,
|
|
5
|
-
sortedRowModel: RowModel<TGenerics>
|
|
6
|
-
): RowModel<TGenerics> {
|
|
7
|
-
const expandedRows: Row<TGenerics>[] = []
|
|
8
|
-
|
|
9
|
-
const { expandSubRows } = instance.options
|
|
10
|
-
|
|
11
|
-
const handleRow = (row: Row<TGenerics>) => {
|
|
12
|
-
expandedRows.push(row)
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
expandSubRows &&
|
|
16
|
-
row.subRows?.length &&
|
|
17
|
-
instance.getIsRowExpanded(row.id)
|
|
18
|
-
) {
|
|
19
|
-
row.subRows.forEach(handleRow)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
sortedRowModel.rows.forEach(handleRow)
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
rows: expandedRows,
|
|
27
|
-
flatRows: sortedRowModel.flatRows,
|
|
28
|
-
rowsById: sortedRowModel.rowsById,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
|
|
2
|
-
|
|
3
|
-
export function globalFilterRowsFn<TGenerics extends PartialGenerics>(
|
|
4
|
-
instance: TableInstance<TGenerics>,
|
|
5
|
-
rowModel: RowModel<TGenerics>
|
|
6
|
-
): RowModel<TGenerics> {
|
|
7
|
-
const globalFilter = instance.getState().globalFilter
|
|
8
|
-
const newFilteredFlatRows: Row<TGenerics>[] = []
|
|
9
|
-
const newFilteredRowsById: Record<string, Row<TGenerics>> = {}
|
|
10
|
-
|
|
11
|
-
const filterFromChildrenUp = instance.options.filterFromChildrenUp
|
|
12
|
-
|
|
13
|
-
const filterFn = instance.getGlobalFilterFn()
|
|
14
|
-
|
|
15
|
-
if (!filterFn) {
|
|
16
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
17
|
-
console.warn(`Could not find a valid 'globalFilterType'`)
|
|
18
|
-
}
|
|
19
|
-
return rowModel
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const filterableColumns = instance
|
|
23
|
-
.getAllLeafColumns()
|
|
24
|
-
.filter(column => column.getCanGlobalFilter())
|
|
25
|
-
|
|
26
|
-
const filterableColumnIds = filterableColumns.map(d => d.id)
|
|
27
|
-
|
|
28
|
-
if (filterFromChildrenUp) {
|
|
29
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
30
|
-
// Filter from children up
|
|
31
|
-
rowsToFilter = rowsToFilter.filter(row => {
|
|
32
|
-
if (!row.subRows?.length) {
|
|
33
|
-
return true
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
37
|
-
|
|
38
|
-
return row.subRows.length
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter)
|
|
42
|
-
|
|
43
|
-
// Apply the filter to any subRows
|
|
44
|
-
rowsToFilter.forEach(row => {
|
|
45
|
-
newFilteredFlatRows.push(row)
|
|
46
|
-
newFilteredRowsById[row.id] = row
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
return rowsToFilter
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
54
|
-
flatRows: newFilteredFlatRows,
|
|
55
|
-
rowsById: newFilteredRowsById,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Filters top level and nested rows
|
|
60
|
-
const recurseFilterRows = (rowsToFilter: Row<TGenerics>[], depth = 0) => {
|
|
61
|
-
// Filter from parents downward
|
|
62
|
-
rowsToFilter = filterFn(rowsToFilter, filterableColumnIds, globalFilter)
|
|
63
|
-
|
|
64
|
-
// Apply the filter to any subRows
|
|
65
|
-
// We technically could do this recursively in the above loop,
|
|
66
|
-
// but that would severely hinder the API for the user, since they
|
|
67
|
-
// would be required to do that recursion in some scenarios
|
|
68
|
-
rowsToFilter.forEach(row => {
|
|
69
|
-
newFilteredFlatRows.push(row)
|
|
70
|
-
newFilteredRowsById[row.id] = row
|
|
71
|
-
|
|
72
|
-
if (!filterFromChildrenUp) {
|
|
73
|
-
if (!row.subRows?.length) {
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
row.subRows = recurseFilterRows(row.subRows, depth + 1)
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
return rowsToFilter
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
rows: recurseFilterRows(rowModel.rows),
|
|
86
|
-
flatRows: newFilteredFlatRows,
|
|
87
|
-
rowsById: newFilteredRowsById,
|
|
88
|
-
}
|
|
89
|
-
}
|
package/src/utils/groupRowsFn.ts
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
|
|
2
|
-
import { flattenBy } from '../utils'
|
|
3
|
-
|
|
4
|
-
export function groupRowsFn<TGenerics extends PartialGenerics>(
|
|
5
|
-
instance: TableInstance<TGenerics>,
|
|
6
|
-
sortedRowModel: RowModel<TGenerics>
|
|
7
|
-
): RowModel<TGenerics> {
|
|
8
|
-
const groupingState = instance.getState().grouping
|
|
9
|
-
// Filter the grouping list down to columns that exist
|
|
10
|
-
const existingGrouping = groupingState.filter(columnId =>
|
|
11
|
-
instance.getColumn(columnId)
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
// Find the columns that can or are aggregating
|
|
15
|
-
// Uses each column to aggregate rows into a single value
|
|
16
|
-
const aggregateRowsToValues = (
|
|
17
|
-
leafRows: Row<TGenerics>[],
|
|
18
|
-
groupedRows: Row<TGenerics>[],
|
|
19
|
-
depth: number
|
|
20
|
-
) => {
|
|
21
|
-
const values: Record<string, unknown> = {}
|
|
22
|
-
|
|
23
|
-
instance.getAllLeafColumns().forEach(column => {
|
|
24
|
-
// Don't aggregate columns that are in the grouping
|
|
25
|
-
if (existingGrouping.includes(column.id)) {
|
|
26
|
-
values[column.id] = groupedRows[0]
|
|
27
|
-
? groupedRows[0].values[column.id]
|
|
28
|
-
: null
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Aggregate the values
|
|
33
|
-
const aggregateFn = instance.getColumnAggregationFn(column.id)
|
|
34
|
-
|
|
35
|
-
if (aggregateFn) {
|
|
36
|
-
// Get the columnValues to aggregate
|
|
37
|
-
const groupedValues = groupedRows.map(row => row.values[column.id])
|
|
38
|
-
|
|
39
|
-
// Get the columnValues to aggregate
|
|
40
|
-
const leafValues = leafRows.map(row => {
|
|
41
|
-
let columnValue = row.values[column.id]
|
|
42
|
-
|
|
43
|
-
if (!depth && column.aggregateValue) {
|
|
44
|
-
columnValue = column.aggregateValue(columnValue)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return columnValue
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
values[column.id] = aggregateFn(leafValues, groupedValues)
|
|
51
|
-
} else if (column.aggregationType) {
|
|
52
|
-
console.info({ column })
|
|
53
|
-
throw new Error(
|
|
54
|
-
process.env.NODE_ENV !== 'production'
|
|
55
|
-
? `React Table: Invalid column.aggregateType option for column listed above`
|
|
56
|
-
: ''
|
|
57
|
-
)
|
|
58
|
-
} else {
|
|
59
|
-
values[column.id] = null
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
return values
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const groupedFlatRows: Row<TGenerics>[] = []
|
|
67
|
-
const groupedRowsById: Record<string, Row<TGenerics>> = {}
|
|
68
|
-
// const onlyGroupedFlatRows: Row[] = [];
|
|
69
|
-
// const onlyGroupedRowsById: Record<RowId, Row> = {};
|
|
70
|
-
// const nonGroupedFlatRows: Row[] = [];
|
|
71
|
-
// const nonGroupedRowsById: Record<RowId, Row> = {};
|
|
72
|
-
|
|
73
|
-
// Recursively group the data
|
|
74
|
-
const groupUpRecursively = (
|
|
75
|
-
rows: Row<TGenerics>[],
|
|
76
|
-
depth = 0,
|
|
77
|
-
parentId: string
|
|
78
|
-
) => {
|
|
79
|
-
// This is the last level, just return the rows
|
|
80
|
-
if (depth === existingGrouping.length) {
|
|
81
|
-
return rows
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const columnId = existingGrouping[depth]!
|
|
85
|
-
|
|
86
|
-
// Group the rows together for this level
|
|
87
|
-
const rowGroupsMap = groupBy(rows, columnId)
|
|
88
|
-
|
|
89
|
-
// Peform aggregations for each group
|
|
90
|
-
const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(
|
|
91
|
-
([groupingValue, groupedRows], index) => {
|
|
92
|
-
let id = `${columnId}:${groupingValue}`
|
|
93
|
-
id = parentId ? `${parentId}>${id}` : id
|
|
94
|
-
|
|
95
|
-
// First, Recurse to group sub rows before aggregation
|
|
96
|
-
const subRows = groupUpRecursively(groupedRows, depth + 1, id)
|
|
97
|
-
|
|
98
|
-
// Flatten the leaf rows of the rows in this group
|
|
99
|
-
const leafRows = depth
|
|
100
|
-
? flattenBy(groupedRows, row => row.leafRows)
|
|
101
|
-
: groupedRows
|
|
102
|
-
|
|
103
|
-
const values = aggregateRowsToValues(leafRows, groupedRows, depth)
|
|
104
|
-
|
|
105
|
-
const row = instance.createRow(id, undefined, index, depth, values)
|
|
106
|
-
|
|
107
|
-
Object.assign(row, {
|
|
108
|
-
groupingColumnId: columnId,
|
|
109
|
-
groupingValue,
|
|
110
|
-
subRows,
|
|
111
|
-
leafRows,
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
subRows.forEach(subRow => {
|
|
115
|
-
groupedFlatRows.push(subRow)
|
|
116
|
-
groupedRowsById[subRow.id] = subRow
|
|
117
|
-
// if (subRow.getIsGrouped?.()) {
|
|
118
|
-
// onlyGroupedFlatRows.push(subRow);
|
|
119
|
-
// onlyGroupedRowsById[subRow.id] = subRow;
|
|
120
|
-
// } else {
|
|
121
|
-
// nonGroupedFlatRows.push(subRow);
|
|
122
|
-
// nonGroupedRowsById[subRow.id] = subRow;
|
|
123
|
-
// }
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
return row
|
|
127
|
-
}
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
return aggregatedGroupedRows
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const groupedRows = groupUpRecursively(sortedRowModel.rows, 0, '')
|
|
134
|
-
|
|
135
|
-
groupedRows.forEach(subRow => {
|
|
136
|
-
groupedFlatRows.push(subRow)
|
|
137
|
-
groupedRowsById[subRow.id] = subRow
|
|
138
|
-
// if (subRow.getIsGrouped?.()) {
|
|
139
|
-
// onlyGroupedFlatRows.push(subRow);
|
|
140
|
-
// onlyGroupedRowsById[subRow.id] = subRow;
|
|
141
|
-
// } else {
|
|
142
|
-
// nonGroupedFlatRows.push(subRow);
|
|
143
|
-
// nonGroupedRowsById[subRow.id] = subRow;
|
|
144
|
-
// }
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
rows: groupedRows,
|
|
149
|
-
flatRows: groupedFlatRows,
|
|
150
|
-
rowsById: groupedRowsById,
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function groupBy<TGenerics extends PartialGenerics>(
|
|
155
|
-
rows: Row<TGenerics>[],
|
|
156
|
-
columnId: string
|
|
157
|
-
) {
|
|
158
|
-
const groupMap = new Map<any, Row<TGenerics>[]>()
|
|
159
|
-
|
|
160
|
-
return rows.reduce((map, row) => {
|
|
161
|
-
const resKey = `${row.values[columnId]}`
|
|
162
|
-
const previous = map.get(resKey)
|
|
163
|
-
if (!previous) {
|
|
164
|
-
map.set(resKey, [row])
|
|
165
|
-
} else {
|
|
166
|
-
map.set(resKey, [...previous, row])
|
|
167
|
-
}
|
|
168
|
-
return map
|
|
169
|
-
}, groupMap)
|
|
170
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, RowModel } from '../types'
|
|
2
|
-
import { expandRowsFn } from './expandRowsFn'
|
|
3
|
-
|
|
4
|
-
export function paginateRowsFn<TGenerics extends PartialGenerics>(
|
|
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,95 +0,0 @@
|
|
|
1
|
-
import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
|
|
2
|
-
import { SortingFn } from '../features/Sorting'
|
|
3
|
-
|
|
4
|
-
export function sortRowsFn<TGenerics extends PartialGenerics>(
|
|
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 ? 0 : aUndefined ? 1 : -1
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// This function should always return in ascending order
|
|
60
|
-
let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)
|
|
61
|
-
|
|
62
|
-
if (sortInt !== 0) {
|
|
63
|
-
if (isDesc) {
|
|
64
|
-
sortInt *= -1
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (columnInfo.invertSorting) {
|
|
68
|
-
sortInt *= -1
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return sortInt
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return rowA.index - rowB.index
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
// If there are sub-rows, sort them
|
|
79
|
-
sortedData.forEach(row => {
|
|
80
|
-
sortedFlatRows.push(row)
|
|
81
|
-
if (!row.subRows || row.subRows.length <= 1) {
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
row.subRows = sortData(row.subRows)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
return sortedData
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
rows: sortData(rowModel.rows),
|
|
92
|
-
flatRows: sortedFlatRows,
|
|
93
|
-
rowsById: rowModel.rowsById,
|
|
94
|
-
}
|
|
95
|
-
}
|