Command palette

@yasinsensoy/web

Web · Components

Table

Data table.

7 exports

Live example

Preview

Recent orders
OrdersStatus
#1027Can ÖztürkPaidOct 9, 2026$980.00
#1026Zeynep DemirPaidOct 4, 2026$250.00
#1025Mehmet KayaPendingOct 3, 2026$1,420.00
#1024Ayşe YılmazPaidOct 1, 2026$250.00
Total2900

Code

import { TableSort, Table, Badge } from "@yasinsensoy/web";

const [sort, setSort] = useState<TableSort | null>(null);

<Table
  label="Orders"
  rows={orders}
  caption="Recent
  orders"
  sort={sort}
  onSortChange={setSort}
  columns={[
    { key: "id", header: "Order" },
    { key: "customer", header: "Customer", sortable: true },
    { key: "paid", header: "Status", render: (s) => <Badge tone={s.paid ? "success" : "warning"}>…</Badge> },
    { key: "date", header: "Date", format: "date", hideOnMobile: true },
    { key: "total", header: "Amount", tooltip: "VAT included, shipping excluded", format: "currency", sortable: true },
  ]}
  footer={{ customer: "Toplam", total: total }}
/>

Events

  1. Events appear here when you interact with the preview.

Import

import { Table } from "@yasinsensoy/web";

Table

componentServer component

Data table. Columns are given with columns, rows with rows; the header, cells, mobile card view, formatting and sorting come built in.

It is a server component: functions like render can be passed from the server too. Only the scrollbar part goes to the browser.

  • Overflowing tables scroll horizontally in their own container; the page doesn't overflow.
  • On phones each row turns into a card (stackOnMobile), with the column name before each value.
  • With format, numbers, currency, percentages and dates are formatted by locale; numbers are right-aligned and line up with tabular-nums.
  • For sorting give sort + onSortChange (in a client component).
  • For pagination give pagination; if you give all rows the table slices the current page itself after sorting. In a server component pages become links with pagination={{ searchParams }}.
Table({ columns, rows, rowKey, caption, empty: emptyProp, footer, stackOnMobile, stickyHeader, label, sort, onSortChange, onRowClick, selectedKey, locale: localeProp, currency: currencyProp, pagination, classNames, className, ...props }: TableProps<T>): JSX.Element

Examples

<Table
  label="Orders"
  rows={orders}
  columns={[
    { key: "no", header: "Order" },
    { key: "customer", header: "Customer", render: (o) => <b>{o.customer}</b> },
    { key: "status", header: "Status", render: (o) => <Badge tone="success">{o.status}</Badge> },
    { key: "amount", header: "Amount", format: "currency", sortable: true },
    { key: "date", header: "Date", format: "date", hideOnMobile: true },
  ]}
  footer={{ no: "Total", amount: "$1,250.00" }}
  sort={sort}
  onSortChange={setSort}
/>

Built-in formats of a cell value. Numbers are formatted by locale.

type TableFormat = "number" | "currency" | "percent" | "date" | "datetime"

TableColumn

interface

Column of Table.

NameTypeDescription
keystringId of the column; if value is omitted, the value of this field in the row is shown.
headerReactNodeHeader cell.
tooltip?TooltipPropTooltip shown with an ⓘ icon next to the header (e.g. how the column is computed). See TooltipProp.
mobileLabel?stringName written before the value in the mobile card view. If omitted and header is text, that is used.
value?(row: T) => unknownProduces the cell value from the row (sorting and formatting use it too).
render?(row: T, index: number) => ReactNodeFully customizes the cell content (e.g. a badge, a button).
format?TableFormatBuilt-in format: number, currency, percent (0.25 → 25%), date.
align?"start" | "center" | "end"Alignment. Numeric formats default to "end".
sortable?booleanClicking the header can sort by this column. See TableProps.sort.
width?stringColumn width (CSS), e.g. "8rem" or "20%".
hideOnMobile?booleanHidden in the mobile card view.
className?stringClasses added to this column's cells.

TableSort

interface

Sort state.

NameTypeDescription
keystringkey of the sorted column.
direction"asc" | "desc"Direction.

Classes that can be passed to the inner parts of Table.

NameTypeDescription
container?stringScroll container.
header?stringHeader row.
row?stringEach data row.
footer?stringFooter (totals) row.
wrapper?stringContainer wrapping the table and pagination (when pagination is given).

The Table pagination prop: same as PaginationProps.

  • If total (or pageCount) is not given, rows counts as all records; the table slices the current page itself after sorting.
  • If total is given, rows is only the current page (server pagination).

Since the table is a server component it doesn't keep page state: give the page either with page + onPageChange (in a client component) or linked via searchParams (in a server component).

type TablePagination = PaginationProps

TableProps

interface

Props of the Table component.

Extends: Omit<ComponentProps<"table">, "children">

NameTypeDefaultDescription
columnsreadonly TableColumn<T>[]Columns.
rowsreadonly T[]Rows.
rowKey?keyof T | ((row: T, index: number) => string | number)Unique key of a row: a field name or a function. If omitted, the id field, otherwise the index is used.
caption?ReactNodeCaption below the table; screen readers announce the table with it.
empty?ReactNodeContent shown when there are no rows. Defaults to the tableEmpty text ("Kayıt yok").
footer?Partial<Record<string, ReactNode>>Footer row content by column key (e.g. totals).
stackOnMobile?booleantrueOn small screens (below 640 px) turns each row into a card; the column name is written before each value. If false the table scrolls horizontally.
stickyHeader?booleanThe header row stays fixed at the top on vertical scroll. Give a height (e.g. max-h-96) with classNames.container.
label?stringScreen reader name of the scroll container; if given, it can be scrolled with the keyboard.
sort?TableSort | nullSorting. If given, rows are sorted by it and sortable column headers become clickable; you keep the state with onSortChange.
onSortChange?(sort: TableSort | null) => voidCalled with the new sort when a sortable header is clicked.
onRowClick?(row: T, index: number) => voidMakes rows clickable (e.g. go to details).
selectedKey?string | number | nullThe row with this key looks selected.
locale?stringLocale used for formatting. Defaults to the UIProvider's locale in a client tree, "tr-TR" on the server.
currency?stringCurrency. Defaults to the UIProvider's currency in a client tree, "TRY" on the server.
pagination?TablePaginationPagination below the table. See TablePagination.
classNames?TableClassNamesClasses added to the inner parts.