Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Paginated Data Table for Ark UI

A transactions table, five rows per page, with Previous, Next and a Page label. Columns include ID, Description, Date, Status and Amount.

A transactions table shows five rows at a time. Columns include ID, Description, Date, Status and Amount. Under it, a Page label sits beside Previous and Next.

Step through pages when people rarely jump, such as a ledger. Numbered buttons, as on Pagination, fit when they jump to a page. In React, Ark UI does not count the pages.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Use email insteadNo credit card

Usage

<div className="w-full max-w-4xl">
  <div className="rounded-md border bg-background">
    <Table>
      <TableHeader>
        {table.getHeaderGroups().map((headerGroup) => (
          <TableRow key={headerGroup.id}>
            {headerGroup.headers.map((header) => (
              <TableHead key={header.id}>
                {header.isPlaceholder ? null : (
                  <table.FlexRender header={header} />
                )}
              </TableHead>
            ))}
          </TableRow>
        ))}
      </TableHeader>
      <TableBody>
        {rows.length > 0 ? (
          rows.map((row) => (
            <TableRow key={row.id}>
              {row.getAllCells().map((cell) => (
                <TableCell key={cell.id}>
                  <table.FlexRender cell={cell} />
                </TableCell>
              ))}
            </TableRow>
          ))
        ) : (
          <TableRow>
            <TableCell
              className="h-24 text-center"
{/* The rest of the file is under Installation. */}

FAQ

How many rows are on a page?

Five: initialState.pagination sets pageSize to 5, and getRowModel() returns that page through rowPaginationFeature and createPaginatedRowModel(). Call table.setPageSize to change it.

How do Previous and Next work?

They call table.previousPage() and table.nextPage(), and each is disabled when getCanPreviousPage() or getCanNextPage() is false.

What does the page label read?

Page, then table.state.pagination.pageIndex + 1, of table.getPageCount(). The index starts at zero, so the label adds one.

Is the page index stored outside the table?

No, only initialState is passed and the table keeps the page. Read it from table.state.pagination or listen with onPaginationChange to sync it with the URL.

What appears when there are no rows?

One cell spanning every column with No results.With these eight transactions it doesn't show.

Can I change pages from the keyboard?

Previous and Next are buttons, so Tab reaches them and Enter or Space activates them; a disabled one is skipped. For a jump to any page, see the numeric pagination example.

API Reference

Table

Sets colSpan={columns.length}. The rest is on the Table page.

Button

Sets disabled={!table.getCanPreviousPage()}, onClick={handlePrevious}, size="sm", variant="outline", disabled={!table.getCanNextPage()} and onClick={handleNext}. The rest is on the Button page.