@tanstack/react-table 0.0.1-alpha.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/dist/react-table.development.js +3406 -0
- package/dist/react-table.development.js.map +1 -0
- package/dist/react-table.production.min.js +2 -0
- package/dist/react-table.production.min.js.map +1 -0
- package/lib/index.js +65 -0
- package/package.json +122 -0
- package/src/.DS_Store +0 -0
- package/src/aggregationTypes.ts +115 -0
- package/src/core.tsx +1194 -0
- package/src/createTable.tsx +181 -0
- package/src/features/Expanding.ts +388 -0
- package/src/features/Filters.ts +707 -0
- package/src/features/Grouping.ts +451 -0
- package/src/features/Headers.ts +907 -0
- package/src/features/Ordering.ts +134 -0
- package/src/features/Pinning.ts +213 -0
- package/src/features/Sorting.ts +487 -0
- package/src/features/Visibility.ts +281 -0
- package/src/features/notest/useAbsoluteLayout.test.js +152 -0
- package/src/features/notest/useBlockLayout.test.js +158 -0
- package/src/features/notest/useColumnOrder.test.js +186 -0
- package/src/features/notest/useExpanded.test.js +125 -0
- package/src/features/notest/useFilters.test.js +393 -0
- package/src/features/notest/useFiltersAndRowSelect.test.js +256 -0
- package/src/features/notest/useFlexLayout.test.js +152 -0
- package/src/features/notest/useGroupBy.test.js +259 -0
- package/src/features/notest/usePagination.test.js +231 -0
- package/src/features/notest/useResizeColumns.test.js +229 -0
- package/src/features/notest/useRowSelect.test.js +250 -0
- package/src/features/notest/useRowState.test.js +178 -0
- package/src/features/tests/Visibility.test.tsx +225 -0
- package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +390 -0
- package/src/features/tests/withSorting.notest.tsx +341 -0
- package/src/features/withColumnResizing.ts +281 -0
- package/src/features/withPagination.ts +208 -0
- package/src/features/withRowSelection.ts +467 -0
- package/src/filterTypes.ts +251 -0
- package/src/index.tsx +7 -0
- package/src/sortTypes.ts +159 -0
- package/src/test-utils/makeTestData.ts +41 -0
- package/src/tests/__snapshots__/core.test.tsx.snap +148 -0
- package/src/tests/core.test.tsx +241 -0
- package/src/types.ts +285 -0
- package/src/utils/columnFilterRowsFn.ts +162 -0
- package/src/utils/expandRowsFn.ts +53 -0
- package/src/utils/globalFilterRowsFn.ts +129 -0
- package/src/utils/groupRowsFn.ts +196 -0
- package/src/utils/sortRowsFn.ts +115 -0
- package/src/utils.tsx +243 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
ComponentProps,
|
|
3
|
+
MouseEvent as ReactMouseEvent,
|
|
4
|
+
PropsWithoutRef,
|
|
5
|
+
PropsWithRef,
|
|
6
|
+
TouchEvent as ReactTouchEvent,
|
|
7
|
+
} from 'react'
|
|
8
|
+
|
|
9
|
+
import { getLeafHeaders, makeStateUpdater } from '../utils'
|
|
10
|
+
|
|
11
|
+
import { withColumnResizing as name, withColumnVisibility } from '../Constants'
|
|
12
|
+
import {
|
|
13
|
+
ColumnId,
|
|
14
|
+
ColumnResizing,
|
|
15
|
+
ReduceColumn,
|
|
16
|
+
ReduceHeader,
|
|
17
|
+
Header,
|
|
18
|
+
MakeInstance,
|
|
19
|
+
GetDefaultOptions,
|
|
20
|
+
} from '../types'
|
|
21
|
+
|
|
22
|
+
let passiveSupported: boolean | null = null
|
|
23
|
+
|
|
24
|
+
export function passiveEventSupported() {
|
|
25
|
+
// memoize support to avoid adding multiple test events
|
|
26
|
+
if (typeof passiveSupported === 'boolean') return passiveSupported
|
|
27
|
+
|
|
28
|
+
let supported = false
|
|
29
|
+
try {
|
|
30
|
+
const options = {
|
|
31
|
+
get passive() {
|
|
32
|
+
supported = true
|
|
33
|
+
return false
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
window.addEventListener('test', noop, options)
|
|
38
|
+
window.removeEventListener('test', noop)
|
|
39
|
+
} catch (err) {
|
|
40
|
+
supported = false
|
|
41
|
+
}
|
|
42
|
+
passiveSupported = supported
|
|
43
|
+
return passiveSupported
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const getDefaultOptions: GetDefaultOptions = options => {
|
|
47
|
+
return {
|
|
48
|
+
onColumnResizingChange: React.useCallback(
|
|
49
|
+
makeStateUpdater('columnResizing'),
|
|
50
|
+
[]
|
|
51
|
+
),
|
|
52
|
+
...options,
|
|
53
|
+
initialState: {
|
|
54
|
+
columnResizing: {
|
|
55
|
+
columnWidths: {},
|
|
56
|
+
},
|
|
57
|
+
...options.initialState,
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const extendInstance: MakeInstance = instance => {
|
|
63
|
+
instance.setColumnResizing = React.useCallback(
|
|
64
|
+
updater => instance.options.onColumnResizingChange?.(updater, instance),
|
|
65
|
+
[instance]
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
instance.getColumnCanResize = React.useCallback(
|
|
69
|
+
columnId => {
|
|
70
|
+
const column = instance.allColumns.find(d => d.id === columnId)
|
|
71
|
+
|
|
72
|
+
if (!column) return false
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
(column.disableResizing ? false : undefined) ??
|
|
76
|
+
(instance.options?.disableResizing ? false : undefined) ??
|
|
77
|
+
column.defaultCanResize ??
|
|
78
|
+
true
|
|
79
|
+
)
|
|
80
|
+
},
|
|
81
|
+
[instance.allColumns, instance.options.disableResizing]
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
instance.getColumnWidth = React.useCallback(
|
|
85
|
+
columnId => {
|
|
86
|
+
if (!columnId) return 0
|
|
87
|
+
const { allColumns } = instance
|
|
88
|
+
const column = allColumns.find(d => d.id === columnId)
|
|
89
|
+
const columnWidths = instance.state.columnResizing?.columnWidths
|
|
90
|
+
|
|
91
|
+
if (!column) return 0
|
|
92
|
+
|
|
93
|
+
return Math.min(
|
|
94
|
+
Math.max(
|
|
95
|
+
column?.minWidth ?? 0,
|
|
96
|
+
(columnWidths?.[columnId] ?? 0) || (column.width ?? 0)
|
|
97
|
+
),
|
|
98
|
+
column.maxWidth ?? 0
|
|
99
|
+
)
|
|
100
|
+
},
|
|
101
|
+
[instance]
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
const isResizingColumn = instance.state.columnResizing?.isResizingColumn
|
|
105
|
+
instance.getColumnIsResizing = React.useCallback(
|
|
106
|
+
columnId => {
|
|
107
|
+
return isResizingColumn === columnId
|
|
108
|
+
},
|
|
109
|
+
[isResizingColumn]
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
return instance
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const reduceColumn: ReduceColumn = (column, { instance }) => {
|
|
116
|
+
column.getIsResizing = () => instance.getColumnIsResizing(column.id)
|
|
117
|
+
column.getCanResize = () => instance.getColumnCanResize(column.id)
|
|
118
|
+
|
|
119
|
+
return column
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const reduceHeader: ReduceHeader = (header, { instance }) => {
|
|
123
|
+
header.getIsResizing = () =>
|
|
124
|
+
header?.column?.getIsResizing ? header.column.getIsResizing() : true
|
|
125
|
+
header.getCanResize = () =>
|
|
126
|
+
header?.column?.getCanResize ? header.column.getCanResize() : true
|
|
127
|
+
|
|
128
|
+
function isTouchStartEvent(
|
|
129
|
+
e: ReactTouchEvent | ReactMouseEvent
|
|
130
|
+
): e is ReactTouchEvent {
|
|
131
|
+
return e.type === 'touchstart'
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
header.getResizerProps = (props = {}) => {
|
|
135
|
+
const onResizeStart = (
|
|
136
|
+
e: ReactMouseEvent | ReactTouchEvent,
|
|
137
|
+
header: Header
|
|
138
|
+
) => {
|
|
139
|
+
if (isTouchStartEvent(e)) {
|
|
140
|
+
// lets not respond to multiple touches (e.g. 2 or 3 fingers)
|
|
141
|
+
if (e.touches && e.touches.length > 1) {
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const headersToResize = getLeafHeaders(header)
|
|
146
|
+
const headerIdWidths: [ColumnId, number][] = headersToResize.map(d => [
|
|
147
|
+
d.id,
|
|
148
|
+
d.getWidth(),
|
|
149
|
+
])
|
|
150
|
+
|
|
151
|
+
const clientX = isTouchStartEvent(e)
|
|
152
|
+
? Math.round(e.touches[0].clientX)
|
|
153
|
+
: e.clientX
|
|
154
|
+
|
|
155
|
+
const onMove = (clientXPos?: number) => {
|
|
156
|
+
if (typeof clientXPos !== 'number') {
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return instance.setColumnResizing(old => {
|
|
161
|
+
const deltaX = clientXPos - (old?.startX ?? 0)
|
|
162
|
+
const percentageDeltaX = Math.max(
|
|
163
|
+
deltaX / (old?.columnWidth ?? 0),
|
|
164
|
+
-0.999999
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
const newColumnWidths: ColumnResizing['columnWidths'] = {}
|
|
168
|
+
;(old?.headerIdWidths ?? []).forEach(([headerId, headerWidth]) => {
|
|
169
|
+
newColumnWidths[headerId] = Math.max(
|
|
170
|
+
headerWidth + headerWidth * percentageDeltaX,
|
|
171
|
+
0
|
|
172
|
+
)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
...old,
|
|
177
|
+
columnWidths: {
|
|
178
|
+
...(old?.columnWidths ?? {}),
|
|
179
|
+
...newColumnWidths,
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const onEnd = () =>
|
|
186
|
+
instance.setColumnResizing(old => ({
|
|
187
|
+
...old,
|
|
188
|
+
startX: null,
|
|
189
|
+
isResizingColumn: false,
|
|
190
|
+
}))
|
|
191
|
+
|
|
192
|
+
const mouseEvents = {
|
|
193
|
+
moveHandler: (e: MouseEvent) => onMove(e.clientX),
|
|
194
|
+
upHandler: () => {
|
|
195
|
+
document.removeEventListener('mousemove', mouseEvents.moveHandler)
|
|
196
|
+
document.removeEventListener('mouseup', mouseEvents.upHandler)
|
|
197
|
+
onEnd()
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const touchEvents = {
|
|
202
|
+
moveHandler: (e: TouchEvent) => {
|
|
203
|
+
if (e.cancelable) {
|
|
204
|
+
e.preventDefault()
|
|
205
|
+
e.stopPropagation()
|
|
206
|
+
}
|
|
207
|
+
onMove(e.touches[0].clientX)
|
|
208
|
+
return false
|
|
209
|
+
},
|
|
210
|
+
upHandler: () => {
|
|
211
|
+
document.removeEventListener('touchmove', touchEvents.moveHandler)
|
|
212
|
+
document.removeEventListener('touchend', touchEvents.upHandler)
|
|
213
|
+
onEnd()
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const passiveIfSupported = passiveEventSupported()
|
|
218
|
+
? { passive: false }
|
|
219
|
+
: false
|
|
220
|
+
|
|
221
|
+
if (isTouchStartEvent(e)) {
|
|
222
|
+
document.addEventListener(
|
|
223
|
+
'touchmove',
|
|
224
|
+
touchEvents.moveHandler,
|
|
225
|
+
passiveIfSupported
|
|
226
|
+
)
|
|
227
|
+
document.addEventListener(
|
|
228
|
+
'touchend',
|
|
229
|
+
touchEvents.upHandler,
|
|
230
|
+
passiveIfSupported
|
|
231
|
+
)
|
|
232
|
+
} else {
|
|
233
|
+
document.addEventListener(
|
|
234
|
+
'mousemove',
|
|
235
|
+
mouseEvents.moveHandler,
|
|
236
|
+
passiveIfSupported
|
|
237
|
+
)
|
|
238
|
+
document.addEventListener(
|
|
239
|
+
'mouseup',
|
|
240
|
+
mouseEvents.upHandler,
|
|
241
|
+
passiveIfSupported
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
instance.setColumnResizing(old => ({
|
|
246
|
+
...old,
|
|
247
|
+
startX: clientX,
|
|
248
|
+
headerIdWidths,
|
|
249
|
+
columnWidth: header.getWidth(),
|
|
250
|
+
isResizingColumn: header.id,
|
|
251
|
+
}))
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
onMouseDown: (e: ReactMouseEvent) => {
|
|
256
|
+
e.persist()
|
|
257
|
+
onResizeStart(e, header)
|
|
258
|
+
},
|
|
259
|
+
onTouchStart: (e: ReactTouchEvent) => {
|
|
260
|
+
e.persist()
|
|
261
|
+
onResizeStart(e, header)
|
|
262
|
+
},
|
|
263
|
+
draggable: false,
|
|
264
|
+
role: 'separator',
|
|
265
|
+
...props,
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return header
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export const withColumnResizing = {
|
|
273
|
+
name,
|
|
274
|
+
after: [withColumnVisibility],
|
|
275
|
+
plugs: {
|
|
276
|
+
getDefaultOptions,
|
|
277
|
+
extendInstance,
|
|
278
|
+
reduceColumn,
|
|
279
|
+
reduceHeader,
|
|
280
|
+
},
|
|
281
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
functionalUpdate,
|
|
5
|
+
expandRows,
|
|
6
|
+
useLazyMemo,
|
|
7
|
+
useMountedLayoutEffect,
|
|
8
|
+
makeStateUpdater,
|
|
9
|
+
} from '../utils'
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
withPagination as name,
|
|
13
|
+
withColumnVisibility,
|
|
14
|
+
withColumnFilters,
|
|
15
|
+
withGlobalFilter,
|
|
16
|
+
withGrouping,
|
|
17
|
+
withSorting,
|
|
18
|
+
withExpanding,
|
|
19
|
+
} from '../Constants'
|
|
20
|
+
import { MakeInstance, GetDefaultOptions } from '../types'
|
|
21
|
+
|
|
22
|
+
const getDefaultOptions: GetDefaultOptions = options => {
|
|
23
|
+
return {
|
|
24
|
+
onPageIndexChange: React.useCallback(makeStateUpdater('pageIndex'), []),
|
|
25
|
+
onPageSizeChange: React.useCallback(makeStateUpdater('pageSize'), []),
|
|
26
|
+
onPageCountChange: React.useCallback(makeStateUpdater('pageCount'), []),
|
|
27
|
+
autoResetPageIndex: true,
|
|
28
|
+
paginateExpandedRows: true,
|
|
29
|
+
...options,
|
|
30
|
+
initialState: {
|
|
31
|
+
pageIndex: 0,
|
|
32
|
+
pageSize: 10,
|
|
33
|
+
pageCount: 0,
|
|
34
|
+
...options.initialState,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const extendInstance: MakeInstance = instance => {
|
|
40
|
+
const pageResetDeps = [
|
|
41
|
+
instance.options.manualPagination ? null : instance.options.data,
|
|
42
|
+
instance.state.globalFilter,
|
|
43
|
+
instance.state.columnFilters,
|
|
44
|
+
instance.state.grouping,
|
|
45
|
+
instance.state.sorting,
|
|
46
|
+
]
|
|
47
|
+
React.useMemo(() => {
|
|
48
|
+
if (instance.options.autoResetPageIndex) {
|
|
49
|
+
instance.state.pageIndex = instance.options.initialState?.pageIndex ?? 0
|
|
50
|
+
}
|
|
51
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
+
}, pageResetDeps)
|
|
53
|
+
|
|
54
|
+
useMountedLayoutEffect(() => {
|
|
55
|
+
if (instance.options.autoResetPageIndex) {
|
|
56
|
+
instance.resetPageIndex?.()
|
|
57
|
+
}
|
|
58
|
+
}, pageResetDeps)
|
|
59
|
+
|
|
60
|
+
instance.setPageIndex = React.useCallback(
|
|
61
|
+
updater =>
|
|
62
|
+
instance.options.onPageIndexChange?.(old => {
|
|
63
|
+
const newPageIndex = functionalUpdate(updater, old)
|
|
64
|
+
const pageCount = instance.getPageCount?.() ?? 0
|
|
65
|
+
const maxPageIndex =
|
|
66
|
+
pageCount > 0 ? pageCount - 1 : Number.MAX_SAFE_INTEGER
|
|
67
|
+
|
|
68
|
+
return Math.min(Math.max(0, newPageIndex), maxPageIndex)
|
|
69
|
+
}, instance),
|
|
70
|
+
[instance]
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
instance.setPageSize = React.useCallback(
|
|
74
|
+
updater =>
|
|
75
|
+
instance.options.onPageSizeChange?.(old => {
|
|
76
|
+
const newPageSize = Math.max(1, functionalUpdate(updater, old))
|
|
77
|
+
const topRowIndex = old! * instance.state.pageIndex!
|
|
78
|
+
const pageIndex = Math.floor(topRowIndex / newPageSize)
|
|
79
|
+
|
|
80
|
+
if (instance.state.pageIndex !== pageIndex) {
|
|
81
|
+
instance.setPageIndex?.(pageIndex)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return newPageSize
|
|
85
|
+
}, instance),
|
|
86
|
+
[instance]
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
instance.setPageCount = React.useCallback(
|
|
90
|
+
updater =>
|
|
91
|
+
instance.options.onPageCountChange?.(
|
|
92
|
+
old => Math.max(0, functionalUpdate(updater, old)),
|
|
93
|
+
instance
|
|
94
|
+
),
|
|
95
|
+
[instance]
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
instance.resetPageIndex = React.useCallback(
|
|
99
|
+
() =>
|
|
100
|
+
instance.setPageIndex?.(instance.options.initialState?.pageIndex ?? 0),
|
|
101
|
+
[instance]
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
instance.resetPageSize = React.useCallback(
|
|
105
|
+
() => instance.setPageSize?.(instance.options.initialState?.pageSize ?? 10),
|
|
106
|
+
[instance]
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
instance.resetPageCount = React.useCallback(
|
|
110
|
+
() =>
|
|
111
|
+
instance.setPageCount?.(instance.options.initialState?.pageCount ?? 0),
|
|
112
|
+
[instance]
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
instance.getPageCount = React.useCallback(
|
|
116
|
+
() =>
|
|
117
|
+
instance.options.manualPagination
|
|
118
|
+
? instance.state.pageCount!
|
|
119
|
+
: instance.rows
|
|
120
|
+
? Math.ceil(instance.rows.length / instance.state.pageSize!)
|
|
121
|
+
: -1,
|
|
122
|
+
[
|
|
123
|
+
instance.options.manualPagination,
|
|
124
|
+
instance.rows,
|
|
125
|
+
instance.state.pageCount,
|
|
126
|
+
instance.state.pageSize,
|
|
127
|
+
]
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
const pageCount = instance.getPageCount?.()
|
|
131
|
+
|
|
132
|
+
instance.getPageOptions = useLazyMemo(() => {
|
|
133
|
+
let pageOptions: number[] = []
|
|
134
|
+
if (pageCount > 0) {
|
|
135
|
+
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i)
|
|
136
|
+
}
|
|
137
|
+
return pageOptions
|
|
138
|
+
}, [pageCount])
|
|
139
|
+
|
|
140
|
+
instance.getPageRows = React.useCallback(() => {
|
|
141
|
+
const {
|
|
142
|
+
rows,
|
|
143
|
+
state: { pageIndex, pageSize },
|
|
144
|
+
options: { manualPagination },
|
|
145
|
+
} = instance
|
|
146
|
+
let page
|
|
147
|
+
|
|
148
|
+
if (manualPagination) {
|
|
149
|
+
page = rows
|
|
150
|
+
} else {
|
|
151
|
+
const pageStart = pageSize! * pageIndex!
|
|
152
|
+
const pageEnd = pageStart + pageSize!
|
|
153
|
+
|
|
154
|
+
page = rows.slice(pageStart, pageEnd)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (instance.options.paginateExpandedRows) {
|
|
158
|
+
return page
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return expandRows(page, instance)
|
|
162
|
+
}, [instance])
|
|
163
|
+
|
|
164
|
+
instance.getCanPreviousPage = React.useCallback(
|
|
165
|
+
() => instance.state.pageIndex! > 0,
|
|
166
|
+
[instance.state.pageIndex]
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
instance.getCanNextPage = React.useCallback(() => {
|
|
170
|
+
const {
|
|
171
|
+
state: { pageSize, pageIndex },
|
|
172
|
+
getPageRows,
|
|
173
|
+
getPageCount,
|
|
174
|
+
} = instance
|
|
175
|
+
|
|
176
|
+
const pageCount = getPageCount?.() ?? 0
|
|
177
|
+
|
|
178
|
+
return pageCount === 0
|
|
179
|
+
? (getPageRows?.().length ?? 0) >= pageSize!
|
|
180
|
+
: pageIndex! < (pageCount ?? 0) - 1
|
|
181
|
+
}, [instance])
|
|
182
|
+
|
|
183
|
+
instance.gotoPreviousPage = React.useCallback(() => {
|
|
184
|
+
return instance.setPageIndex?.(old => old! - 1)
|
|
185
|
+
}, [instance])
|
|
186
|
+
|
|
187
|
+
instance.gotoNextPage = React.useCallback(() => {
|
|
188
|
+
return instance.setPageIndex?.(old => old! + 1)
|
|
189
|
+
}, [instance])
|
|
190
|
+
|
|
191
|
+
return instance
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export const withPagination = {
|
|
195
|
+
name,
|
|
196
|
+
after: [
|
|
197
|
+
withColumnVisibility,
|
|
198
|
+
withColumnFilters,
|
|
199
|
+
withGlobalFilter,
|
|
200
|
+
withGrouping,
|
|
201
|
+
withSorting,
|
|
202
|
+
withExpanding,
|
|
203
|
+
],
|
|
204
|
+
plugs: {
|
|
205
|
+
getDefaultOptions,
|
|
206
|
+
extendInstance,
|
|
207
|
+
},
|
|
208
|
+
}
|