Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Data table

Searchable, sortable client table with pagination, a loading skeleton and row arrows.

10 clients
Atelier Morel Paris 6 €27,100
Maison Duval Lille 5 €21,900
Brightwell Legal Lyon 4 €18,400
Harbor Dental Bordeaux 3 €12,800
1-4 of 10
1 / 3

Installation

pnpm add @heyramzi/ui

Usage

import {
  Pagination,
  RowArrow,
  SortableHead,
  TableSkeleton,
  formatCount,
  normalizeQuery,
  anyContainsQuery,
  paginateRows,
  sortRows,
  toggleSort,
  type SortState,
} from "@heyramzi/ui/components/data-table";
<table>
  <thead>
    <tr>
      <SortableHead key="name" {sort} onSort={(key) => (sort = toggleSort(sort, key))}>Client</SortableHead>
      <SortableHead key="revenue" {sort} onSort={(key) => (sort = toggleSort(sort, key))} numeric>Revenue</SortableHead>
    </tr>
  </thead>
  <tbody>
    {#each paginateRows(sortRows(clients, sort), page, pageSize) as row (row.id)}
      <tr><td>{row.name}</td><td>{row.revenue}</td></tr>
    {/each}
  </tbody>
</table>
<Pagination {page} {pageSize} total={clients.length} onPageChange={(p) => (page = p)} />

Keyboard and accessibility

Key Does
Tab Moves focus to the next column's sort button, then into the rows.
Space Enter On a sort button, sorts by that column. Pressing again flips the order.
Shift F10 ContextMenu On a row in a RowContextMenu, or anything focused inside it, opens the row menu.
  • A sortable head holds a real button, and the head reports ascending or descending to a screen reader.
  • The pager's previous and next buttons are named by previousLabel and nextLabel.
  • The row menu also opens on right-click or a long press. Give the row a link or button so the keyboard can reach it.

API reference

SortableHead

key required keyof T & string
sort required SortState<T>
onSort required (key: keyof T & string) => void
Called on click and on Enter/Space. Choosing the next direction is the caller's.
numeric boolean
Default false
Numbers right-align to their digits, so their caret leads the label.
title string
The long form of an abbreviated head, as the browser tooltip.
class string
style string
children required Snippet
Prop Type Default
key required keyof T & string
sort required SortState<T>
onSort required

Called on click and on Enter/Space. Choosing the next direction is the caller's.

(key: keyof T & string) => void
numeric

Numbers right-align to their digits, so their caret leads the label.

boolean false
title

The long form of an abbreviated head, as the browser tooltip.

string
class string
style string
children required Snippet

TableSkeleton

rows number
Default 5
Number of skeleton rows to render
columns ColumnDef[]
Column definitions control skeleton widths and alignment
columnCount number
Default 6
Simple mode: just specify column count
rowClass string
Merged onto each row, for a table whose own rows draw a different line.
class string
Prop Type Default
rows

Number of skeleton rows to render

number 5
columns

Column definitions control skeleton widths and alignment

ColumnDef[]
columnCount

Simple mode: just specify column count

number 6
rowClass

Merged onto each row, for a table whose own rows draw a different line.

string
class string

RowArrow

class string
Prop Type Default
class string

Pagination

page required number
pageSize required number
total required number
onPageChange (page: number) => void
buildHref (page: number) => string
If provided, renders <a> tags instead of buttons (for server-side pagination)
previousLabel string
Default "Previous page"
The accessible name of the icon-only previous and next buttons.
nextLabel string
Default "Next page"
Prop Type Default
page required number
pageSize required number
total required number
onPageChange (page: number) => void
buildHref

If provided, renders <a> tags instead of buttons (for server-side pagination)

(page: number) => string
previousLabel

The accessible name of the icon-only previous and next buttons.

string "Previous page"
nextLabel string "Next page"

InfiniteScroll

items required T[]
isDone required boolean
isLoading required boolean
children required Snippet<[{ items: T[] }]>
skeleton Snippet
Skeleton snippet rendered while loading more
onLoadMore required () => void
threshold number
Default 200
loadingClass string
Prop Type Default
items required T[]
isDone required boolean
isLoading required boolean
children required Snippet<[{ items: T[] }]>
skeleton

Skeleton snippet rendered while loading more

Snippet
onLoadMore required () => void
threshold number 200
loadingClass string

RowContextMenu

onDelete required () => void
href string
id string
deleteLabel string
Default "Delete"
copyLinkLabel string
Default "Copy link"
copyIdLabel string
Default "Copy ID"
onCopied () => void
Called after a successful clipboard copy so consumers can show their own toast
children required Snippet<[Record<string, unknown>]>
Prop Type Default
onDelete required () => void
href string
id string
deleteLabel string "Delete"
copyLinkLabel string "Copy link"
copyIdLabel string "Copy ID"
onCopied

Called after a successful clipboard copy so consumers can show their own toast

() => void
children required Snippet<[Record<string, unknown>]>