Ir al contenido

Table

Filas del mismo tipo de cosa, alineadas en columnas para compararlas. En el celular cada fila se vuelve una tarjeta: la primera columna es el título de la tarjeta y cada otro valor lleva el nombre de su columna, así nada se desplaza de lado. Cuando hay más filas de las que caben en una página, tiene páginas.

import { Table, TableSkeleton } from '@sypnia/ui/react'

En esta página
  1. Ordenar
  2. Páginas: 60 filas, de 10 en 10
  3. Cargando
  4. Algo falló
  5. Vacía, con el paso siguiente
  6. Acciones en cada fila
  7. Skeleton
  8. Cuándo usarlo
  9. Para todos
  10. Props

Ordenar

Presiona «Customer» o «Total». Los números y las fechas se escriben en el idioma de la página.

1042Laura MéndezPaid16 nov 2026128,40 US$
1041Diego RuizPending16 nov 202642,00 US$
1040Ana CastañoPaid15 nov 2026310,95 US$
1039Marco SilvaRefunded14 nov 202618,50 US$
1038Julia PrietoPaid12 nov 202696,00 US$
Código
import { Badge, Table, useSypnia, type Column } from '@sypnia/ui/react';

interface Order { id: string; customer: string; total: number; status: 'Paid' | 'Pending' | 'Refunded'; placed: string }
const orders: Order[] = [
  { id: '1042', customer: 'Laura Méndez', total: 128.4, status: 'Paid', placed: '2026-11-16' },
  { id: '1041', customer: 'Diego Ruiz', total: 42, status: 'Pending', placed: '2026-11-16' },
  { id: '1040', customer: 'Ana Castaño', total: 310.95, status: 'Paid', placed: '2026-11-15' },
  { id: '1039', customer: 'Marco Silva', total: 18.5, status: 'Refunded', placed: '2026-11-14' },
  { id: '1038', customer: 'Julia Prieto', total: 96, status: 'Paid', placed: '2026-11-12' },
];
const tone = { Paid: 'ok', Pending: 'warn', Refunded: 'fail' } as const;

// Press a column name to sort: once ascending, twice descending, three times back to the original order.
export default function Basic() {
  const { format } = useSypnia();
  const columns: Column<Order>[] = [
    { id: 'id', header: 'Order', cell: (o) => o.id, sortValue: (o) => o.id },
    { id: 'customer', header: 'Customer', cell: (o) => o.customer, sortValue: (o) => o.customer },
    { id: 'status', header: 'Status', cell: (o) => <Badge tone={tone[o.status]} dot>{o.status}</Badge>, sortValue: (o) => o.status },
    { id: 'placed', header: 'Placed', cell: (o) => format.date(o.placed), sortValue: (o) => o.placed },
    { id: 'total', header: 'Total', numeric: true, cell: (o) => format.currency(o.total, 'USD'), sortValue: (o) => o.total },
  ];
  return <Table label="Orders" columns={columns} rows={orders} rowKey={(o) => o.id} />;
}

Páginas: 60 filas, de 10 en 10

La barra debajo de las filas dice cuáles están en pantalla y deja elegir cuántas por página.

Status
1042Laura MéndezPaid12,00 US$
1041Iván PeñaPaid49,13 US$
1040Julia PrietoPaid86,26 US$
1039Diego RuizRefunded123,39 US$
1038Clara OssaPending160,52 US$
1037Tomás VeraPaid197,65 US$
1036Ana CastañoPaid234,78 US$
1035Felipe ReyPaid271,91 US$
1034Sara LozanoRefunded18,04 US$
1033Marco SilvaPending55,17 US$
1–10 de 60
Código
import { Badge, Table, useSypnia, type Column } from '@sypnia/ui/react';

const names = ['Laura Méndez', 'Diego Ruiz', 'Ana Castaño', 'Marco Silva', 'Julia Prieto', 'Tomás Vera', 'Sara Lozano', 'Iván Peña', 'Clara Ossa', 'Felipe Rey'];
const states = ['Paid', 'Paid', 'Pending', 'Paid', 'Refunded'] as const;
const tone = { Paid: 'ok', Pending: 'warn', Refunded: 'fail' } as const;
// 60 orders, made up but always the same.
const orders = Array.from({ length: 60 }, (_, i) => ({
  id: String(1042 - i), customer: names[(i * 7) % names.length], status: states[(i * 3) % states.length], total: 12 + ((i * 37) % 290) + ((i * 13) % 100) / 100,
}));
type Order = (typeof orders)[number];

