@tanstack/table-core 8.9.3 → 8.9.8
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/lib/core/cell.js +1 -1
- package/build/lib/core/cell.js.map +1 -1
- package/build/lib/core/column.js +3 -3
- package/build/lib/core/column.js.map +1 -1
- package/build/lib/core/headers.js +182 -181
- package/build/lib/core/headers.js.map +1 -1
- package/build/lib/core/row.js +1 -1
- package/build/lib/core/row.js.map +1 -1
- package/build/lib/core/table.js +6 -5
- package/build/lib/core/table.js.map +1 -1
- package/build/lib/features/ColumnSizing.js +173 -179
- package/build/lib/features/ColumnSizing.js.map +1 -1
- package/build/lib/features/Expanding.js +119 -123
- package/build/lib/features/Expanding.js.map +1 -1
- package/build/lib/features/Filters.js +159 -167
- package/build/lib/features/Filters.js.map +1 -1
- package/build/lib/features/Grouping.js +72 -80
- package/build/lib/features/Grouping.js.map +1 -1
- package/build/lib/features/Ordering.js +32 -34
- package/build/lib/features/Ordering.js.map +1 -1
- package/build/lib/features/Pagination.js +112 -114
- package/build/lib/features/Pagination.js.map +1 -1
- package/build/lib/features/Pinning.js +120 -126
- package/build/lib/features/Pinning.js.map +1 -1
- package/build/lib/features/RowSelection.js +245 -247
- package/build/lib/features/RowSelection.js.map +1 -1
- package/build/lib/features/Sorting.js +163 -167
- package/build/lib/features/Sorting.js.map +1 -1
- package/build/lib/features/Visibility.js +60 -66
- package/build/lib/features/Visibility.js.map +1 -1
- package/build/lib/filterFns.js +6 -6
- package/build/lib/filterFns.js.map +1 -1
- package/build/lib/index.esm.js +1484 -1530
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.mjs +1484 -1530
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/utils/filterRowsUtils.js +3 -3
- package/build/lib/utils/filterRowsUtils.js.map +1 -1
- package/build/lib/utils.js +1 -1
- package/build/lib/utils.js.map +1 -1
- package/build/umd/index.development.js +1484 -1530
- 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 +5 -8
- package/src/core/column.ts +3 -3
- package/src/core/headers.ts +264 -280
- package/src/core/row.ts +1 -1
- package/src/core/table.ts +4 -3
- package/src/features/ColumnSizing.ts +220 -231
- package/src/features/Expanding.ts +132 -140
- package/src/features/Filters.ts +193 -206
- package/src/features/Grouping.ts +94 -110
- package/src/features/Ordering.ts +48 -51
- package/src/features/Pagination.ts +150 -154
- package/src/features/Pinning.ts +158 -178
- package/src/features/RowSelection.ts +280 -286
- package/src/features/Sorting.ts +196 -206
- package/src/features/Visibility.ts +98 -107
- package/src/utils/filterRowsUtils.ts +3 -3
package/src/features/Grouping.ts
CHANGED
|
@@ -135,127 +135,115 @@ export const Grouping: TableFeature = {
|
|
|
135
135
|
createColumn: <TData extends RowData, TValue>(
|
|
136
136
|
column: Column<TData, TValue>,
|
|
137
137
|
table: Table<TData>
|
|
138
|
-
):
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return old.filter(d => d !== column.id)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return [...(old ?? []), column.id]
|
|
148
|
-
})
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
getCanGroup: () => {
|
|
152
|
-
return (
|
|
153
|
-
column.columnDef.enableGrouping ??
|
|
154
|
-
true ??
|
|
155
|
-
table.options.enableGrouping ??
|
|
156
|
-
true ??
|
|
157
|
-
!!column.accessorFn
|
|
158
|
-
)
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
getIsGrouped: () => {
|
|
162
|
-
return table.getState().grouping?.includes(column.id)
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
getGroupedIndex: () => table.getState().grouping?.indexOf(column.id),
|
|
166
|
-
|
|
167
|
-
getToggleGroupingHandler: () => {
|
|
168
|
-
const canGroup = column.getCanGroup()
|
|
169
|
-
|
|
170
|
-
return () => {
|
|
171
|
-
if (!canGroup) return
|
|
172
|
-
column.toggleGrouping()
|
|
138
|
+
): void => {
|
|
139
|
+
column.toggleGrouping = () => {
|
|
140
|
+
table.setGrouping(old => {
|
|
141
|
+
// Find any existing grouping for this column
|
|
142
|
+
if (old?.includes(column.id)) {
|
|
143
|
+
return old.filter(d => d !== column.id)
|
|
173
144
|
}
|
|
174
|
-
},
|
|
175
|
-
getAutoAggregationFn: () => {
|
|
176
|
-
const firstRow = table.getCoreRowModel().flatRows[0]
|
|
177
145
|
|
|
178
|
-
|
|
146
|
+
return [...(old ?? []), column.id]
|
|
147
|
+
})
|
|
148
|
+
}
|
|
179
149
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
150
|
+
column.getCanGroup = () => {
|
|
151
|
+
return (
|
|
152
|
+
column.columnDef.enableGrouping ??
|
|
153
|
+
true ??
|
|
154
|
+
table.options.enableGrouping ??
|
|
155
|
+
true ??
|
|
156
|
+
!!column.accessorFn
|
|
157
|
+
)
|
|
158
|
+
}
|
|
183
159
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
},
|
|
188
|
-
getAggregationFn: () => {
|
|
189
|
-
if (!column) {
|
|
190
|
-
throw new Error()
|
|
191
|
-
}
|
|
160
|
+
column.getIsGrouped = () => {
|
|
161
|
+
return table.getState().grouping?.includes(column.id)
|
|
162
|
+
}
|
|
192
163
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
164
|
+
column.getGroupedIndex = () => table.getState().grouping?.indexOf(column.id)
|
|
165
|
+
|
|
166
|
+
column.getToggleGroupingHandler = () => {
|
|
167
|
+
const canGroup = column.getCanGroup()
|
|
168
|
+
|
|
169
|
+
return () => {
|
|
170
|
+
if (!canGroup) return
|
|
171
|
+
column.toggleGrouping()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
column.getAutoAggregationFn = () => {
|
|
175
|
+
const firstRow = table.getCoreRowModel().flatRows[0]
|
|
176
|
+
|
|
177
|
+
const value = firstRow?.getValue(column.id)
|
|
178
|
+
|
|
179
|
+
if (typeof value === 'number') {
|
|
180
|
+
return aggregationFns.sum
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (Object.prototype.toString.call(value) === '[object Date]') {
|
|
184
|
+
return aggregationFns.extent
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
column.getAggregationFn = () => {
|
|
188
|
+
if (!column) {
|
|
189
|
+
throw new Error()
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return isFunction(column.columnDef.aggregationFn)
|
|
193
|
+
? column.columnDef.aggregationFn
|
|
194
|
+
: column.columnDef.aggregationFn === 'auto'
|
|
195
|
+
? column.getAutoAggregationFn()
|
|
196
|
+
: table.options.aggregationFns?.[
|
|
197
|
+
column.columnDef.aggregationFn as string
|
|
198
|
+
] ??
|
|
199
|
+
aggregationFns[column.columnDef.aggregationFn as BuiltInAggregationFn]
|
|
204
200
|
}
|
|
205
201
|
},
|
|
206
202
|
|
|
207
|
-
createTable: <TData extends RowData>(
|
|
208
|
-
table
|
|
209
|
-
): GroupingInstance<TData> => {
|
|
210
|
-
return {
|
|
211
|
-
setGrouping: updater => table.options.onGroupingChange?.(updater),
|
|
212
|
-
|
|
213
|
-
resetGrouping: defaultState => {
|
|
214
|
-
table.setGrouping(
|
|
215
|
-
defaultState ? [] : table.initialState?.grouping ?? []
|
|
216
|
-
)
|
|
217
|
-
},
|
|
218
|
-
|
|
219
|
-
getPreGroupedRowModel: () => table.getFilteredRowModel(),
|
|
220
|
-
getGroupedRowModel: () => {
|
|
221
|
-
if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
|
|
222
|
-
table._getGroupedRowModel = table.options.getGroupedRowModel(table)
|
|
223
|
-
}
|
|
203
|
+
createTable: <TData extends RowData>(table: Table<TData>): void => {
|
|
204
|
+
table.setGrouping = updater => table.options.onGroupingChange?.(updater)
|
|
224
205
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
206
|
+
table.resetGrouping = defaultState => {
|
|
207
|
+
table.setGrouping(defaultState ? [] : table.initialState?.grouping ?? [])
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
table.getPreGroupedRowModel = () => table.getFilteredRowModel()
|
|
211
|
+
table.getGroupedRowModel = () => {
|
|
212
|
+
if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
|
|
213
|
+
table._getGroupedRowModel = table.options.getGroupedRowModel(table)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (table.options.manualGrouping || !table._getGroupedRowModel) {
|
|
217
|
+
return table.getPreGroupedRowModel()
|
|
218
|
+
}
|
|
228
219
|
|
|
229
|
-
|
|
230
|
-
},
|
|
220
|
+
return table._getGroupedRowModel()
|
|
231
221
|
}
|
|
232
222
|
},
|
|
233
223
|
|
|
234
224
|
createRow: <TData extends RowData>(
|
|
235
225
|
row: Row<TData>,
|
|
236
226
|
table: Table<TData>
|
|
237
|
-
):
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
227
|
+
): void => {
|
|
228
|
+
row.getIsGrouped = () => !!row.groupingColumnId
|
|
229
|
+
row.getGroupingValue = columnId => {
|
|
230
|
+
if (row._groupingValuesCache.hasOwnProperty(columnId)) {
|
|
231
|
+
return row._groupingValuesCache[columnId]
|
|
232
|
+
}
|
|
244
233
|
|
|
245
|
-
|
|
234
|
+
const column = table.getColumn(columnId)
|
|
246
235
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
236
|
+
if (!column?.columnDef.getGroupingValue) {
|
|
237
|
+
return row.getValue(columnId)
|
|
238
|
+
}
|
|
250
239
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
240
|
+
row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(
|
|
241
|
+
row.original
|
|
242
|
+
)
|
|
254
243
|
|
|
255
|
-
|
|
256
|
-
},
|
|
257
|
-
_groupingValuesCache: {},
|
|
244
|
+
return row._groupingValuesCache[columnId]
|
|
258
245
|
}
|
|
246
|
+
row._groupingValuesCache = {}
|
|
259
247
|
},
|
|
260
248
|
|
|
261
249
|
createCell: <TData extends RowData, TValue>(
|
|
@@ -263,19 +251,15 @@ export const Grouping: TableFeature = {
|
|
|
263
251
|
column: Column<TData, TValue>,
|
|
264
252
|
row: Row<TData>,
|
|
265
253
|
table: Table<TData>
|
|
266
|
-
):
|
|
254
|
+
): void => {
|
|
267
255
|
const getRenderValue = () =>
|
|
268
256
|
cell.getValue() ?? table.options.renderFallbackValue
|
|
269
257
|
|
|
270
|
-
|
|
271
|
-
getIsGrouped
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
!cell.getIsGrouped() &&
|
|
276
|
-
!cell.getIsPlaceholder() &&
|
|
277
|
-
!!row.subRows?.length,
|
|
278
|
-
}
|
|
258
|
+
cell.getIsGrouped = () =>
|
|
259
|
+
column.getIsGrouped() && column.id === row.groupingColumnId
|
|
260
|
+
cell.getIsPlaceholder = () => !cell.getIsGrouped() && column.getIsGrouped()
|
|
261
|
+
cell.getIsAggregated = () =>
|
|
262
|
+
!cell.getIsGrouped() && !cell.getIsPlaceholder() && !!row.subRows?.length
|
|
279
263
|
},
|
|
280
264
|
}
|
|
281
265
|
|
package/src/features/Ordering.ts
CHANGED
|
@@ -45,60 +45,57 @@ export const Ordering: TableFeature = {
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
|
|
48
|
-
createTable: <TData extends RowData>(
|
|
49
|
-
table
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
()
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
)
|
|
86
|
-
if (foundIndex > -1) {
|
|
87
|
-
orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]!)
|
|
88
|
-
}
|
|
48
|
+
createTable: <TData extends RowData>(table: Table<TData>): void => {
|
|
49
|
+
table.setColumnOrder = updater =>
|
|
50
|
+
table.options.onColumnOrderChange?.(updater)
|
|
51
|
+
table.resetColumnOrder = defaultState => {
|
|
52
|
+
table.setColumnOrder(
|
|
53
|
+
defaultState ? [] : table.initialState.columnOrder ?? []
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
table._getOrderColumnsFn = memo(
|
|
57
|
+
() => [
|
|
58
|
+
table.getState().columnOrder,
|
|
59
|
+
table.getState().grouping,
|
|
60
|
+
table.options.groupedColumnMode,
|
|
61
|
+
],
|
|
62
|
+
(columnOrder, grouping, groupedColumnMode) => columns => {
|
|
63
|
+
// Sort grouped columns to the start of the column list
|
|
64
|
+
// before the headers are built
|
|
65
|
+
let orderedColumns: Column<TData, unknown>[] = []
|
|
66
|
+
|
|
67
|
+
// If there is no order, return the normal columns
|
|
68
|
+
if (!columnOrder?.length) {
|
|
69
|
+
orderedColumns = columns
|
|
70
|
+
} else {
|
|
71
|
+
const columnOrderCopy = [...columnOrder]
|
|
72
|
+
|
|
73
|
+
// If there is an order, make a copy of the columns
|
|
74
|
+
const columnsCopy = [...columns]
|
|
75
|
+
|
|
76
|
+
// And make a new ordered array of the columns
|
|
77
|
+
|
|
78
|
+
// Loop over the columns and place them in order into the new array
|
|
79
|
+
while (columnsCopy.length && columnOrderCopy.length) {
|
|
80
|
+
const targetColumnId = columnOrderCopy.shift()
|
|
81
|
+
const foundIndex = columnsCopy.findIndex(
|
|
82
|
+
d => d.id === targetColumnId
|
|
83
|
+
)
|
|
84
|
+
if (foundIndex > -1) {
|
|
85
|
+
orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]!)
|
|
89
86
|
}
|
|
90
|
-
|
|
91
|
-
// If there are any columns left, add them to the end
|
|
92
|
-
orderedColumns = [...orderedColumns, ...columnsCopy]
|
|
93
87
|
}
|
|
94
88
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
{
|
|
98
|
-
key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn',
|
|
99
|
-
// debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
89
|
+
// If there are any columns left, add them to the end
|
|
90
|
+
orderedColumns = [...orderedColumns, ...columnsCopy]
|
|
100
91
|
}
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
|
|
93
|
+
return orderColumns(orderedColumns, grouping, groupedColumnMode)
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn',
|
|
97
|
+
// debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
98
|
+
}
|
|
99
|
+
)
|
|
103
100
|
},
|
|
104
101
|
}
|
|
@@ -76,181 +76,177 @@ export const Pagination: TableFeature = {
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
|
|
79
|
-
createTable: <TData extends RowData>(
|
|
80
|
-
table: Table<TData>
|
|
81
|
-
): PaginationInstance<TData> => {
|
|
79
|
+
createTable: <TData extends RowData>(table: Table<TData>): void => {
|
|
82
80
|
let registered = false
|
|
83
81
|
let queued = false
|
|
84
82
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
registered = true
|
|
90
|
-
})
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
table.options.autoResetAll ??
|
|
96
|
-
table.options.autoResetPageIndex ??
|
|
97
|
-
!table.options.manualPagination
|
|
98
|
-
) {
|
|
99
|
-
if (queued) return
|
|
100
|
-
queued = true
|
|
101
|
-
table._queue(() => {
|
|
102
|
-
table.resetPageIndex()
|
|
103
|
-
queued = false
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
setPagination: updater => {
|
|
108
|
-
const safeUpdater: Updater<PaginationState> = old => {
|
|
109
|
-
let newState = functionalUpdate(updater, old)
|
|
110
|
-
|
|
111
|
-
return newState
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return table.options.onPaginationChange?.(safeUpdater)
|
|
115
|
-
},
|
|
116
|
-
resetPagination: defaultState => {
|
|
117
|
-
table.setPagination(
|
|
118
|
-
defaultState
|
|
119
|
-
? getDefaultPaginationState()
|
|
120
|
-
: table.initialState.pagination ?? getDefaultPaginationState()
|
|
121
|
-
)
|
|
122
|
-
},
|
|
123
|
-
setPageIndex: updater => {
|
|
124
|
-
table.setPagination(old => {
|
|
125
|
-
let pageIndex = functionalUpdate(updater, old.pageIndex)
|
|
126
|
-
|
|
127
|
-
const maxPageIndex =
|
|
128
|
-
typeof table.options.pageCount === 'undefined' ||
|
|
129
|
-
table.options.pageCount === -1
|
|
130
|
-
? Number.MAX_SAFE_INTEGER
|
|
131
|
-
: table.options.pageCount - 1
|
|
132
|
-
|
|
133
|
-
pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex))
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
...old,
|
|
137
|
-
pageIndex,
|
|
138
|
-
}
|
|
83
|
+
table._autoResetPageIndex = () => {
|
|
84
|
+
if (!registered) {
|
|
85
|
+
table._queue(() => {
|
|
86
|
+
registered = true
|
|
139
87
|
})
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
)
|
|
154
|
-
},
|
|
155
|
-
setPageSize: updater => {
|
|
156
|
-
table.setPagination(old => {
|
|
157
|
-
const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize))
|
|
158
|
-
const topRowIndex = old.pageSize * old.pageIndex!
|
|
159
|
-
const pageIndex = Math.floor(topRowIndex / pageSize)
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
...old,
|
|
163
|
-
pageIndex,
|
|
164
|
-
pageSize,
|
|
165
|
-
}
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (
|
|
92
|
+
table.options.autoResetAll ??
|
|
93
|
+
table.options.autoResetPageIndex ??
|
|
94
|
+
!table.options.manualPagination
|
|
95
|
+
) {
|
|
96
|
+
if (queued) return
|
|
97
|
+
queued = true
|
|
98
|
+
table._queue(() => {
|
|
99
|
+
table.resetPageIndex()
|
|
100
|
+
queued = false
|
|
166
101
|
})
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (typeof newPageCount === 'number') {
|
|
176
|
-
newPageCount = Math.max(-1, newPageCount)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return {
|
|
180
|
-
...old,
|
|
181
|
-
pageCount: newPageCount,
|
|
182
|
-
}
|
|
183
|
-
}),
|
|
184
|
-
|
|
185
|
-
getPageOptions: memo(
|
|
186
|
-
() => [table.getPageCount()],
|
|
187
|
-
pageCount => {
|
|
188
|
-
let pageOptions: number[] = []
|
|
189
|
-
if (pageCount && pageCount > 0) {
|
|
190
|
-
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i)
|
|
191
|
-
}
|
|
192
|
-
return pageOptions
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
key: process.env.NODE_ENV === 'development' && 'getPageOptions',
|
|
196
|
-
debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
197
|
-
}
|
|
198
|
-
),
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
table.setPagination = updater => {
|
|
105
|
+
const safeUpdater: Updater<PaginationState> = old => {
|
|
106
|
+
let newState = functionalUpdate(updater, old)
|
|
107
|
+
|
|
108
|
+
return newState
|
|
109
|
+
}
|
|
199
110
|
|
|
200
|
-
|
|
111
|
+
return table.options.onPaginationChange?.(safeUpdater)
|
|
112
|
+
}
|
|
113
|
+
table.resetPagination = defaultState => {
|
|
114
|
+
table.setPagination(
|
|
115
|
+
defaultState
|
|
116
|
+
? getDefaultPaginationState()
|
|
117
|
+
: table.initialState.pagination ?? getDefaultPaginationState()
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
table.setPageIndex = updater => {
|
|
121
|
+
table.setPagination(old => {
|
|
122
|
+
let pageIndex = functionalUpdate(updater, old.pageIndex)
|
|
201
123
|
|
|
202
|
-
|
|
203
|
-
|
|
124
|
+
const maxPageIndex =
|
|
125
|
+
typeof table.options.pageCount === 'undefined' ||
|
|
126
|
+
table.options.pageCount === -1
|
|
127
|
+
? Number.MAX_SAFE_INTEGER
|
|
128
|
+
: table.options.pageCount - 1
|
|
204
129
|
|
|
205
|
-
|
|
130
|
+
pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex))
|
|
206
131
|
|
|
207
|
-
|
|
208
|
-
|
|
132
|
+
return {
|
|
133
|
+
...old,
|
|
134
|
+
pageIndex,
|
|
209
135
|
}
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
table.resetPageIndex = defaultState => {
|
|
139
|
+
table.setPageIndex(
|
|
140
|
+
defaultState
|
|
141
|
+
? defaultPageIndex
|
|
142
|
+
: table.initialState?.pagination?.pageIndex ?? defaultPageIndex
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
table.resetPageSize = defaultState => {
|
|
146
|
+
table.setPageSize(
|
|
147
|
+
defaultState
|
|
148
|
+
? defaultPageSize
|
|
149
|
+
: table.initialState?.pagination?.pageSize ?? defaultPageSize
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
table.setPageSize = updater => {
|
|
153
|
+
table.setPagination(old => {
|
|
154
|
+
const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize))
|
|
155
|
+
const topRowIndex = old.pageSize * old.pageIndex!
|
|
156
|
+
const pageIndex = Math.floor(topRowIndex / pageSize)
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
...old,
|
|
160
|
+
pageIndex,
|
|
161
|
+
pageSize,
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
table.setPageCount = updater =>
|
|
166
|
+
table.setPagination(old => {
|
|
167
|
+
let newPageCount = functionalUpdate(
|
|
168
|
+
updater,
|
|
169
|
+
table.options.pageCount ?? -1
|
|
170
|
+
)
|
|
210
171
|
|
|
211
|
-
if (
|
|
212
|
-
|
|
172
|
+
if (typeof newPageCount === 'number') {
|
|
173
|
+
newPageCount = Math.max(-1, newPageCount)
|
|
213
174
|
}
|
|
214
175
|
|
|
215
|
-
return
|
|
176
|
+
return {
|
|
177
|
+
...old,
|
|
178
|
+
pageCount: newPageCount,
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
table.getPageOptions = memo(
|
|
183
|
+
() => [table.getPageCount()],
|
|
184
|
+
pageCount => {
|
|
185
|
+
let pageOptions: number[] = []
|
|
186
|
+
if (pageCount && pageCount > 0) {
|
|
187
|
+
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i)
|
|
188
|
+
}
|
|
189
|
+
return pageOptions
|
|
216
190
|
},
|
|
191
|
+
{
|
|
192
|
+
key: process.env.NODE_ENV === 'development' && 'getPageOptions',
|
|
193
|
+
debug: () => table.options.debugAll ?? table.options.debugTable,
|
|
194
|
+
}
|
|
195
|
+
)
|
|
217
196
|
|
|
218
|
-
|
|
219
|
-
return table.setPageIndex(old => old - 1)
|
|
220
|
-
},
|
|
197
|
+
table.getCanPreviousPage = () => table.getState().pagination.pageIndex > 0
|
|
221
198
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return old + 1
|
|
225
|
-
})
|
|
226
|
-
},
|
|
199
|
+
table.getCanNextPage = () => {
|
|
200
|
+
const { pageIndex } = table.getState().pagination
|
|
227
201
|
|
|
228
|
-
|
|
229
|
-
getPaginationRowModel: () => {
|
|
230
|
-
if (
|
|
231
|
-
!table._getPaginationRowModel &&
|
|
232
|
-
table.options.getPaginationRowModel
|
|
233
|
-
) {
|
|
234
|
-
table._getPaginationRowModel =
|
|
235
|
-
table.options.getPaginationRowModel(table)
|
|
236
|
-
}
|
|
202
|
+
const pageCount = table.getPageCount()
|
|
237
203
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
204
|
+
if (pageCount === -1) {
|
|
205
|
+
return true
|
|
206
|
+
}
|
|
241
207
|
|
|
242
|
-
|
|
243
|
-
|
|
208
|
+
if (pageCount === 0) {
|
|
209
|
+
return false
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return pageIndex < pageCount - 1
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
table.previousPage = () => {
|
|
216
|
+
return table.setPageIndex(old => old - 1)
|
|
217
|
+
}
|
|
244
218
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
219
|
+
table.nextPage = () => {
|
|
220
|
+
return table.setPageIndex(old => {
|
|
221
|
+
return old + 1
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
table.getPrePaginationRowModel = () => table.getExpandedRowModel()
|
|
226
|
+
table.getPaginationRowModel = () => {
|
|
227
|
+
if (
|
|
228
|
+
!table._getPaginationRowModel &&
|
|
229
|
+
table.options.getPaginationRowModel
|
|
230
|
+
) {
|
|
231
|
+
table._getPaginationRowModel =
|
|
232
|
+
table.options.getPaginationRowModel(table)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (table.options.manualPagination || !table._getPaginationRowModel) {
|
|
236
|
+
return table.getPrePaginationRowModel()
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return table._getPaginationRowModel()
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
table.getPageCount = () => {
|
|
243
|
+
return (
|
|
244
|
+
table.options.pageCount ??
|
|
245
|
+
Math.ceil(
|
|
246
|
+
table.getPrePaginationRowModel().rows.length /
|
|
247
|
+
table.getState().pagination.pageSize
|
|
252
248
|
)
|
|
253
|
-
|
|
249
|
+
)
|
|
254
250
|
}
|
|
255
251
|
},
|
|
256
252
|
}
|