Data table
A table with sorting, row selection, numeric columns, an empty state and virtual scrolling.
import { DataTable } from "@kashi-ui/react";
Example
Click the “مشتری” (Customer) or “مبلغ” (Amount) column header to sort. Names are sorted in Persian alphabetical order.
| تاریخ | وضعیت | |||
|---|---|---|---|---|
| مریم کریمی | ۱۴۰۵/۰۸/۰۳ | پرداختشده | ۳٬۹۰۰٬۰۰۰ | |
| سارا احمدی | ۱۴۰۵/۰۸/۰۴ | پرداختشده | ۱٬۲۵۰٬۰۰۰ | |
| نگار صادقی | ۱۴۰۵/۰۷/۲۹ | پرداختشده | ۶۲۰٬۰۰۰ | |
| علی رضایی | ۱۴۰۵/۰۸/۰۳ | در انتظار | ۴۸۰٬۰۰۰ | |
| رضا نوری | ۱۴۰۵/۰۸/۰۱ | ناموفق | ۷۵٬۰۰۰ |
هیچ ردیفی انتخاب نشده
<DataTable
caption="تراکنشهای اخیر"
description="آخرین پرداختهای مشتریان در این ماه"
rows={transactions}
getRowId={(r) => r.id}
selectable
selected={selected}
onSelectedChange={setSelected}
defaultSort={{ key: "amount", direction: "descending" }}
columns={[
{ key: "customer", header: "مشتری", sortable: true },
{ key: "date", header: "تاریخ" },
{ key: "status", header: "وضعیت", render: (r) => <Badge tone="success" dot>…</Badge> },
{ key: "amount", header: "مبلغ (تومان)", sortable: true, numeric: true,
render: (r) => formatNumber(r.amount) },
]}
/>Loading, stripes, sticky header and pagination
Click “بارگذاری دوباره” (Reload) to see the skeleton rows, and click any row to see the click event. Scroll the table: the header stays in place.
| تاریخ | وضعیت | ||
|---|---|---|---|
| سارا احمدی | ۱۴۰۵/۰۸/۰۴ | پرداختشده | ۱٬۲۵۰٬۰۰۰ |
| علی رضایی | ۱۴۰۵/۰۸/۰۳ | در انتظار | ۴۸۰٬۰۰۰ |
| مریم کریمی | ۱۴۰۵/۰۸/۰۳ | پرداختشده | ۳٬۹۰۰٬۰۰۰ |
| رضا نوری | ۱۴۰۵/۰۸/۰۱ | ناموفق | ۷۵٬۰۰ ۰ |
| نگار صادقی | ۱۴۰۵/۰۷/۲۹ | پرداختشده | ۶۲۰٬۰۰۰ |
<DataTable
…
striped
stickyHeader
maxHeight="16rem"
loading={isLoading ? 4 : false}
onRowClick={(row) => open(row)}
columns={[
{ key: "date", header: "تاریخ", hideBelow: "sm" },
{ key: "status", header: "وضعیت", align: "center" },
…
]}
footer={<Pagination page={page} total={8} onChange={setPage} />}
/>| Name | Description, type and default |
|---|---|
striped | Striped rows |
stickyHeader / maxHeight | Header stays fixed while scrolling |
loading | Skeleton rows; a number sets the row count |
onRowClick | Row click (clicks on buttons and links inside the row are not handled) |
footer | Content below the table |
align / hideBelow / className (column) | Alignment, hiding on mobile, class for the cells |
classNames | Custom class for each part |
CSS variables: --k-table-radius, --k-table-cell-px, --k-table-cell-py, --k-table-header-bg, --k-table-stripe, --k-table-row-hover.
Tens of thousands of rows with virtual scrolling
With virtual, only the rows in view are rendered, plus a few above and below. Ten thousand or a hundred thousand rows scroll as smoothly as twenty. Sorting, selection and the sticky header work as before, and screen readers announce the total and each row’s position through aria-rowcount and aria-rowindex.
| سفارش | |||
|---|---|---|---|
| #۱۴۰۵۰۰۰۰ | سارا محمدی | تهران | ۱۲۰٬۰۰۰ |
| #۱۴۰۵۰۰۰۷ | علی رضایی | اصفهان | ۸٬۰۳۹٬۰۰۰ |
| #۱۴۰۵۰۰۱۴ | مریم کریمی | شیراز | ۶٬۹۵۸٬۰۰۰ |
| #۱۴۰۵۰۰۲۱ | حسین احمدی | تبریز | ۵٬۸۷۷٬۰۰۰ |
| #۱۴۰۵۰۰۲۸ | نگار حسینی | مشهد | ۴٬۷۹۶٬۰۰۰ |
| #۱۴۰۵۰۰۳۵ | رضا موسوی | کاشان | ۳٬۷۱۵٬۰۰۰ |
| #۱۴۰۵۰۰۴۲ | سارا محمدی | تهران | ۲٬۶۳۴٬۰۰۰ |
| #۱۴۰۵۰۰۴۹ | علی رضایی | اصفهان | ۱٬۵۵۳٬۰۰۰ |
| #۱۴۰۵۰۰۵۶ | مریم کریمی | شیراز | ۴۷۲٬۰۰۰ |
| #۱۴۰۵۰۰۶۳ | حسین احمدی | تبریز | ۸٬۳۹۱٬۰۰۰ |
| #۱۴۰۵۰۰۷۰ | نگار حسینی | مشهد | ۷٬۳۱۰٬۰۰۰ |
| #۱۴۰۵۰۰۷۷ | رضا موسوی | کاشان | ۶٬۲۲۹٬۰۰۰ |
| #۱۴۰۵۰۰۸۴ | سارا محمدی | تهران | ۵٬۱۴۸٬۰۰۰ |
| #۱۴۰۵۰۰۹۱ | علی رضایی | اصفهان | ۴٬۰۶۷٬۰۰۰ |
| #۱۴۰۵۰۰۹۸ | مریم کریمی | شیراز | ۲٬۹۸۶٬۰۰۰ |
| #۱۴۰۵۰۱۰۵ | حسین احمدی | تبریز | ۱٬۹۰۵٬۰۰۰ |
| #۱۴۰۵۰۱۱۲ | نگار حسینی | مشهد | ۸۲۴٬۰۰۰ |
| #۱۴۰۵۰۱۱۹ | رضا موسوی | کاشان | ۸٬۷۴۳٬۰۰۰ |
| #۱۴۰۵۰۱۲۶ | سارا محمدی | تهران | ۷٬۶۶۲٬۰۰۰ |
| #۱۴۰۵۰۱۳۳ | علی رضایی | اصفهان | ۶٬۵۸۱٬۰۰۰ |
| #۱۴۰۵۰۱۴۰ | مریم کریمی | شیراز | ۵٬۵۰۰٬۰۰۰ |
| #۱۴۰۵۰۱۴۷ | حسین احمدی | تبریز | ۴٬۴۱۹٬۰۰۰ |
| #۱۴۰۵۰۱۵۴ | نگار حسینی | مشهد | ۳٬۳۳۸٬۰۰۰ |
| #۱۴۰۵۰۱۶۱ | رضا موسوی | کاشان | ۲٬۲۵۷٬۰۰۰ |
| #۱۴۰۵۰۱۶۸ | سارا محمدی | تهران | ۱٬۱۷۶٬۰۰۰ |
| #۱۴۰۵۰۱۷۵ | علی رضایی | اصفهان | ۹٬۰۹۵٬۰۰۰ |
| #۱۴۰۵۰۱۸۲ | مریم کریمی | شیراز | ۸٬۰۱۴٬۰۰۰ |
<DataTable
caption="۱۰٬۰۰۰ سفارش"
rows={orders}
getRowId={(r) => r.id}
columns={columns}
virtual
maxHeight="22rem"
/>- The table height comes from
maxHeight(default 28rem). - Rows must have equal height. The real row height is measured automatically; if your rows have a fixed height, pass it with
virtual={{ rowHeight: 48 }}. - Rows that are not rendered cannot be found with the browser’s search (Ctrl+F). If users need to search all rows, put a search field above the table.
- For data that arrives from the server page by page, pagination is usually simpler.
Props
| Name | Description, type and default |
|---|---|
virtual | Virtual scrolling for thousands of rows; overscan is the number of extra rows above and below (default 6) |
columns | Columns: key, header, render, sortable, sortValue, numeric, width |
rows | Rows |
getRowId | Unique ID of each row |
caption | Table title; required, for screen readers |
description / hideCaption | Description under the title / visually hide the title |
selectable | Selection column with a "select all" checkbox |
selected / onSelectedChange | Selected rows |
sort / defaultSort / onSortChange | Sorting; controlled mode for server-side sorting |
empty | Content for an empty table, for example an EmptyState |
compact | Compact rows |
Accessibility
- A real HTML table with a
<caption>andscope="col"headers, so screen readers can move between cells. - The sorted header has
aria-sort, and sorting is done with a real button. - Each row’s checkbox gets its own name (
labels.selectRow), such as “انتخاب تراکنش سارا احمدی” (Select transaction Sara Ahmadi). - On narrow screens the table container scrolls horizontally and can be scrolled with the keyboard (Tab).