Skip to content

منو

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} />}
    />
    New props
    NameDescription, type and default
    striped

    Striped rows

    Type: booleanDefault false

    stickyHeader / maxHeight

    Header stays fixed while scrolling

    Type: boolean / string

    loading

    Skeleton rows; a number sets the row count

    Type: booleannumberDefault false

    onRowClick

    Row click (clicks on buttons and links inside the row are not handled)

    Type: (row) => void

    footer

    Content below the table

    Type: ReactNode

    align / hideBelow / className (column)

    Alignment, hiding on mobile, class for the cells

    classNames

    Custom class for each part

    Type: { root, table, row, cell, header, footer }

    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

    Props
    NameDescription, type and default
    virtual

    Virtual scrolling for thousands of rows; overscan is the number of extra rows above and below (default 6)

    Type: boolean{ rowHeight?: number; overscan?: number }Default false

    columns

    Columns: key, header, render, sortable, sortValue, numeric, width

    Type: Column[]

    rows

    Rows

    Type: T[]

    getRowId

    Unique ID of each row

    Type: (row) => string

    caption

    Table title; required, for screen readers

    Type: ReactNode

    description / hideCaption

    Description under the title / visually hide the title

    Type: ReactNode / boolean

    selectable

    Selection column with a "select all" checkbox

    Type: booleanDefault false

    selected / onSelectedChange

    Selected rows

    Type: string[]

    sort / defaultSort / onSortChange

    Sorting; controlled mode for server-side sorting

    Type: { key, direction }null

    empty

    Content for an empty table, for example an EmptyState

    Type: ReactNode

    compact

    Compact rows

    Type: booleanDefault false

    Accessibility

    • A real HTML table with a <caption> and scope="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).