[ Data Display ]

Table

A data table driven by a columns array and a data array. Columns can render custom cells, align content and set a width. Built-in pagination handles client-side and server-side data, with an optional rows-per-page select. The table scrolls horizontally on small screens.

8 examplesDark modeAccessible

Import#

import { Table } from 'reusify-ui';

When to use#

  • Comparing structured records across the same attributes: users, orders, invoices.
  • For a handful of items with rich content, a list of Cards may read better.
  • Turn on pagination once a list grows past roughly 10–20 rows, so the page stays short and fast.

Examples#

Basic#

Columns read row[key] by default. rowKey gives React a stable key per row.

NameEmailRole
Aarav Sharmaaarav@acme.devAdmin
Priya Vermapriya@acme.devEditor
Rohan Guptarohan@acme.devViewer
Isha Patelisha@acme.devEditor
const columns = [
  { key: 'name', header: 'Name' },
  { key: 'email', header: 'Email' },
  { key: 'role', header: 'Role' },
];

<Table columns={columns} data={users} rowKey="id" />

Custom cells, striped & hover#

render(row, index) returns any JSX. Combine it with Avatar and Badge for a typical admin table.

UserRoleStatus
Aarav Sharma
aarav@acme.dev
AdminActive
Priya Verma
priya@acme.dev
EditorInvited
Rohan Gupta
rohan@acme.dev
ViewerActive
Isha Patel
isha@acme.dev
EditorSuspended
<Table
  striped
  hoverable
  rowKey="id"
  data={users}
  columns={[
    {
      key: 'name',
      header: 'User',
      render: (u) => (
        <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
          <Avatar name={u.name} size="sm" />
          <div>
            <div>{u.name}</div>
            <small>{u.email}</small>
          </div>
        </div>
      ),
    },
    { key: 'role', header: 'Role' },
    {
      key: 'status',
      header: 'Status',
      align: 'right',
      render: (u) => <Badge color={statusColor[u.status]} dot>{u.status}</Badge>,
    },
  ]}
/>

Pagination#

Add pagination and the table slices data into pages for you, with a "Showing 1–5 of 57" summary and page buttons in the footer. Pass true for 10 rows per page, or an object to configure it.

UserRolePlanStatusMRR
Aarav Sharma
aarav.sharma0@acme.dev
OwnerTeamActive₹1,999
Priya Mehta
priya.mehta1@acme.dev
ViewerTeamActive₹1,999
Rohan Gupta
rohan.gupta2@acme.dev
ViewerHobbyActive₹0
Isha Das
isha.das3@acme.dev
ViewerTeamActive₹1,999
Kabir Singh
kabir.singh4@acme.dev
ViewerProActive₹499
// 57 users, 5 per page
<Table
  rowKey="id"
  columns={columns}
  data={users}
  pagination={{ pageSize: 5 }}
/>

Rows per page#

pageSizeOptions adds a "Rows per page" select to the footer. Changing it jumps back to page 1. Use defaultPageSize to choose the starting size.

UserRolePlanStatusMRR
Aarav Sharma
aarav.sharma0@acme.dev
OwnerTeamActive₹1,999
Priya Mehta
priya.mehta1@acme.dev
ViewerTeamActive₹1,999
Rohan Gupta
rohan.gupta2@acme.dev
ViewerHobbyActive₹0
Isha Das
isha.das3@acme.dev
ViewerTeamActive₹1,999
Kabir Singh
kabir.singh4@acme.dev
ViewerProActive₹499
Neha Iyer
neha.iyer5@acme.dev
AdminTeamInvited₹1,999
Dev Ali
dev.ali6@acme.dev
EditorProActive₹499
Sara Gupta
sara.gupta7@acme.dev
EditorHobbyInvited₹0
Arjun Gupta
arjun.gupta8@acme.dev
EditorTeamActive₹1,999
Ananya Gupta
ananya.gupta9@acme.dev
EditorEnterpriseActive₹9,999
<Table
  rowKey="id"
  size="sm"
  striped
  columns={columns}
  data={users}
  pagination={{ defaultPageSize: 10, pageSizeOptions: [5, 10, 20, 50] }}
/>

Controlled page#

Pass page and onPageChange to keep the current page in your own state, for example to sync it with the URL or jump to a page from outside the table.

Current page in parent state: 3
UserRolePlanStatusMRR
Aditya Patel
aditya.patel12@acme.dev
EditorEnterpriseSuspended₹0
Kavya Khan
kavya.khan13@acme.dev
AdminProActive₹499
Reyansh Singh
reyansh.singh14@acme.dev
ViewerHobbyActive₹0
Diya Singh
diya.singh15@acme.dev
ViewerProActive₹499
Ishaan Sharma
ishaan.sharma16@acme.dev
AdminProInvited₹499
Tara Khan
tara.khan17@acme.dev
EditorHobbyActive₹0
const [page, setPage] = useState(3);

<Button onClick={() => setPage(1)}>First page</Button>

<Table
  rowKey="id"
  columns={columns}
  data={users}
  pagination={{ page, onPageChange: setPage, pageSize: 6 }}
/>

Server-side pagination#

