table icon indicating copy to clipboard operation
table copied to clipboard

Manual Pagination doesn't update `table.getRowModel().rows` - it shows all results

Open luciodale opened this issue 2 years ago • 4 comments

Describe the bug

I was looking at the manual pagination example here: https://tanstack.com/table/v8/docs/examples/react/pagination-controlled and noticed that the pagination is happening at the query level.

When trying to add the pagination client side, the logic seems to work properly, but the content doesn't update based on the new pagination values. A reproducible example is here: https://codesandbox.io/p/sandbox/boring-wilbur-fqkd7r?embed=1&file=%2Fsrc%2Fmain.tsx%3A79%2C37-82%2C6

My default pagination object looks like this:

{
      pageIndex: 0,
      pageSize: 10
}

but the table shows 100 results. if I change the visible rows from the dropdown in the UI or change the page, the table always shows the whole payload vs paginated results.

Am I actually supposed to slice the data myself off table.getRowModel().rows?

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/boring-wilbur-fqkd7r?embed=1&file=%2Fsrc%2Fmain.tsx%3A79%2C37-82%2C6

Steps to reproduce

Just load the UI and see the data is not being paginated

Expected behavior

Table should only show 10 items as per the default object

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

whatever codesandbox is running on

react-table version

v8.9.2

TypeScript version

No response

Additional context

No response

Terms & Code of Conduct

  • [X] I agree to follow this project's Code of Conduct
  • [X] I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

luciodale avatar Jun 15 '23 11:06 luciodale

Same here.

qutluq avatar Jul 14 '23 07:07 qutluq

@luciodale If you are using controlled pagination you should send only the slice of the data you want to display. So if you have pageSize: 10 table is expecting you to send only 10 items into data property.

ajkl2533 avatar Jul 25 '23 09:07 ajkl2533

I agree with @ajkl2533, the issue should be closed.

talatkuyuk avatar Jul 29 '23 06:07 talatkuyuk

just set manualPagination: true, in your useReactTable for server and manual pagination:

const table = useReactTable({
    data,
    columns,
    state: {
      sorting,
      columnVisibility,
      rowSelection,
      columnFilters,
    },
    manualPagination: true,
    enableRowSelection: true,
    onRowSelectionChange: setRowSelection,
    onSortingChange: setSorting,
    onColumnFiltersChange: setColumnFilters,
    onColumnVisibilityChange: setColumnVisibility,
    getCoreRowModel: getCoreRowModel(),
    getFilteredRowModel: getFilteredRowModel(),
    getPaginationRowModel: getPaginationRowModel(),
    getSortedRowModel: getSortedRowModel(),
    getFacetedRowModel: getFacetedRowModel(),
    getFacetedUniqueValues: getFacetedUniqueValues()
  });

Theo-flux avatar May 30 '25 10:05 Theo-flux