@tanstack/table-core 8.0.0-beta.7 → 8.0.0-beta.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/cjs/features/Pagination.js +6 -12
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/esm/index.js +6 -12
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +308 -308
- package/build/types/features/Pagination.d.ts +1 -1
- package/build/umd/index.development.js +6 -12
- 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/features/Pagination.ts +15 -18
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-beta.
|
|
4
|
+
"version": "8.0.0-beta.8",
|
|
5
5
|
"description": "Headless UI for building powerful tables & datagrids for TS/JS.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/table#readme",
|
|
@@ -11,7 +11,6 @@ import { functionalUpdate, makeStateUpdater, memo } from '../utils'
|
|
|
11
11
|
export type PaginationState = {
|
|
12
12
|
pageIndex: number
|
|
13
13
|
pageSize: number
|
|
14
|
-
pageCount?: number
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
export type PaginationTableState = {
|
|
@@ -23,6 +22,7 @@ export type PaginationInitialTableState = {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
export type PaginationOptions<TGenerics extends TableGenerics> = {
|
|
25
|
+
pageCount?: number
|
|
26
26
|
manualPagination?: boolean
|
|
27
27
|
onPaginationChange?: OnChangeFn<PaginationState>
|
|
28
28
|
autoResetPageIndex?: boolean
|
|
@@ -131,8 +131,8 @@ export const Pagination: TableFeature = {
|
|
|
131
131
|
let pageIndex = functionalUpdate(updater, old.pageIndex)
|
|
132
132
|
|
|
133
133
|
const maxPageIndex =
|
|
134
|
-
typeof
|
|
135
|
-
?
|
|
134
|
+
typeof instance.options.pageCount !== 'undefined'
|
|
135
|
+
? instance.options.pageCount - 1
|
|
136
136
|
: Number.MAX_SAFE_INTEGER
|
|
137
137
|
|
|
138
138
|
pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex)
|
|
@@ -172,7 +172,10 @@ export const Pagination: TableFeature = {
|
|
|
172
172
|
},
|
|
173
173
|
setPageCount: updater =>
|
|
174
174
|
instance.setPagination(old => {
|
|
175
|
-
let newPageCount = functionalUpdate(
|
|
175
|
+
let newPageCount = functionalUpdate(
|
|
176
|
+
updater,
|
|
177
|
+
instance.options.pageCount ?? -1
|
|
178
|
+
)
|
|
176
179
|
|
|
177
180
|
if (typeof newPageCount === 'number') {
|
|
178
181
|
newPageCount = Math.max(-1, newPageCount)
|
|
@@ -185,11 +188,8 @@ export const Pagination: TableFeature = {
|
|
|
185
188
|
}),
|
|
186
189
|
|
|
187
190
|
getPageOptions: memo(
|
|
188
|
-
() => [
|
|
189
|
-
|
|
190
|
-
instance.getState().pagination.pageCount,
|
|
191
|
-
],
|
|
192
|
-
(pageSize, pageCount) => {
|
|
191
|
+
() => [instance.getPageCount()],
|
|
192
|
+
pageCount => {
|
|
193
193
|
let pageOptions: number[] = []
|
|
194
194
|
if (pageCount && pageCount > 0) {
|
|
195
195
|
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i)
|
|
@@ -251,15 +251,12 @@ export const Pagination: TableFeature = {
|
|
|
251
251
|
},
|
|
252
252
|
|
|
253
253
|
getPageCount: () => {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return Math.ceil(
|
|
261
|
-
instance.getPrePaginationRowModel().rows.length /
|
|
262
|
-
instance.getState().pagination.pageSize
|
|
254
|
+
return (
|
|
255
|
+
instance.options.pageCount ??
|
|
256
|
+
Math.ceil(
|
|
257
|
+
instance.getPrePaginationRowModel().rows.length /
|
|
258
|
+
instance.getState().pagination.pageSize
|
|
259
|
+
)
|
|
263
260
|
)
|
|
264
261
|
},
|
|
265
262
|
}
|