When your API returns one page at a time, pass totalRows. The table then shows data as-is (it doesn't slice it) and builds the footer from totalRows. loading dims the rows while the next page is fetched. This demo uses a fake API with a 600 ms delay.

UserRolePlanStatusMRR
Loading…
function UsersTable() {
  const [page, setPage] = useState(1);
  const [pageSize, setPageSize] = useState(5);
  const [result, setResult] = useState({ rows: [], total: 0, loading: true });

  useEffect(() => {
    setResult((r) => ({ ...r, loading: true }));
    fetch(`/api/users?page=${page}&size=${pageSize}`)
      .then((res) => res.json())
      .then(({ rows, total }) => setResult({ rows, total, loading: false }));
  }, [page, pageSize]);

  return (
    <Table
      rowKey="id"
      columns={columns}
      data={result.rows}
      loading={result.loading}
      pagination={{
        page,
        onPageChange: setPage,
        pageSize,
        onPageSizeChange: setPageSize,
        pageSizeOptions: [5, 10, 20],
        totalRows: result.total,
      }}
    />
  );
}

Interactive example: users admin#

Everything together on 57 dummy users: search, status and plan filters, rows per page, pagination, and a Drawer with details when you click a row. Filters reset the page to 1, and the page stays controlled in parent state.

57 users · ₹1,75,456 MRR · click a row for details

UserRolePlanStatusMRR
Aarav Sharma
aarav.sharma0@acme.dev
OwnerTeamActive₹1,999
Priya Mehta
priya.mehta1@acme.dev
ViewerTeamActive₹1,999
Rohan Gupta
rohan.gupta2@acme.dev
ViewerHobbyActive₹0
Isha Das
isha.das3@acme.dev
ViewerTeamActive₹1,999
Kabir Singh
kabir.singh4@acme.dev
ViewerProActive₹499
Neha Iyer
neha.iyer5@acme.dev
AdminTeamInvited₹1,999
Dev Ali
dev.ali6@acme.dev
EditorProActive₹499
Sara Gupta
sara.gupta7@acme.dev
EditorHobbyInvited₹0
function UsersAdmin() {
  const [query, setQuery] = useState('');
  const [status, setStatus] = useState('all');
  const [page, setPage] = useState(1);
  const [selected, setSelected] = useState(null);

  const filtered = users.filter(
    (u) =>
      (status === 'all' || u.status === status) &&
      u.name.toLowerCase().includes(query.toLowerCase()),
  );

  return (
    <>
      <Input
        placeholder="Search…"
        leftIcon={<FiSearch />}
        value={query}
        onChange={(e) => { setQuery(e.target.value); setPage(1); }}
      />
      <Select
        value={status}
        onChange={(v) => { setStatus(v); setPage(1); }}
        options={[
          { label: 'All statuses', value: 'all' },
          { label: 'Active', value: 'Active' },
          { label: 'Invited', value: 'Invited' },
          { label: 'Suspended', value: 'Suspended' },
        ]}
      />

      <Table
        rowKey="id"
        hoverable
        columns={columns}
        data={filtered}
        onRowClick={setSelected}
        emptyText="No users match these filters."
        pagination={{ page, onPageChange: setPage, defaultPageSize: 8, pageSizeOptions: [5, 8, 15, 25] }}
      />

      <Drawer open={!!selected} onClose={() => setSelected(null)} title="User details">
        {selected && <UserDetails user={selected} />}
      </Drawer>
    </>
  );
}

Empty state & compact size#

NameRole
No users yet. Invite your team!
<Table size="sm" columns={columns} data={[]} emptyText="No users yet. Invite your team!" />

API reference#

<Table />

columns*-
TableColumn[]

Column definitions (see below).

data*-
object[]

Rows to display.

rowKeyindex
string | (row, index) => string | number

Property name or function returning a stable key per row.

stripedfalse
boolean

Alternating row backgrounds.

hoverablefalse
boolean

Highlights the row under the cursor.

size'md'
'sm' | 'md'

Cell padding.

caption-
ReactNode

Table caption, shown below the table.

emptyText'No data'
ReactNode

Shown when data is empty.

onRowClick-
(row, index) => void

Makes rows clickable (also turns on hover).

paginationfalse
boolean | TablePagination

Splits rows into pages with a footer. true means 10 rows per page; pass an object to configure (see below).

loadingfalse
boolean

Dims the rows and sets aria-busy, e.g. while fetching the next page.

className-
string

Class for the outer wrapper.

<TablePagination />

The options object for pagination. index in render(row, index) and onRowClick is the position in the full data, not within the page.

pageSize10
number

Rows per page. Controlled only when onPageSizeChange is also passed.

defaultPageSize10
number

Starting rows per page when users can change it.

pageSizeOptions-
number[]

Shows a "Rows per page" select with these sizes.

onPageSizeChange-
(size: number) => void

Called when the rows-per-page select changes. Makes pageSize controlled.

page-
number

Current page, starting at 1 (controlled).

defaultPage1
number

Starting page (uncontrolled).

onPageChange-
(page: number) => void

Called with the new page.

totalRows-
number

Server-side mode: data is already the current page and totalRows is the size of the whole set.

siblingCount1
number

Page buttons shown on each side of the current page.

<TableColumn />

The shape of each item in columns.

key*-
string

Unique column id and the default property to read.

header*-
ReactNode

Header cell content.

render-
(row, index) => ReactNode

Custom cell renderer.

align'left'
'left' | 'center' | 'right'

Text alignment for header and cells.

width-
string | number

Column width.

Accessibility#

  • Uses semantic <table>, <thead>, <th scope="col"> and <tbody>.
  • Add a caption to describe the data for screen-reader users.
  • onRowClick rows aren't keyboard-focusable. Also put a link or button in a cell for keyboard users.
  • The pagination footer uses the accessible Pagination and Select components; the "Showing x–y of z" summary is announced politely when the page changes.
  • loading sets aria-busy on the table so assistive tech knows new rows are coming.