// With pageSize the table paginates by itself. Sorting sorts all 60 rows, not only the ones in view.
export default function Paginated() {
  const { format } = useSypnia();
  const columns: Column<Order>[] = [
    { id: 'id', header: 'Order', cell: (o) => o.id, sortValue: (o) => Number(o.id) },
    { id: 'customer', header: 'Customer', cell: (o) => o.customer, sortValue: (o) => o.customer },
    { id: 'status', header: 'Status', cell: (o) => <Badge tone={tone[o.status]} dot>{o.status}</Badge> },
    { id: 'total', header: 'Total', numeric: true, cell: (o) => format.currency(o.total, 'USD'), sortValue: (o) => o.total },
  ];
  return <Table label="Orders" columns={columns} rows={orders} rowKey={(o) => o.id} pageSize={10} />;
}

Cargando

Tantas filas de skeleton como van a llegar, con las columnas reales y cada celda del tamaño de su valor, durante unos dos segundos. Presiona «Load again» para verlo otra vez.

Team
NameEmailRole
Código
import { useEffect, useState } from 'react';
import { Badge, Button, SkeletonOf, SkeletonWords, Table, type Column } from '@sypnia/ui/react';

interface Member { name: string; email: string; role: string }
const team: Member[] = [
  { name: 'Laura Méndez', email: 'laura@northwind.io', role: 'Owner' },
  { name: 'Diego Ruiz', email: 'diego@northwind.io', role: 'Editor' },
  { name: 'Ana Castaño', email: 'ana@northwind.io', role: 'Viewer' },
];
// Each column says what its cells look like while loading: a typical value as SkeletonWords, the real Badge as SkeletonOf.
const columns: Column<Member>[] = [
  { id: 'name', header: 'Name', cell: (m) => m.name, skeleton: (i) => <SkeletonWords>{['Laura Méndez', 'Diego Ruiz', 'Ana Castaño'][i % 3]}</SkeletonWords> },
  { id: 'email', header: 'Email', cell: (m) => m.email, skeleton: <SkeletonWords>diego@northwind.io</SkeletonWords> },
  { id: 'role', header: 'Role', cell: (m) => <Badge>{m.role}</Badge>, skeleton: <SkeletonOf><Badge>Editor</Badge></SkeletonOf> },
];

// While the rows are on their way, the table draws as many skeleton rows as will come (loadingRows: the count of the last
// visit, a known total) with its real columns, each cell the size of its value. Press «Load again»: nothing moves.
export default function Loading() {
  const [rows, setRows] = useState<Member[]>();
  useEffect(() => { if (!rows) { const t = setTimeout(() => setRows(team), 2500); return () => clearTimeout(t); } }, [rows]);
  return (
    <Table label="Team members" columns={columns} rows={rows} rowKey={(m) => m.email} loading={!rows} loadingRows={team.length}
      toolbar={<><span className="sy-text--sm sy-text--strong">Team</span><Button size="sm" disabled={!rows} onClick={() => setRows(undefined)}>Load again</Button></>} />
  );
}

Algo falló

Qué pasó, con palabras, y «Try again». Presiónalo.

Código
import { useState } from 'react';
import { Table, type Column } from '@sypnia/ui/react';

interface Invoice { id: string; month: string; amount: string }
const invoices: Invoice[] = [
  { id: 'INV-0011', month: 'November 2026', amount: 'US$ 49.00' },
  { id: 'INV-0010', month: 'October 2026', amount: 'US$ 49.00' },
];
const columns: Column<Invoice>[] = [
  { id: 'id', header: 'Invoice', cell: (i) => i.id },
  { id: 'month', header: 'Month', cell: (i) => i.month },
  { id: 'amount', header: 'Amount', numeric: true, cell: (i) => i.amount },
];

