@tanstack/react-table 8.0.0-alpha.3 → 8.0.0-alpha.4
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.js +1 -1
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/features/Pagination.js +22 -18
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/index.js +2 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/paginateRowsFn.js +44 -0
- package/build/cjs/utils/paginateRowsFn.js.map +1 -0
- package/build/esm/index.js +50 -20
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +254 -222
- package/build/types/core.d.ts +1 -1
- package/build/types/features/Pagination.d.ts +5 -4
- package/build/types/index.d.ts +1 -0
- package/build/umd/index.development.js +50 -19
- 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.tsx +2 -3
- package/src/features/Pagination.ts +43 -30
- package/src/index.tsx +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-table",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.4",
|
|
5
5
|
"description": "Hooks for building lightweight, fast and extendable datagrids for React",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/react-table#readme",
|
package/src/core.tsx
CHANGED
|
@@ -291,8 +291,7 @@ export type CoreColumnDef<
|
|
|
291
291
|
header: Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
292
292
|
column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
|
|
293
293
|
}>
|
|
294
|
-
} & // | Renderable<{ // | string // header?: // accessorKey?: never // id: string // accessorFn: AccessorFn<TData> // | {
|
|
295
|
-
// instance: ReactTable<
|
|
294
|
+
} & // instance: ReactTable< // | Renderable<{ // | string // header?: // accessorKey?: never // id: string // accessorFn: AccessorFn<TData> // | {
|
|
296
295
|
// TData,
|
|
297
296
|
// TValue,
|
|
298
297
|
// TFilterFns,
|
|
@@ -1053,7 +1052,7 @@ export function createTableInstance<
|
|
|
1053
1052
|
// expanded rows, which then work their way up
|
|
1054
1053
|
|
|
1055
1054
|
getRowModel: () => {
|
|
1056
|
-
return instance.
|
|
1055
|
+
return instance.getPaginationRowModel()
|
|
1057
1056
|
},
|
|
1058
1057
|
|
|
1059
1058
|
getRows: () => {
|
|
@@ -9,10 +9,12 @@ import {
|
|
|
9
9
|
} from '../types'
|
|
10
10
|
import { functionalUpdate, makeStateUpdater, memo } from '../utils'
|
|
11
11
|
|
|
12
|
+
export type PageCount = undefined | null | number
|
|
13
|
+
|
|
12
14
|
export type PaginationState = {
|
|
13
15
|
pageIndex: number
|
|
14
16
|
pageSize: number
|
|
15
|
-
pageCount
|
|
17
|
+
pageCount?: PageCount
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export type PaginationTableState = {
|
|
@@ -59,12 +61,12 @@ export type PaginationInstance<
|
|
|
59
61
|
resetPageIndex: () => void
|
|
60
62
|
setPageSize: (updater: Updater<number>) => void
|
|
61
63
|
resetPageSize: () => void
|
|
62
|
-
setPageCount: (updater: Updater<
|
|
64
|
+
setPageCount: (updater: Updater<PageCount>) => void
|
|
63
65
|
getPageOptions: () => number[]
|
|
64
66
|
getCanPreviousPage: () => boolean
|
|
65
67
|
getCanNextPage: () => boolean
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
previousPage: () => void
|
|
69
|
+
nextPage: () => void
|
|
68
70
|
getPaginationRowModel: () => RowModel<
|
|
69
71
|
TData,
|
|
70
72
|
TValue,
|
|
@@ -117,7 +119,6 @@ export function getInitialState(): PaginationTableState {
|
|
|
117
119
|
pagination: {
|
|
118
120
|
pageIndex: 0,
|
|
119
121
|
pageSize: 10,
|
|
120
|
-
pageCount: -1,
|
|
121
122
|
},
|
|
122
123
|
}
|
|
123
124
|
}
|
|
@@ -167,21 +168,18 @@ export function getInstance<
|
|
|
167
168
|
},
|
|
168
169
|
setPagination: updater => {
|
|
169
170
|
const safeUpdater: Updater<PaginationState> = old => {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
)
|
|
180
|
-
: 0,
|
|
181
|
-
}
|
|
171
|
+
let newState = functionalUpdate(updater, old)
|
|
172
|
+
|
|
173
|
+
if (instance.options.paginateRowsFn) {
|
|
174
|
+
newState.pageCount = instance.getPrePaginationRows()?.length
|
|
175
|
+
? Math.ceil(
|
|
176
|
+
instance.getPrePaginationRows().length /
|
|
177
|
+
instance.getState().pagination.pageSize
|
|
178
|
+
)
|
|
179
|
+
: 0
|
|
182
180
|
}
|
|
183
181
|
|
|
184
|
-
return
|
|
182
|
+
return newState
|
|
185
183
|
}
|
|
186
184
|
|
|
187
185
|
return instance.options.onPaginationChange?.(
|
|
@@ -200,13 +198,18 @@ export function getInstance<
|
|
|
200
198
|
},
|
|
201
199
|
setPageIndex: updater => {
|
|
202
200
|
instance.setPagination(old => {
|
|
203
|
-
|
|
201
|
+
let pageIndex = functionalUpdate(updater, old.pageIndex)
|
|
202
|
+
|
|
204
203
|
const maxPageIndex =
|
|
205
|
-
old.pageCount
|
|
204
|
+
old.pageCount && old.pageCount > 0
|
|
205
|
+
? old.pageCount - 1
|
|
206
|
+
: Number.MAX_SAFE_INTEGER
|
|
207
|
+
|
|
208
|
+
pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex)
|
|
206
209
|
|
|
207
210
|
return {
|
|
208
211
|
...old,
|
|
209
|
-
pageIndex
|
|
212
|
+
pageIndex,
|
|
210
213
|
}
|
|
211
214
|
})
|
|
212
215
|
},
|
|
@@ -232,10 +235,18 @@ export function getInstance<
|
|
|
232
235
|
})
|
|
233
236
|
},
|
|
234
237
|
setPageCount: updater =>
|
|
235
|
-
instance.setPagination(old =>
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
238
|
+
instance.setPagination(old => {
|
|
239
|
+
let newPageCount = functionalUpdate(updater, old.pageCount)
|
|
240
|
+
|
|
241
|
+
if (typeof newPageCount === 'number') {
|
|
242
|
+
newPageCount = Math.max(-1, newPageCount)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
...old,
|
|
247
|
+
pageCount: newPageCount,
|
|
248
|
+
}
|
|
249
|
+
}),
|
|
239
250
|
|
|
240
251
|
getPageOptions: memo(
|
|
241
252
|
() => [
|
|
@@ -244,7 +255,7 @@ export function getInstance<
|
|
|
244
255
|
],
|
|
245
256
|
(pageSize, pageCount) => {
|
|
246
257
|
let pageOptions: number[] = []
|
|
247
|
-
if (pageCount > 0) {
|
|
258
|
+
if (pageCount && pageCount > 0) {
|
|
248
259
|
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i)
|
|
249
260
|
}
|
|
250
261
|
return pageOptions
|
|
@@ -274,12 +285,14 @@ export function getInstance<
|
|
|
274
285
|
)
|
|
275
286
|
},
|
|
276
287
|
|
|
277
|
-
|
|
278
|
-
return instance.setPageIndex
|
|
288
|
+
previousPage: () => {
|
|
289
|
+
return instance.setPageIndex(old => old - 1)
|
|
279
290
|
},
|
|
280
291
|
|
|
281
|
-
|
|
282
|
-
return instance.setPageIndex
|
|
292
|
+
nextPage: () => {
|
|
293
|
+
return instance.setPageIndex(old => {
|
|
294
|
+
return old + 1
|
|
295
|
+
})
|
|
283
296
|
},
|
|
284
297
|
|
|
285
298
|
getPaginationRowModel: memo(
|