[ 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.
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.
| Name | Role | |
|---|---|---|
| Aarav Sharma | aarav@acme.dev | Admin |
| Priya Verma | priya@acme.dev | Editor |
| Rohan Gupta | rohan@acme.dev | Viewer |
| Isha Patel | isha@acme.dev | Editor |
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.
| User | Role | Status |
|---|---|---|
Aarav Sharma aarav@acme.dev | Admin | Active |
Priya Verma priya@acme.dev | Editor | Invited |
Rohan Gupta rohan@acme.dev | Viewer | Active |
Isha Patel isha@acme.dev | Editor | Suspended |
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.
| User | Role | Plan | Status | MRR |
|---|---|---|---|---|
Aarav Sharma aarav.sharma0@acme.dev | Owner | Team | Active | ₹1,999 |
Priya Mehta priya.mehta1@acme.dev | Viewer | Team | Active | ₹1,999 |
Rohan Gupta rohan.gupta2@acme.dev | Viewer | Hobby | Active | ₹0 |
Isha Das isha.das3@acme.dev | Viewer | Team | Active | ₹1,999 |
Kabir Singh kabir.singh4@acme.dev | Viewer | Pro | Active | ₹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.
| User | Role | Plan | Status | MRR |
|---|---|---|---|---|
Aarav Sharma aarav.sharma0@acme.dev | Owner | Team | Active | ₹1,999 |
Priya Mehta priya.mehta1@acme.dev | Viewer | Team | Active | ₹1,999 |
Rohan Gupta rohan.gupta2@acme.dev | Viewer | Hobby | Active | ₹0 |
Isha Das isha.das3@acme.dev | Viewer | Team | Active | ₹1,999 |
Kabir Singh kabir.singh4@acme.dev | Viewer | Pro | Active | ₹499 |
Neha Iyer neha.iyer5@acme.dev | Admin | Team | Invited | ₹1,999 |
Dev Ali dev.ali6@acme.dev | Editor | Pro | Active | ₹499 |
Sara Gupta sara.gupta7@acme.dev | Editor | Hobby | Invited | ₹0 |
Arjun Gupta arjun.gupta8@acme.dev | Editor | Team | Active | ₹1,999 |
Ananya Gupta ananya.gupta9@acme.dev | Editor | Enterprise | Active | ₹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.
3| User | Role | Plan | Status | MRR |
|---|---|---|---|---|
Aditya Patel aditya.patel12@acme.dev | Editor | Enterprise | Suspended | ₹0 |
Kavya Khan kavya.khan13@acme.dev | Admin | Pro | Active | ₹499 |
Reyansh Singh reyansh.singh14@acme.dev | Viewer | Hobby | Active | ₹0 |
Diya Singh diya.singh15@acme.dev | Viewer | Pro | Active | ₹499 |
Ishaan Sharma ishaan.sharma16@acme.dev | Admin | Pro | Invited | ₹499 |
Tara Khan tara.khan17@acme.dev | Editor | Hobby | Active | ₹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.
| User | Role | Plan | Status | MRR |
|---|---|---|---|---|
| Loading… | ||||
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
| User | Role | Plan | Status | MRR |
|---|---|---|---|---|
Aarav Sharma aarav.sharma0@acme.dev | Owner | Team | Active | ₹1,999 |
Priya Mehta priya.mehta1@acme.dev | Viewer | Team | Active | ₹1,999 |
Rohan Gupta rohan.gupta2@acme.dev | Viewer | Hobby | Active | ₹0 |
Isha Das isha.das3@acme.dev | Viewer | Team | Active | ₹1,999 |
Kabir Singh kabir.singh4@acme.dev | Viewer | Pro | Active | ₹499 |
Neha Iyer neha.iyer5@acme.dev | Admin | Team | Invited | ₹1,999 |
Dev Ali dev.ali6@acme.dev | Editor | Pro | Active | ₹499 |
Sara Gupta sara.gupta7@acme.dev | Editor | Hobby | Invited | ₹0 |
Empty state & compact size#
| Name | Role |
|---|---|
| No users yet. Invite your team! | |
<Table size="sm" columns={columns} data={[]} emptyText="No users yet. Invite your team!" />API reference#
<Table />
| Prop | Type | Default | Description |
|---|---|---|---|
columns* | TableColumn[] | - | Column definitions (see below). |
data* | object[] | - | Rows to display. |
rowKey | string | (row, index) => string | number | index | Property name or function returning a stable key per row. |
striped | boolean | false | Alternating row backgrounds. |
hoverable | boolean | false | Highlights the row under the cursor. |
size | 'sm' | 'md' | 'md' | Cell padding. |
caption | ReactNode | - | Table caption, shown below the table. |
emptyText | ReactNode | 'No data' | Shown when data is empty. |
onRowClick | (row, index) => void | - | Makes rows clickable (also turns on hover). |
pagination | boolean | TablePagination | false | Splits rows into pages with a footer. true means 10 rows per page; pass an object to configure (see below). |
loading | boolean | false | Dims the rows and sets aria-busy, e.g. while fetching the next page. |
className | string | - | Class for the outer wrapper. |
columns*-TableColumn[]Column definitions (see below).
data*-object[]Rows to display.
rowKeyindexstring | (row, index) => string | numberProperty name or function returning a stable key per row.
stripedfalsebooleanAlternating row backgrounds.
hoverablefalsebooleanHighlights the row under the cursor.
size'md''sm' | 'md'Cell padding.
caption-ReactNodeTable caption, shown below the table.
emptyText'No data'ReactNodeShown when data is empty.
onRowClick-(row, index) => voidMakes rows clickable (also turns on hover).
paginationfalseboolean | TablePaginationSplits rows into pages with a footer. true means 10 rows per page; pass an object to configure (see below).
loadingfalsebooleanDims the rows and sets aria-busy, e.g. while fetching the next page.
className-stringClass 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.
| Prop | Type | Default | Description |
|---|---|---|---|
pageSize | number | 10 | Rows per page. Controlled only when onPageSizeChange is also passed. |
defaultPageSize | number | 10 | 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). |
defaultPage | number | 1 | 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. |
siblingCount | number | 1 | Page buttons shown on each side of the current page. |
pageSize10numberRows per page. Controlled only when onPageSizeChange is also passed.
defaultPageSize10numberStarting rows per page when users can change it.
pageSizeOptions-number[]Shows a "Rows per page" select with these sizes.
onPageSizeChange-(size: number) => voidCalled when the rows-per-page select changes. Makes pageSize controlled.
page-numberCurrent page, starting at 1 (controlled).
defaultPage1numberStarting page (uncontrolled).
onPageChange-(page: number) => voidCalled with the new page.
totalRows-numberServer-side mode: data is already the current page and totalRows is the size of the whole set.
siblingCount1numberPage buttons shown on each side of the current page.
<TableColumn />
The shape of each item in columns.
| Prop | Type | Default | Description |
|---|---|---|---|
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' | 'center' | 'right' | 'left' | Text alignment for header and cells. |
width | string | number | - | Column width. |
key*-stringUnique column id and the default property to read.
header*-ReactNodeHeader cell content.
render-(row, index) => ReactNodeCustom cell renderer.
align'left''left' | 'center' | 'right'Text alignment for header and cells.
width-string | numberColumn 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.