// The error takes the place of the rows and offers to try again. Press it: skeleton first, then the rows.
export default function Failed() {
  const [state, setState] = useState<'failed' | 'loading' | 'ready'>('failed');
  const retry = () => { setState('loading'); setTimeout(() => setState('ready'), 1800); };
  return (
    <Table label="Invoices" columns={columns} rowKey={(i) => i.id}
      rows={state === 'ready' ? invoices : undefined} loading={state === 'loading'}
      error={state === 'failed' ? 'The invoices could not be loaded. The billing service did not answer.' : undefined} onRetry={retry} />
  );
}

Vacía, con el paso siguiente

Qué va aquí y el botón que agrega lo primero.

No webhooks yet

A webhook tells your server the moment something changes, so it does not have to keep asking.
Código
import { useState } from 'react';
import { Button, EmptyState, Table, type Column } from '@sypnia/ui/react';

interface Hook { url: string; event: string }
const columns: Column<Hook>[] = [
  { id: 'url', header: 'Address', cell: (h) => <span className="sy-machine">{h.url}</span> },
  { id: 'event', header: 'When', cell: (h) => h.event },
];

// An empty table says what goes in it and offers the first step. Press «Add a webhook».
export default function Empty() {
  const [hooks, setHooks] = useState<Hook[]>([]);
  return (
    <Table label="Webhooks" columns={columns} rows={hooks} rowKey={(h) => h.url}
      empty={
        <EmptyState icon="link" title="No webhooks yet"
          actions={<Button variant="primary" icon="plus" onClick={() => setHooks([{ url: 'https://northwind.io/hooks/orders', event: 'An order is paid' }])}>Add a webhook</Button>}>
          A webhook tells your server the moment something changes, so it does not have to keep asking.
        </EmptyState>
      } />
  );
}

Acciones en cada fila

Una acción común como icono, el resto en un menú, y la destructiva detrás de una confirmación.

API keys
KindLast usedActions
Back officeSecretToday
Mobile appPublicToday
Old websitePublicMarch 2
Código
import { useState } from 'react';
import { Badge, Button, ConfirmDialog, IconButton, Menu, MenuItem, Table, toast, Toaster, type Column } from '@sypnia/ui/react';

interface Key { id: string; name: string; kind: 'Secret' | 'Public'; used: string }
const start: Key[] = [
  { id: 'key_1', name: 'Back office', kind: 'Secret', used: 'Today' },
  { id: 'key_2', name: 'Mobile app', kind: 'Public', used: 'Today' },
  { id: 'key_3', name: 'Old website', kind: 'Public', used: 'March 2' },
];

// The last column holds the actions of each row. On a phone they go to the foot of the card.
export default function RowActions() {
  const [keys, setKeys] = useState(start);
  const [doomed, setDoomed] = useState<Key | null>(null);
  const columns: Column<Key>[] = [
    { id: 'name', header: 'Name', cell: (k) => k.name, sortValue: (k) => k.name },
    { id: 'kind', header: 'Kind', cell: (k) => <Badge outline>{k.kind}</Badge> },
    { id: 'used', header: 'Last used', cell: (k) => k.used },
    { id: 'actions', header: 'Actions', actions: true, cell: (k) => (
      <>
        <IconButton icon="copy" label={`Copy the ID of ${k.name}`} onClick={() => { void navigator.clipboard?.writeText(k.id); toast('ID copied'); }} />
        <Menu trigger={<IconButton icon="more" label={`More actions for ${k.name}`} tooltip={false} />}>
          <MenuItem icon="edit" onAction={() => toast(`Rename ${k.name}`, { tone: 'info' })}>Rename</MenuItem>
          <MenuItem icon="trash" danger onAction={() => setDoomed(k)}>Revoke key</MenuItem>
        </Menu>
      </>
    ) },
  ];
  return (
    <>
      <Table label="API keys" columns={columns} rows={keys} rowKey={(k) => k.id}
        toolbar={<><span className="sy-text--sm sy-text--strong">API keys</span><Button size="sm" onClick={() => setKeys(start)}>Restore the keys</Button></>} />
      <ConfirmDialog open={doomed !== null} onClose={() => setDoomed(null)} title={`Revoke the key ${doomed?.name}?`} action="Revoke key"
        onConfirm={() => { setKeys(keys.filter((k) => k !== doomed)); setDoomed(null); toast('Key revoked'); }}>
        Apps that use it stop working at once. This cannot be undone.
      </ConfirmDialog>
      <Toaster />
    </>
  );
}

