@tanstack/table-core 8.0.12 → 8.1.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/core/cell.js +13 -13
- package/build/cjs/core/cell.js.map +1 -1
- package/build/cjs/core/column.js +20 -21
- package/build/cjs/core/column.js.map +1 -1
- package/build/cjs/core/headers.js +63 -68
- package/build/cjs/core/headers.js.map +1 -1
- package/build/cjs/core/row.js +16 -11
- package/build/cjs/core/row.js.map +1 -1
- package/build/cjs/core/{instance.js → table.js} +46 -57
- package/build/cjs/core/table.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +36 -36
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +34 -34
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +46 -52
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +24 -49
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Ordering.js +8 -8
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +37 -37
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +33 -33
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +86 -74
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +36 -40
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +30 -30
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/index.js +3 -4
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +8 -8
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +8 -8
- package/build/cjs/utils/getCoreRowModel.js.map +1 -1
- package/build/cjs/utils/getExpandedRowModel.js +4 -4
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +3 -3
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -1
- package/build/cjs/utils/getFacetedRowModel.js +4 -4
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedUniqueValues.js +3 -3
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -1
- package/build/cjs/utils/getFilteredRowModel.js +8 -8
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +9 -9
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +4 -4
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +7 -7
- package/build/cjs/utils/getSortedRowModel.js.map +1 -1
- package/build/cjs/utils.js +2 -2
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +585 -677
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +352 -377
- package/build/types/index.d.ts +761 -29
- package/build/umd/index.development.js +586 -678
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/core/cell.ts +34 -28
- package/src/core/column.ts +83 -72
- package/src/core/headers.ts +118 -149
- package/src/core/row.ts +31 -25
- package/src/core/{instance.ts → table.ts} +85 -116
- package/src/features/ColumnSizing.ts +45 -47
- package/src/features/Expanding.ts +53 -59
- package/src/features/Filters.ts +112 -132
- package/src/features/Grouping.ts +63 -112
- package/src/features/Ordering.ts +19 -21
- package/src/features/Pagination.ts +54 -55
- package/src/features/Pinning.ts +49 -61
- package/src/features/RowSelection.ts +115 -114
- package/src/features/Sorting.ts +57 -72
- package/src/features/Visibility.ts +48 -48
- package/src/index.ts +1 -2
- package/src/types.ts +64 -69
- package/src/utils/filterRowsUtils.ts +33 -28
- package/src/utils/getCoreRowModel.ts +22 -22
- package/src/utils/getExpandedRowModel.ts +15 -15
- package/src/utils/getFacetedMinMaxValues.ts +6 -6
- package/src/utils/getFacetedRowModel.ts +12 -12
- package/src/utils/getFacetedUniqueValues.ts +6 -6
- package/src/utils/getFilteredRowModel.ts +17 -17
- package/src/utils/getGroupedRowModel.ts +18 -21
- package/src/utils/getPaginationRowModel.ts +10 -13
- package/src/utils/getSortedRowModel.ts +14 -14
- package/src/utils.ts +8 -2
- package/build/cjs/core/instance.js.map +0 -1
- package/build/cjs/createTable.js +0 -72
- package/build/cjs/createTable.js.map +0 -1
- package/build/types/aggregationFns.d.ts +0 -13
- package/build/types/core/cell.d.ts +0 -9
- package/build/types/core/column.d.ts +0 -40
- package/build/types/core/headers.d.ts +0 -46
- package/build/types/core/instance.d.ts +0 -58
- package/build/types/core/row.d.ts +0 -15
- package/build/types/createTable.d.ts +0 -63
- package/build/types/features/ColumnSizing.d.ts +0 -63
- package/build/types/features/Expanding.d.ts +0 -39
- package/build/types/features/Filters.d.ts +0 -90
- package/build/types/features/Grouping.d.ts +0 -68
- package/build/types/features/Ordering.d.ts +0 -18
- package/build/types/features/Pagination.d.ts +0 -42
- package/build/types/features/Pinning.d.ts +0 -40
- package/build/types/features/RowSelection.d.ts +0 -40
- package/build/types/features/Sorting.d.ts +0 -63
- package/build/types/features/Visibility.d.ts +0 -40
- package/build/types/filterFns.d.ts +0 -13
- package/build/types/sortingFns.d.ts +0 -11
- package/build/types/types.d.ts +0 -53
- package/build/types/utils/filterRowsUtils.d.ts +0 -4
- package/build/types/utils/getCoreRowModel.d.ts +0 -2
- package/build/types/utils/getExpandedRowModel.d.ts +0 -7
- package/build/types/utils/getFacetedMinMaxValues.d.ts +0 -2
- package/build/types/utils/getFacetedRowModel.d.ts +0 -2
- package/build/types/utils/getFacetedUniqueValues.d.ts +0 -2
- package/build/types/utils/getFilteredRowModel.d.ts +0 -2
- package/build/types/utils/getGroupedRowModel.d.ts +0 -2
- package/build/types/utils/getPaginationRowModel.d.ts +0 -4
- package/build/types/utils/getSortedRowModel.d.ts +0 -2
- package/build/types/utils.d.ts +0 -19
- package/src/createTable.ts +0 -188
package/src/features/Grouping.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { RowModel } from '..'
|
|
2
2
|
import { BuiltInAggregationFn, aggregationFns } from '../aggregationFns'
|
|
3
|
-
import { TableFeature } from '../core/
|
|
3
|
+
import { TableFeature } from '../core/table'
|
|
4
4
|
import {
|
|
5
5
|
Cell,
|
|
6
6
|
Column,
|
|
7
7
|
OnChangeFn,
|
|
8
|
-
|
|
8
|
+
Table,
|
|
9
9
|
Row,
|
|
10
10
|
Updater,
|
|
11
|
-
|
|
11
|
+
ColumnDefTemplate,
|
|
12
12
|
TableGenerics,
|
|
13
|
+
RowData,
|
|
13
14
|
} from '../types'
|
|
14
15
|
import { isFunction, makeStateUpdater, Overwrite } from '../utils'
|
|
15
16
|
|
|
@@ -19,46 +20,33 @@ export type GroupingTableState = {
|
|
|
19
20
|
grouping: GroupingState
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
export type AggregationFn<
|
|
23
|
+
export type AggregationFn<TData extends RowData> = (
|
|
23
24
|
columnId: string,
|
|
24
|
-
leafRows: Row<
|
|
25
|
-
childRows: Row<
|
|
25
|
+
leafRows: Row<TData>[],
|
|
26
|
+
childRows: Row<TData>[]
|
|
26
27
|
) => any
|
|
27
28
|
|
|
28
|
-
export type CustomAggregationFns
|
|
29
|
-
string,
|
|
30
|
-
AggregationFn<TGenerics>
|
|
31
|
-
>
|
|
29
|
+
export type CustomAggregationFns = Record<string, AggregationFn<any>>
|
|
32
30
|
|
|
33
|
-
export type AggregationFnOption<
|
|
31
|
+
export type AggregationFnOption<TData extends RowData> =
|
|
34
32
|
| 'auto'
|
|
35
33
|
| BuiltInAggregationFn
|
|
36
|
-
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
aggregatedCell?: Renderable<
|
|
42
|
-
TGenerics,
|
|
43
|
-
{
|
|
44
|
-
instance: TableInstance<TGenerics>
|
|
45
|
-
row: Row<TGenerics>
|
|
46
|
-
column: Column<TGenerics>
|
|
47
|
-
cell: Cell<TGenerics>
|
|
48
|
-
getValue: () => TGenerics['Value']
|
|
49
|
-
}
|
|
50
|
-
>
|
|
34
|
+
| AggregationFn<TData>
|
|
35
|
+
|
|
36
|
+
export type GroupingColumnDef<TData extends RowData> = {
|
|
37
|
+
aggregationFn?: AggregationFnOption<TData>
|
|
38
|
+
aggregatedCell?: ColumnDefTemplate<ReturnType<Cell<TData>['getContext']>>
|
|
51
39
|
enableGrouping?: boolean
|
|
52
40
|
}
|
|
53
41
|
|
|
54
|
-
export type GroupingColumn<
|
|
42
|
+
export type GroupingColumn<TData extends RowData> = {
|
|
55
43
|
getCanGroup: () => boolean
|
|
56
44
|
getIsGrouped: () => boolean
|
|
57
45
|
getGroupedIndex: () => number
|
|
58
46
|
toggleGrouping: () => void
|
|
59
47
|
getToggleGroupingHandler: () => () => void
|
|
60
|
-
getAutoAggregationFn: () => AggregationFn<
|
|
61
|
-
getAggregationFn: () => AggregationFn<
|
|
48
|
+
getAutoAggregationFn: () => AggregationFn<TData> | undefined
|
|
49
|
+
getAggregationFn: () => AggregationFn<TData> | undefined
|
|
62
50
|
}
|
|
63
51
|
|
|
64
52
|
export type GroupingRow = {
|
|
@@ -68,11 +56,10 @@ export type GroupingRow = {
|
|
|
68
56
|
_groupingValuesCache: Record<string, any>
|
|
69
57
|
}
|
|
70
58
|
|
|
71
|
-
export type GroupingCell
|
|
59
|
+
export type GroupingCell = {
|
|
72
60
|
getIsGrouped: () => boolean
|
|
73
61
|
getIsPlaceholder: () => boolean
|
|
74
62
|
getIsAggregated: () => boolean
|
|
75
|
-
renderAggregatedCell: () => string | null | TGenerics['Rendered']
|
|
76
63
|
}
|
|
77
64
|
|
|
78
65
|
export type ColumnDefaultOptions = {
|
|
@@ -81,33 +68,30 @@ export type ColumnDefaultOptions = {
|
|
|
81
68
|
enableGrouping: boolean
|
|
82
69
|
}
|
|
83
70
|
|
|
84
|
-
export type GroupingOptions
|
|
71
|
+
export type GroupingOptions = {
|
|
85
72
|
manualGrouping?: boolean
|
|
86
|
-
aggregationFns?: TGenerics['AggregationFns']
|
|
87
73
|
onGroupingChange?: OnChangeFn<GroupingState>
|
|
88
74
|
enableGrouping?: boolean
|
|
89
|
-
getGroupedRowModel?: (
|
|
75
|
+
getGroupedRowModel?: (table: Table<any>) => () => RowModel<any>
|
|
90
76
|
groupedColumnMode?: false | 'reorder' | 'remove'
|
|
91
77
|
}
|
|
92
78
|
|
|
93
79
|
export type GroupingColumnMode = false | 'reorder' | 'remove'
|
|
94
80
|
|
|
95
|
-
export type GroupingInstance<
|
|
81
|
+
export type GroupingInstance<TData extends RowData> = {
|
|
96
82
|
setGrouping: (updater: Updater<GroupingState>) => void
|
|
97
83
|
resetGrouping: (defaultState?: boolean) => void
|
|
98
|
-
getPreGroupedRowModel: () => RowModel<
|
|
99
|
-
getGroupedRowModel: () => RowModel<
|
|
100
|
-
_getGroupedRowModel?: () => RowModel<
|
|
84
|
+
getPreGroupedRowModel: () => RowModel<TData>
|
|
85
|
+
getGroupedRowModel: () => RowModel<TData>
|
|
86
|
+
_getGroupedRowModel?: () => RowModel<TData>
|
|
101
87
|
}
|
|
102
88
|
|
|
103
89
|
//
|
|
104
90
|
|
|
105
91
|
export const Grouping: TableFeature = {
|
|
106
|
-
getDefaultColumnDef: <
|
|
107
|
-
TGenerics extends TableGenerics
|
|
108
|
-
>(): GroupingColumnDef<TGenerics> => {
|
|
92
|
+
getDefaultColumnDef: <TData extends RowData>(): GroupingColumnDef<TData> => {
|
|
109
93
|
return {
|
|
110
|
-
aggregatedCell: props => props.getValue()?.toString?.() ?? null,
|
|
94
|
+
aggregatedCell: props => (props.getValue() as any)?.toString?.() ?? null,
|
|
111
95
|
aggregationFn: 'auto',
|
|
112
96
|
}
|
|
113
97
|
},
|
|
@@ -119,22 +103,22 @@ export const Grouping: TableFeature = {
|
|
|
119
103
|
}
|
|
120
104
|
},
|
|
121
105
|
|
|
122
|
-
getDefaultOptions: <
|
|
123
|
-
|
|
124
|
-
): GroupingOptions
|
|
106
|
+
getDefaultOptions: <TData extends RowData>(
|
|
107
|
+
table: Table<TData>
|
|
108
|
+
): GroupingOptions => {
|
|
125
109
|
return {
|
|
126
|
-
onGroupingChange: makeStateUpdater('grouping',
|
|
110
|
+
onGroupingChange: makeStateUpdater('grouping', table),
|
|
127
111
|
groupedColumnMode: 'reorder',
|
|
128
112
|
}
|
|
129
113
|
},
|
|
130
114
|
|
|
131
|
-
createColumn: <
|
|
132
|
-
column: Column<
|
|
133
|
-
|
|
134
|
-
): GroupingColumn<
|
|
115
|
+
createColumn: <TData extends RowData>(
|
|
116
|
+
column: Column<TData>,
|
|
117
|
+
table: Table<TData>
|
|
118
|
+
): GroupingColumn<TData> => {
|
|
135
119
|
return {
|
|
136
120
|
toggleGrouping: () => {
|
|
137
|
-
|
|
121
|
+
table.setGrouping(old => {
|
|
138
122
|
// Find any existing grouping for this column
|
|
139
123
|
if (old?.includes(column.id)) {
|
|
140
124
|
return old.filter(d => d !== column.id)
|
|
@@ -148,17 +132,17 @@ export const Grouping: TableFeature = {
|
|
|
148
132
|
return (
|
|
149
133
|
column.columnDef.enableGrouping ??
|
|
150
134
|
true ??
|
|
151
|
-
|
|
135
|
+
table.options.enableGrouping ??
|
|
152
136
|
true ??
|
|
153
137
|
!!column.accessorFn
|
|
154
138
|
)
|
|
155
139
|
},
|
|
156
140
|
|
|
157
141
|
getIsGrouped: () => {
|
|
158
|
-
return
|
|
142
|
+
return table.getState().grouping?.includes(column.id)
|
|
159
143
|
},
|
|
160
144
|
|
|
161
|
-
getGroupedIndex: () =>
|
|
145
|
+
getGroupedIndex: () => table.getState().grouping?.indexOf(column.id),
|
|
162
146
|
|
|
163
147
|
getToggleGroupingHandler: () => {
|
|
164
148
|
const canGroup = column.getCanGroup()
|
|
@@ -169,7 +153,7 @@ export const Grouping: TableFeature = {
|
|
|
169
153
|
}
|
|
170
154
|
},
|
|
171
155
|
getAutoAggregationFn: () => {
|
|
172
|
-
const firstRow =
|
|
156
|
+
const firstRow = table.getCoreRowModel().flatRows[0]
|
|
173
157
|
|
|
174
158
|
const value = firstRow?.getValue(column.id)
|
|
175
159
|
|
|
@@ -182,8 +166,6 @@ export const Grouping: TableFeature = {
|
|
|
182
166
|
}
|
|
183
167
|
},
|
|
184
168
|
getAggregationFn: () => {
|
|
185
|
-
const userAggregationFns = instance.options.aggregationFns
|
|
186
|
-
|
|
187
169
|
if (!column) {
|
|
188
170
|
throw new Error()
|
|
189
171
|
}
|
|
@@ -192,64 +174,55 @@ export const Grouping: TableFeature = {
|
|
|
192
174
|
? column.columnDef.aggregationFn
|
|
193
175
|
: column.columnDef.aggregationFn === 'auto'
|
|
194
176
|
? column.getAutoAggregationFn()
|
|
195
|
-
: (
|
|
196
|
-
column.columnDef.aggregationFn as string
|
|
197
|
-
] ??
|
|
198
|
-
(aggregationFns[
|
|
177
|
+
: (aggregationFns[
|
|
199
178
|
column.columnDef.aggregationFn as BuiltInAggregationFn
|
|
200
|
-
] as AggregationFn<
|
|
179
|
+
] as AggregationFn<TData>)
|
|
201
180
|
},
|
|
202
181
|
}
|
|
203
182
|
},
|
|
204
183
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
): GroupingInstance<
|
|
184
|
+
createTable: <TData extends RowData>(
|
|
185
|
+
table: Table<TData>
|
|
186
|
+
): GroupingInstance<TData> => {
|
|
208
187
|
return {
|
|
209
|
-
setGrouping: updater =>
|
|
188
|
+
setGrouping: updater => table.options.onGroupingChange?.(updater),
|
|
210
189
|
|
|
211
190
|
resetGrouping: defaultState => {
|
|
212
|
-
|
|
213
|
-
defaultState ? [] :
|
|
191
|
+
table.setGrouping(
|
|
192
|
+
defaultState ? [] : table.initialState?.grouping ?? []
|
|
214
193
|
)
|
|
215
194
|
},
|
|
216
195
|
|
|
217
|
-
getPreGroupedRowModel: () =>
|
|
196
|
+
getPreGroupedRowModel: () => table.getFilteredRowModel(),
|
|
218
197
|
getGroupedRowModel: () => {
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
instance.options.getGroupedRowModel
|
|
222
|
-
) {
|
|
223
|
-
instance._getGroupedRowModel =
|
|
224
|
-
instance.options.getGroupedRowModel(instance)
|
|
198
|
+
if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
|
|
199
|
+
table._getGroupedRowModel = table.options.getGroupedRowModel(table)
|
|
225
200
|
}
|
|
226
201
|
|
|
227
|
-
if (
|
|
228
|
-
return
|
|
202
|
+
if (table.options.manualGrouping || !table._getGroupedRowModel) {
|
|
203
|
+
return table.getPreGroupedRowModel()
|
|
229
204
|
}
|
|
230
205
|
|
|
231
|
-
return
|
|
206
|
+
return table._getGroupedRowModel()
|
|
232
207
|
},
|
|
233
208
|
}
|
|
234
209
|
},
|
|
235
210
|
|
|
236
|
-
createRow: <
|
|
237
|
-
row: Row<TGenerics>
|
|
238
|
-
): GroupingRow => {
|
|
211
|
+
createRow: <TData extends RowData>(row: Row<TData>): GroupingRow => {
|
|
239
212
|
return {
|
|
240
213
|
getIsGrouped: () => !!row.groupingColumnId,
|
|
241
214
|
_groupingValuesCache: {},
|
|
242
215
|
}
|
|
243
216
|
},
|
|
244
217
|
|
|
245
|
-
createCell: <
|
|
246
|
-
cell: Cell<
|
|
247
|
-
column: Column<
|
|
248
|
-
row: Row<
|
|
249
|
-
|
|
250
|
-
): GroupingCell
|
|
218
|
+
createCell: <TData extends RowData>(
|
|
219
|
+
cell: Cell<TData>,
|
|
220
|
+
column: Column<TData>,
|
|
221
|
+
row: Row<TData>,
|
|
222
|
+
table: Table<TData>
|
|
223
|
+
): GroupingCell => {
|
|
251
224
|
const getRenderValue = () =>
|
|
252
|
-
cell.getValue() ??
|
|
225
|
+
cell.getValue() ?? table.options.renderFallbackValue
|
|
253
226
|
|
|
254
227
|
return {
|
|
255
228
|
getIsGrouped: () =>
|
|
@@ -259,34 +232,12 @@ export const Grouping: TableFeature = {
|
|
|
259
232
|
!cell.getIsGrouped() &&
|
|
260
233
|
!cell.getIsPlaceholder() &&
|
|
261
234
|
!!row.subRows?.length,
|
|
262
|
-
renderAggregatedCell: () => {
|
|
263
|
-
if (process.env.NODE_ENV === 'development') {
|
|
264
|
-
if (!column.columnDef.aggregatedCell) {
|
|
265
|
-
console.warn(
|
|
266
|
-
'A columnDef.aggregatedCell template is recommended for displaying aggregated values.'
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const template =
|
|
272
|
-
column.columnDef.aggregatedCell || column.columnDef.cell
|
|
273
|
-
|
|
274
|
-
return template
|
|
275
|
-
? instance._render(template, {
|
|
276
|
-
instance,
|
|
277
|
-
column,
|
|
278
|
-
row,
|
|
279
|
-
cell,
|
|
280
|
-
getValue: getRenderValue,
|
|
281
|
-
})
|
|
282
|
-
: null
|
|
283
|
-
},
|
|
284
235
|
}
|
|
285
236
|
},
|
|
286
237
|
}
|
|
287
238
|
|
|
288
|
-
export function orderColumns<
|
|
289
|
-
leafColumns: Column<
|
|
239
|
+
export function orderColumns<TData extends RowData>(
|
|
240
|
+
leafColumns: Column<TData>[],
|
|
290
241
|
grouping: string[],
|
|
291
242
|
groupedColumnMode?: GroupingColumnMode
|
|
292
243
|
) {
|
package/src/features/Ordering.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { makeStateUpdater, memo } from '../utils'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
Table,
|
|
5
5
|
OnChangeFn,
|
|
6
6
|
Updater,
|
|
7
7
|
Column,
|
|
8
8
|
TableGenerics,
|
|
9
|
+
RowData,
|
|
9
10
|
} from '../types'
|
|
10
11
|
|
|
11
12
|
import { Grouping, orderColumns } from './Grouping'
|
|
12
|
-
import { TableFeature } from '../core/
|
|
13
|
+
import { TableFeature } from '../core/table'
|
|
13
14
|
|
|
14
15
|
export type ColumnOrderTableState = {
|
|
15
16
|
columnOrder: ColumnOrderState
|
|
@@ -25,12 +26,10 @@ export type ColumnOrderDefaultOptions = {
|
|
|
25
26
|
onColumnOrderChange: OnChangeFn<ColumnOrderState>
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export type ColumnOrderInstance<
|
|
29
|
+
export type ColumnOrderInstance<TData extends RowData> = {
|
|
29
30
|
setColumnOrder: (updater: Updater<ColumnOrderState>) => void
|
|
30
31
|
resetColumnOrder: (defaultState?: boolean) => void
|
|
31
|
-
_getOrderColumnsFn: () => (
|
|
32
|
-
columns: Column<TGenerics>[]
|
|
33
|
-
) => Column<TGenerics>[]
|
|
32
|
+
_getOrderColumnsFn: () => (columns: Column<TData>[]) => Column<TData>[]
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
//
|
|
@@ -43,35 +42,34 @@ export const Ordering: TableFeature = {
|
|
|
43
42
|
}
|
|
44
43
|
},
|
|
45
44
|
|
|
46
|
-
getDefaultOptions: <
|
|
47
|
-
|
|
45
|
+
getDefaultOptions: <TData extends RowData>(
|
|
46
|
+
table: Table<TData>
|
|
48
47
|
): ColumnOrderDefaultOptions => {
|
|
49
48
|
return {
|
|
50
|
-
onColumnOrderChange: makeStateUpdater('columnOrder',
|
|
49
|
+
onColumnOrderChange: makeStateUpdater('columnOrder', table),
|
|
51
50
|
}
|
|
52
51
|
},
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
): ColumnOrderInstance<
|
|
53
|
+
createTable: <TData extends RowData>(
|
|
54
|
+
table: Table<TData>
|
|
55
|
+
): ColumnOrderInstance<TData> => {
|
|
57
56
|
return {
|
|
58
|
-
setColumnOrder: updater =>
|
|
59
|
-
instance.options.onColumnOrderChange?.(updater),
|
|
57
|
+
setColumnOrder: updater => table.options.onColumnOrderChange?.(updater),
|
|
60
58
|
resetColumnOrder: defaultState => {
|
|
61
|
-
|
|
62
|
-
defaultState ? [] :
|
|
59
|
+
table.setColumnOrder(
|
|
60
|
+
defaultState ? [] : table.initialState.columnOrder ?? []
|
|
63
61
|
)
|
|
64
62
|
},
|
|
65
63
|
_getOrderColumnsFn: memo(
|
|
66
64
|
() => [
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
table.getState().columnOrder,
|
|
66
|
+
table.getState().grouping,
|
|
67
|
+
table.options.groupedColumnMode,
|
|
70
68
|
],
|
|
71
69
|
(columnOrder, grouping, groupedColumnMode) => columns => {
|
|
72
70
|
// Sort grouped columns to the start of the column list
|
|
73
71
|
// before the headers are built
|
|
74
|
-
let orderedColumns: Column<
|
|
72
|
+
let orderedColumns: Column<TData>[] = []
|
|
75
73
|
|
|
76
74
|
// If there is no order, return the normal columns
|
|
77
75
|
if (!columnOrder?.length) {
|
|
@@ -103,7 +101,7 @@ export const Ordering: TableFeature = {
|
|
|
103
101
|
},
|
|
104
102
|
{
|
|
105
103
|
key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn',
|
|
106
|
-
// debug: () =>
|
|
104
|
+
// debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
107
105
|
}
|
|
108
106
|
),
|
|
109
107
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { TableFeature } from '../core/
|
|
1
|
+
import { TableFeature } from '../core/table'
|
|
2
2
|
import {
|
|
3
3
|
OnChangeFn,
|
|
4
4
|
TableGenerics,
|
|
5
|
-
|
|
5
|
+
Table,
|
|
6
6
|
RowModel,
|
|
7
7
|
Updater,
|
|
8
|
+
RowData,
|
|
8
9
|
} from '../types'
|
|
9
10
|
import { functionalUpdate, makeStateUpdater, memo } from '../utils'
|
|
10
11
|
|
|
@@ -21,19 +22,19 @@ export type PaginationInitialTableState = {
|
|
|
21
22
|
pagination?: Partial<PaginationState>
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export type PaginationOptions
|
|
25
|
+
export type PaginationOptions = {
|
|
25
26
|
pageCount?: number
|
|
26
27
|
manualPagination?: boolean
|
|
27
28
|
onPaginationChange?: OnChangeFn<PaginationState>
|
|
28
29
|
autoResetPageIndex?: boolean
|
|
29
|
-
getPaginationRowModel?: (
|
|
30
|
+
getPaginationRowModel?: (table: Table<any>) => () => RowModel<any>
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export type PaginationDefaultOptions = {
|
|
33
34
|
onPaginationChange: OnChangeFn<PaginationState>
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export type PaginationInstance<
|
|
37
|
+
export type PaginationInstance<TData extends RowData> = {
|
|
37
38
|
_autoResetPageIndex: () => void
|
|
38
39
|
setPagination: (updater: Updater<PaginationState>) => void
|
|
39
40
|
resetPagination: (defaultState?: boolean) => void
|
|
@@ -47,9 +48,9 @@ export type PaginationInstance<TGenerics extends TableGenerics> = {
|
|
|
47
48
|
getCanNextPage: () => boolean
|
|
48
49
|
previousPage: () => void
|
|
49
50
|
nextPage: () => void
|
|
50
|
-
getPrePaginationRowModel: () => RowModel<
|
|
51
|
-
getPaginationRowModel: () => RowModel<
|
|
52
|
-
_getPaginationRowModel?: () => RowModel<
|
|
51
|
+
getPrePaginationRowModel: () => RowModel<TData>
|
|
52
|
+
getPaginationRowModel: () => RowModel<TData>
|
|
53
|
+
_getPaginationRowModel?: () => RowModel<TData>
|
|
53
54
|
getPageCount: () => number
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -74,38 +75,38 @@ export const Pagination: TableFeature = {
|
|
|
74
75
|
}
|
|
75
76
|
},
|
|
76
77
|
|
|
77
|
-
getDefaultOptions: <
|
|
78
|
-
|
|
78
|
+
getDefaultOptions: <TData extends RowData>(
|
|
79
|
+
table: Table<TData>
|
|
79
80
|
): PaginationDefaultOptions => {
|
|
80
81
|
return {
|
|
81
|
-
onPaginationChange: makeStateUpdater('pagination',
|
|
82
|
+
onPaginationChange: makeStateUpdater('pagination', table),
|
|
82
83
|
}
|
|
83
84
|
},
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
): PaginationInstance<
|
|
86
|
+
createTable: <TData extends RowData>(
|
|
87
|
+
table: Table<TData>
|
|
88
|
+
): PaginationInstance<TData> => {
|
|
88
89
|
let registered = false
|
|
89
90
|
let queued = false
|
|
90
91
|
|
|
91
92
|
return {
|
|
92
93
|
_autoResetPageIndex: () => {
|
|
93
94
|
if (!registered) {
|
|
94
|
-
|
|
95
|
+
table._queue(() => {
|
|
95
96
|
registered = true
|
|
96
97
|
})
|
|
97
98
|
return
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
!
|
|
102
|
+
table.options.autoResetAll ??
|
|
103
|
+
table.options.autoResetPageIndex ??
|
|
104
|
+
!table.options.manualPagination
|
|
104
105
|
) {
|
|
105
106
|
if (queued) return
|
|
106
107
|
queued = true
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
table._queue(() => {
|
|
109
|
+
table.resetPageIndex()
|
|
109
110
|
queued = false
|
|
110
111
|
})
|
|
111
112
|
}
|
|
@@ -117,23 +118,24 @@ export const Pagination: TableFeature = {
|
|
|
117
118
|
return newState
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
return
|
|
121
|
+
return table.options.onPaginationChange?.(safeUpdater)
|
|
121
122
|
},
|
|
122
123
|
resetPagination: defaultState => {
|
|
123
|
-
|
|
124
|
+
table.setPagination(
|
|
124
125
|
defaultState
|
|
125
126
|
? getDefaultPaginationState()
|
|
126
|
-
:
|
|
127
|
+
: table.initialState.pagination ?? getDefaultPaginationState()
|
|
127
128
|
)
|
|
128
129
|
},
|
|
129
130
|
setPageIndex: updater => {
|
|
130
|
-
|
|
131
|
+
table.setPagination(old => {
|
|
131
132
|
let pageIndex = functionalUpdate(updater, old.pageIndex)
|
|
132
133
|
|
|
133
134
|
const maxPageIndex =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
typeof table.options.pageCount === 'undefined' ||
|
|
136
|
+
table.options.pageCount === -1
|
|
137
|
+
? Number.MAX_SAFE_INTEGER
|
|
138
|
+
: table.options.pageCount - 1
|
|
137
139
|
|
|
138
140
|
pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex)
|
|
139
141
|
|
|
@@ -144,21 +146,21 @@ export const Pagination: TableFeature = {
|
|
|
144
146
|
})
|
|
145
147
|
},
|
|
146
148
|
resetPageIndex: defaultState => {
|
|
147
|
-
|
|
149
|
+
table.setPageIndex(
|
|
148
150
|
defaultState
|
|
149
151
|
? defaultPageIndex
|
|
150
|
-
:
|
|
152
|
+
: table.initialState?.pagination?.pageIndex ?? defaultPageIndex
|
|
151
153
|
)
|
|
152
154
|
},
|
|
153
155
|
resetPageSize: defaultState => {
|
|
154
|
-
|
|
156
|
+
table.setPageSize(
|
|
155
157
|
defaultState
|
|
156
158
|
? defaultPageSize
|
|
157
|
-
:
|
|
159
|
+
: table.initialState?.pagination?.pageSize ?? defaultPageSize
|
|
158
160
|
)
|
|
159
161
|
},
|
|
160
162
|
setPageSize: updater => {
|
|
161
|
-
|
|
163
|
+
table.setPagination(old => {
|
|
162
164
|
const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize))
|
|
163
165
|
const topRowIndex = old.pageSize * old.pageIndex!
|
|
164
166
|
const pageIndex = Math.floor(topRowIndex / pageSize)
|
|
@@ -171,10 +173,10 @@ export const Pagination: TableFeature = {
|
|
|
171
173
|
})
|
|
172
174
|
},
|
|
173
175
|
setPageCount: updater =>
|
|
174
|
-
|
|
176
|
+
table.setPagination(old => {
|
|
175
177
|
let newPageCount = functionalUpdate(
|
|
176
178
|
updater,
|
|
177
|
-
|
|
179
|
+
table.options.pageCount ?? -1
|
|
178
180
|
)
|
|
179
181
|
|
|
180
182
|
if (typeof newPageCount === 'number') {
|
|
@@ -188,7 +190,7 @@ export const Pagination: TableFeature = {
|
|
|
188
190
|
}),
|
|
189
191
|
|
|
190
192
|
getPageOptions: memo(
|
|
191
|
-
() => [
|
|
193
|
+
() => [table.getPageCount()],
|
|
192
194
|
pageCount => {
|
|
193
195
|
let pageOptions: number[] = []
|
|
194
196
|
if (pageCount && pageCount > 0) {
|
|
@@ -198,16 +200,16 @@ export const Pagination: TableFeature = {
|
|
|
198
200
|
},
|
|
199
201
|
{
|
|
200
202
|
key: process.env.NODE_ENV === 'development' && 'getPageOptions',
|
|
201
|
-
debug: () =>
|
|
203
|
+
debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
202
204
|
}
|
|
203
205
|
),
|
|
204
206
|
|
|
205
|
-
getCanPreviousPage: () =>
|
|
207
|
+
getCanPreviousPage: () => table.getState().pagination.pageIndex > 0,
|
|
206
208
|
|
|
207
209
|
getCanNextPage: () => {
|
|
208
|
-
const { pageIndex } =
|
|
210
|
+
const { pageIndex } = table.getState().pagination
|
|
209
211
|
|
|
210
|
-
const pageCount =
|
|
212
|
+
const pageCount = table.getPageCount()
|
|
211
213
|
|
|
212
214
|
if (pageCount === -1) {
|
|
213
215
|
return true
|
|
@@ -221,41 +223,38 @@ export const Pagination: TableFeature = {
|
|
|
221
223
|
},
|
|
222
224
|
|
|
223
225
|
previousPage: () => {
|
|
224
|
-
return
|
|
226
|
+
return table.setPageIndex(old => old - 1)
|
|
225
227
|
},
|
|
226
228
|
|
|
227
229
|
nextPage: () => {
|
|
228
|
-
return
|
|
230
|
+
return table.setPageIndex(old => {
|
|
229
231
|
return old + 1
|
|
230
232
|
})
|
|
231
233
|
},
|
|
232
234
|
|
|
233
|
-
getPrePaginationRowModel: () =>
|
|
235
|
+
getPrePaginationRowModel: () => table.getExpandedRowModel(),
|
|
234
236
|
getPaginationRowModel: () => {
|
|
235
237
|
if (
|
|
236
|
-
!
|
|
237
|
-
|
|
238
|
+
!table._getPaginationRowModel &&
|
|
239
|
+
table.options.getPaginationRowModel
|
|
238
240
|
) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
+
table._getPaginationRowModel =
|
|
242
|
+
table.options.getPaginationRowModel(table)
|
|
241
243
|
}
|
|
242
244
|
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
!instance._getPaginationRowModel
|
|
246
|
-
) {
|
|
247
|
-
return instance.getPrePaginationRowModel()
|
|
245
|
+
if (table.options.manualPagination || !table._getPaginationRowModel) {
|
|
246
|
+
return table.getPrePaginationRowModel()
|
|
248
247
|
}
|
|
249
248
|
|
|
250
|
-
return
|
|
249
|
+
return table._getPaginationRowModel()
|
|
251
250
|
},
|
|
252
251
|
|
|
253
252
|
getPageCount: () => {
|
|
254
253
|
return (
|
|
255
|
-
|
|
254
|
+
table.options.pageCount ??
|
|
256
255
|
Math.ceil(
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
table.getPrePaginationRowModel().rows.length /
|
|
257
|
+
table.getState().pagination.pageSize
|
|
259
258
|
)
|
|
260
259
|
)
|
|
261
260
|
},
|