T
TanStack•14mo ago
ratty-blush

table.nextPage() not doing anything for me

export const TaskTable: FC<Props> = observer(({ tasks }) => {
const [pagination, setPagination] = useState<PaginationState>({
pageIndex: 0,
pageSize: 10,
})

const table = useReactTable({
data: [...tasks],
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onPaginationChange: setPagination,
state: {
pagination,
},
})

return (
<div>
{JSON.stringify(pagination, null, 2)}
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow>
{headerGroup.headers.map((header) => (
<TableHead id={header.id}>
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
</TableHead>
))}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows.map((row) => (
<TableRow key={row.id}>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious
onClick={() => {
table.previousPage()
}}
aria-disabled={!table.getCanPreviousPage()}
/>
</PaginationItem>
<PaginationItem>
<PaginationNext
onClick={() => {
console.log(1)

table.nextPage(2)
}}
aria-disabled={!table.getCanNextPage()}
/>
</PaginationItem>
</PaginationContent>
</Pagination>
</div>
)})
export const TaskTable: FC<Props> = observer(({ tasks }) => {
const [pagination, setPagination] = useState<PaginationState>({
pageIndex: 0,
pageSize: 10,
})

const table = useReactTable({
data: [...tasks],
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onPaginationChange: setPagination,
state: {
pagination,
},
})

return (
<div>
{JSON.stringify(pagination, null, 2)}
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow>
{headerGroup.headers.map((header) => (
<TableHead id={header.id}>
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
</TableHead>
))}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows.map((row) => (
<TableRow key={row.id}>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious
onClick={() => {
table.previousPage()
}}
aria-disabled={!table.getCanPreviousPage()}
/>
</PaginationItem>
<PaginationItem>
<PaginationNext
onClick={() => {
console.log(1)

table.nextPage(2)
}}
aria-disabled={!table.getCanNextPage()}
/>
</PaginationItem>
</PaginationContent>
</Pagination>
</div>
)})
4 Replies
ratty-blush
ratty-blushOP•14mo ago
Title says it all, here is my table. When I click the next button, the console.log fires but it doesn't go to the next page?
ratty-blush
ratty-blushOP•14mo ago
Turning on debugTable every time I click next I get the following logs
No description
ratty-blush
ratty-blushOP•14mo ago
Adding this line fixed it for me autoResetAll: false,
probable-pink
probable-pink•14mo ago
Good find. I think this is down to the fact you are managing your own pagination state. When this is the case you also need to override the default reset logic. 💯

Did you find this page helpful?