Skeleton

Antes de saber siquiera las columnas: las mismas cajas que la tabla real, así nada se mueve cuando llegan los datos. En el celular, tarjetas.

Código
import { TableSkeleton } from '@sypnia/ui/react';

// Before even the columns are known: header, rows and the pagination bar, in the boxes of a real Table.
// On a phone it is cards, like the real one. When the columns are known, use <Table loading> instead.
export default function Skeleton() {
  return <TableSkeleton columns={4} rows={5} pagination />;
}

Cuándo usarlo

Úsalo cuando

  • Muchas cosas de un tipo con los mismos datos: pedidos, miembros, claves, facturas.
  • La gente compara a lo largo de una columna o busca una fila: haz esas columnas ordenables con sortValue.
  • Dale pageSize y tiene páginas sola; con páginas que vienen de un servidor, pasa pagination.
  • Pon primero la columna que nombra la fila: en el celular es el título de la tarjeta.

No lo uses cuando

  • Las cosas son pocas y cada una tiene una forma distinta: Cards.
  • Son datos de una sola cosa: KeyValue.
  • Hay que editar celdas en el lugar, cambiar el ancho de columnas o recorrer miles de filas: DataTable.
  • La usarías para diseñar una página. Una tabla es para datos.

Para todos

  • Es una tabla de verdad con nombre (label), encabezados de columna y filas, así los lectores de pantalla anuncian «Total, columna 5» mientras la persona se mueve.
  • Un encabezado ordenable es un botón llamado «Ordenar por Total»; la columna dice si está en orden ascendente o descendente. Los valores vacíos van al final en los dos sentidos.
  • En el celular (40rem o menos) cada fila es una tarjeta y cada valor muestra el nombre de su columna al lado; la fila de encabezados sigue disponible para los lectores de pantalla. Las acciones de la fila van al pie de la tarjeta, como objetivos de al menos 44 px.
  • Mientras carga, la tabla se marca como ocupada y dibuja filas de skeleton: sin ruedas de carga. Un error se anuncia de inmediato y ofrece «Intentar de nuevo». Una tabla vacía dice qué va en ella.
  • Debajo de las filas, la barra de páginas dice cuántas hay y cuáles están en pantalla, y lo anuncia después de cada movimiento.
  • Los botones de acción necesitan un nombre que incluya la fila: «Copiar el ID de Back office».

Props

TableTipoPor defecto
columnsobligatorio Column<Row>[]
labelobligatorio

A name for screen readers.

string
rowKeyobligatorio (row: Row) => string | number
rowsobligatorio Row[] | undefined
dense boolean
empty

What to show when there are no rows: an EmptyState with the next step.

ReactNode
error

Something failed: the region says so. Say what happened in plain words.

ReactNode
loading

Data is on its way: rows are drawn as skeletons of the right shape.

boolean
loadingRows

How many skeleton rows to draw while loading: as many as will come (the count of the last visit, a known total). Default 6, never more than a page.

number
onRetry

With `error`: shows a «Try again» button that calls it.

(() => void)
onRowClick ((row: Row) => void)
pageSize

Rows per page, 25 by default: every table paginates by itself. For server-side pages pass `pagination` instead.

number
pagination

Server-side pagination: the table shows `rows` as they are and this bar under them.

{ page: number; pageSize: number; total: number; onPage: (p: number) => void; onPageSize?: ((s: number) => void); }
toolbar ReactNode
TableSkeletonTipoPor defecto
columns number 4
dense boolean
pagination boolean
rows number 6
  1. Ordenar
  2. Páginas: 60 filas, de 10 en 10
  3. Cargando
  4. Algo falló
  5. Vacía, con el paso siguiente
  6. Acciones en cada fila
  7. Skeleton
  8. Cuándo usarlo
  9. Para todos
  10. Props

    Busca páginas, secciones y términos