TanStackT
TanStack3y ago
4 replies
technological-jade

Pagination - how to start pageIndex from 1 not 0?

My initalPagination is
  const [{ pageIndex, pageSize }, setPagination] =
    React.useState<PaginationState>({
      pageIndex: 1,
      pageSize: 10,
    });

but when I open a select menu with pageSize values and select e.g. 20
     <select
          value={table.getState().pagination.pageSize}
          onChange={(e) => {
            table.setPageSize(Number(e.target.value));
          }}
        >
          {[10, 20, 30, 40, 50].map((pageSize) => (
            <option key={pageSize} value={pageSize}>
              Show {pageSize}
            </option>
          ))}
        </select>

the pageIndex is 0.
How to set the pageIndex to start from 1 not from 0?
https://codesandbox.io/p/sandbox/sweet-darkness-md8pvc?welcome=true&file=README.md
image.png
CodeSandbox is an online editor tailored for web applications.
sweet-darkness-md8pvc
Was this page helpful?