Skip to content
Klarhimmel UI

Data table

App, data table previewApp, data table preview

Install

npx shadcn add @klarhimmel/app-data-table
DetailsAbout, usage, props and more

A data table: sort buttons that order by what a column holds (text, numbers, dates; aria-sort), a first column that stays in view while the rest scrolls with an edge…

States

data table in 6 forms: filled, empty, loading, error, compact rows, row selection.

  • state: filled

    Name the section

    Name the table

    Say what each row stands for and tell people they can click a column to sort.

    Name the table and how to sort it
    Person oneName an item12 Jun3$00
    Person twoName an item13 Jun2$00
    Person threeName an item13 Jun5$00
    Person fourName an item15 Jun1$00
    Person fiveName an item16 Jun4$00
  • state: empty

    Name the section

    Name the table

    Say what each row stands for and tell people they can click a column to sort.

    Name the table and how to sort it

    Say there is nothing to show yet

    Say what the first row will be and what makes it appear here.

  • state: loading

    Name the section

    Name the table

    Say what each row stands for and tell people they can click a column to sort.

    Name the table and how to sort it

    Say it is loading

  • state: error

    Name the section

    Name the table

    Say what each row stands for and tell people they can click a column to sort.

    Name the table and how to sort it
  • compact rows

    Name the section

    Name the table

    Say what each row stands for and tell people they can click a column to sort.

    Name the table and how to sort it
    Person oneName an item12 Jun3$00
    Person twoName an item13 Jun2$00
    Person threeName an item13 Jun5$00
    Person fourName an item15 Jun1$00
    Person fiveName an item16 Jun4$00
  • row selection

    Name the section

    Name the table

    Say what each row stands for and tell people they can click a column to sort.

    selected

    Name the table and how to sort it
    Person oneName an item12 Jun3$00
    Person twoName an item13 Jun2$00
    Person threeName an item13 Jun5$00
    Person fourName an item15 Jun1$00
    Person fiveName an item16 Jun4$00

Notes

When to use it

A sortable table of records with optional row selection and bulk actions. For a handful of invoices use app-billing-invoices; for a table where nothing is sorted a simple comparison block is lighter.

Writing for it

- Each column needs a kind of text, number or date, and sorting follows it, so 800 kr comes before 12 000 kr. Set locale (10), such as sv, for the alphabet. - Add keys to a row (30 characters each) when the shown text cannot sort, for example an ISO date behind a text date. They win over the displayed cell. - The first cell in every row is its row header, so put the name there. Rows allow 2 to 6 cells and up to 10 rows.

Watch out for

Turning on selectable adds a checkbox column and a bulk action bar of at most 3 actions that appears only once something is picked. The selection exists only in the block, and selecting works only in the filled state.

Usage

The block in a page, with its default content (long lists shortened). Every prop is in the table below.

section.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { BlockSurface } from '@/components/klarhimmel/blocks/surface';
import AppDataTable, { spec } from '@/components/klarhimmel/blocks/app-data-table';

export default function Section() {
  return (
    <Theme theme="brand">
      <BlockSurface>
        <AppDataTable props={spec.defaults} />
      </BlockSurface>
    </Theme>
  );
}

Props

The type, default and text limit of every prop. On a real page, over-limit text is kept and checkSections flags it (Installation, Check a page before you ship); this live preview shows the default until it fits. The panel above edits all props.

PropTypeDefaultDescription
eyebrowstring'Name the section'Text, up to 60 characters. Optional; empty is not rendered.
titlestring'Name the table'Text, up to 120 characters.
descriptionstring'Say what each row stands for and te…'Text, up to 300 characters. Optional; empty is not rendered.
captionstring'Name the table and how to sort it'Text, up to 80 characters.
columns{ label, align, sortable, kind }[]5 itemsList of 2 to 6. Each item: label, align ('left' | 'right'), sortable, kind ('text' | 'number' | 'date').
rows{ cells, keys }[]5 itemsList of 1 to 10. Each item: cells, keys (optional).
localestring'sv'Text, up to 10 characters.
density'comfortable' | 'compact''comfortable'One of 'comfortable', 'compact'.
selectablebooleanfalseSee the type.
select{ row, all, selected, clear, barLabel, actions }{…}Fields: row, all, selected, clear, barLabel, actions.
scrollHintstring'Say there are more columns'Text, up to 40 characters.
sort{ active, direction }{…}Fields: active, direction ('ascending' | 'descending').
state'filled' | 'empty' | 'loading' | 'error''filled'One of 'filled', 'empty', 'loading', 'error'.
messages{ loading, emptyTitle, emptyBody, emptyAction, errorTitle, errorBody, retry }{…}Fields: loading, emptyTitle, emptyBody, emptyAction, errorTitle, errorBody, retry.
headingLevel'1' | '2'-One of '1', '2'. Optional; empty is not rendered.

Install

Installs

app-data-table
Uses
  • Banner
  • Button
  • EmptyState
  • Skeleton
About
A data table: sort buttons that order by what a column holds (text, numbers, dates; aria-sort), a first column that stays in view while the rest scrolls with an edge fade, comfortable or compact rows, optional row selection with select…
States
Filled, empty, loading and error. Headers sort in place and carry aria-sort; the region scrolls sideways on a phone. New project? Set it up once: /get-started/installation.