Skip to content

Display

Table

SimpleTable styles plain table markup with a sticky header, hover rows and an optional card layout in narrow containers.

<script>
  import { SimpleTable } from "@codeatlasdev/ui";
</script>

<SimpleTable responsive="cards">
  <thead>…</thead>
  <tbody>…</tbody>
</SimpleTable>

SimpleTable styles plain thead and tbody markup inside a focusable, horizontally scrolling region. For search, sorting and pagination use DataTable. It is exported from @codeatlasdev/ui. @codeatlasdev/ui/table also exports a Table, a bordered wrapper around a plain <table> that forwards native table attributes.

#139

Default (scroll)

A regular table at every width.

NameEmailRoleStatus
Ana Souza[email protected]AdminActive
Bruno Lima[email protected]EditorInvited
Carla Dias[email protected]ViewerActive

Reference #139 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { SimpleTable, Card } from '@codeatlasdev/ui';

  const rows = [
    { name: 'Ana Souza', email: '[email protected]', role: 'Admin', status: 'Active' },
    { name: 'Bruno Lima', email: '[email protected]', role: 'Editor', status: 'Invited' },
    { name: 'Carla Dias', email: '[email protected]', role: 'Viewer', status: 'Active' },
  ];
</script>

<Card flush full>
  <SimpleTable>
    <thead>
      <tr><th>Name</th><th>Email</th><th>Role</th><th>Status</th></tr>
    </thead>
    <tbody>
      {#each rows as r}
        <tr>
          <td class="primary">{r.name}</td>
          <td>{r.email}</td>
          <td>{r.role}</td>
          <td>{r.status}</td>
        </tr>
      {/each}
    </tbody>
  </SimpleTable>
</Card>
#138

Cards on narrow containers

When the table's own container is narrower than 600px each row becomes a card. Every cell is captioned with its column header; `data-label` only overrides that. Resize the window to see it.

NameEmailRoleStatus
Ana Souza[email protected]AdminActive
Bruno Lima[email protected]EditorInvited
Carla Dias[email protected]ViewerActive

Reference #138 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { SimpleTable, Card } from '@codeatlasdev/ui';

  const rows = [
    { name: 'Ana Souza', email: '[email protected]', role: 'Admin', status: 'Active' },
    { name: 'Bruno Lima', email: '[email protected]', role: 'Editor', status: 'Invited' },
    { name: 'Carla Dias', email: '[email protected]', role: 'Viewer', status: 'Active' },
  ];
</script>

<Card flush full>
  <SimpleTable responsive="cards">
    <thead>
      <tr><th>Name</th><th>Email</th><th>Role</th><th>Status</th></tr>
    </thead>
    <tbody>
      {#each rows as r}
        <tr>
          <td class="primary" data-label="Name">{r.name}</td>
          <td data-label="Email">{r.email}</td>
          <td data-label="Role">{r.role}</td>
          <td data-label="Status">{r.status}</td>
        </tr>
      {/each}
    </tbody>
  </SimpleTable>
</Card>
#491

Dense, pinned and grouped

`density="compact"`, `frame={false}`, `scroll="none"` and `stickyColumns={2}` inside a panel that owns the scrolling, with collapsible group rows, a sortable header and interactive rows. Scroll the panel sideways: the checkbox and name columns stay put.

CompanyOwnerStageValue
Ana Souza Atlas Co Matheus New $12,000.00
Bruno Lima Nimbus Carla New $8,400.00
Carla Dias Orbit Diego Won $22,000.00
Diego Reis Vertex Matheus Won $5,600.00

Nothing opened yet

Reference #491 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { SimpleTable, TableRow, TableGroupRow, TableSortHeader, Checkbox } from '@codeatlasdev/ui';

  type Lead = { id: string; name: string; company: string; owner: string; value: number; stage: string };
  const leads: Lead[] = [
    { id: 'l1', name: 'Ana Souza', company: 'Atlas Co', owner: 'Matheus', value: 12000, stage: 'New' },
    { id: 'l2', name: 'Bruno Lima', company: 'Nimbus', owner: 'Carla', value: 8400, stage: 'New' },
    { id: 'l3', name: 'Carla Dias', company: 'Orbit', owner: 'Diego', value: 22000, stage: 'Won' },
    { id: 'l4', name: 'Diego Reis', company: 'Vertex', owner: 'Matheus', value: 5600, stage: 'Won' },
  ];

  let sort = $state<'none' | 'asc' | 'desc'>('none');
  let selected = $state<string | undefined>('l2');
  let opened = $state<Record<string, boolean>>({ New: true, Won: true });
  let last = $state('Nothing opened yet');

  const sorted = $derived(
    sort === 'none' ? leads : [...leads].sort((a, b) => (sort === 'asc' ? 1 : -1) * a.name.localeCompare(b.name)),
  );
  const stages = $derived([...new Set(sorted.map((l) => l.stage))]);
  const cycle = () => (sort = sort === 'none' ? 'asc' : sort === 'asc' ? 'desc' : 'none');
</script>

<div class="dense-demo">
  <div class="dense-demo__scroller">
    <SimpleTable density="compact" frame={false} scroll="none" stickyColumns={2} headerCase="sentence">
      <thead>
        <tr>
          <th scope="col"><Checkbox aria-label="Select all leads" /></th>
          <TableSortHeader {sort} onsort={cycle}>Name</TableSortHeader>
          <th scope="col">Company</th>
          <th scope="col">Owner</th>
          <th scope="col">Stage</th>
          <th scope="col">Value</th>
        </tr>
      </thead>
      {#each stages as stage (stage)}
        <tbody>
          <TableGroupRow colspan={6} collapsible bind:open={opened[stage]}>
            {#snippet label()}{stage} <span>{sorted.filter((l) => l.stage === stage).length}</span>{/snippet}
          </TableGroupRow>
          {#if opened[stage]}
            {#each sorted.filter((l) => l.stage === stage) as l (l.id)}
              <TableRow selected={selected === l.id} onactivate={() => { selected = l.id; last = `Opened ${l.name}`; }}>
                <td><Checkbox aria-label={`Select ${l.name}`} /></td>
                <td class="primary">{l.name}</td>
                <td>{l.company}</td>
                <td>{l.owner}</td>
                <td>{l.stage}</td>
                <td>{l.value.toLocaleString('en-US', { style: 'currency', currency: 'USD' })}</td>
              </TableRow>
            {/each}
          {/if}
        </tbody>
      {/each}
    </SimpleTable>
  </div>
  <p class="dense-demo__status" aria-live="polite">{last}</p>
</div>

<style>
  .dense-demo { width: 100%; min-width: 0; max-width: 28rem; }
  .dense-demo__scroller {
    width: 100%;
    overflow-x: auto;
    border: var(--ca-border-width) solid var(--ca-outline-subtle);
    border-radius: var(--ca-radius-lg);
  }
  .dense-demo__status { margin: var(--ca-space-2) 0 0; color: var(--ca-text-hint); font-size: var(--ca-font-size-caption); }
</style>

Dense records screens

For a CRM-style list (thousands of rows, ~10 columns) set density="compact" (rows up to 40px), frame={false} when the table sits in a framed panel, and scroll="none" when the page or panel is the scroller so the sticky header keeps working. stickyColumns={n} pins the first n columns (checkbox, primary column); their background follows hover, selected and focus states and is never transparent. headerCase="sentence" drops the uppercase micro labels.

  • TableRow: selected sets aria-selected; onactivate makes the row reachable by Tab and activates it on click, Enter and Space with an inset focus ring. Events from a checkbox, button, link, menu or input inside the row never activate it (add data-row-ignore to any other element that must not).
  • TableGroupRow: a section row that spans colspan columns. With collapsible its label is a button with aria-expanded bound to open; render the group’s rows under {#if open}. The label stays pinned to the left while the table scrolls.
  • TableSortHeader: a sentence-case sortable th with a direction icon. Pass the column’s sort ('none' | 'asc' | 'desc', which sets aria-sort) and an onsort handler; you own the sort state.

Props

PropTypeDefaultDescription
selectedbooleanundefinedSets `aria-selected` and the selected tint; pinned cells stay opaque.
onactivate(event: MouseEvent | KeyboardEvent) => voidundefinedMakes the row interactive (tabindex 0, click, Enter, Space). Nested controls do not trigger it.
childrenSnippetundefinedThe row's `td` cells.

Props

PropTypeDefaultDescription
colspannumberrequiredNumber of columns to span.
collapsiblebooleanfalseRenders the label as a button with `aria-expanded`.
openbooleantrueExpanded state, bindable. Render the group's rows under `{#if open}`.
labelSnippetundefinedGroup title and count.

Props

PropTypeDefaultDescription
sort'none' | 'asc' | 'desc''none'Current direction; sets `aria-sort` on the `th`.
onsort() => voidundefinedCalled when the header button is pressed; you own the next direction.
childrenSnippetundefinedColumn label.

Props

PropTypeDefaultDescription
responsive'scroll' | 'cards''scroll'`scroll` keeps a regular table. `cards` turns each row into a card when the table's own width is below the `sm` breakpoint (600px). Cell captions come from the `thead` headers automatically.
skeletonbooleanfalseLoading placeholder: rows keep their layout but are hidden, so the table has the exact loaded size. Render placeholder rows so the height matches. See Skeleton.
density'default' | 'compact''default'`compact` renders rows of at most 40px.
framebooleantrue`false` drops the table's own border and radius, for a table inside a framed panel.
scroll'x' | 'none''x'`x`: the root is a focusable horizontal scroller. `none`: the root is `overflow: visible` and the caller owns scrolling, so the sticky header sticks to the page or panel.
stickyColumnsnumber0Pins the first N columns (up to 6) to the left, with an opaque background in every row state.
headerCase'upper' | 'sentence''upper'`sentence` renders header labels in regular size and their own case.
classstring''Extra class on the wrapper.
childrenSnippetundefined`thead` and `tbody` markup.