Skip to content

Table

Download .md

A table shows records in rows and columns; every Sosialoka product lays out its datatables the same way.

  • Use it for records people compare or scan, such as releases, documents or payouts.
  • Use cards for a few rich items, and a plain list for one column of text.
React
JudulArtisStatus
Senja di KotaRara SenandikaTerbit
Kaset PertamaBima LarasMenunggu
Pulang SoreNada KiranaDijadwalkan
Hujan Bulan JuniArka WeningTerbit
Lampu KotaSinta MaharaniDitolak
Vue
JudulArtisStatus
Senja di KotaRara Senandika
Terbit
Kaset PertamaBima Laras
Menunggu
Pulang SoreNada Kirana
Dijadwalkan
Hujan Bulan JuniArka Wening
Terbit
Lampu KotaSinta Maharani
Ditolak
DoRight-align numbers with tabular figures, so the digits line up.
Don'tDon't center numbers; their magnitudes become hard to compare.
123
  1. 1Header row on muted
  2. 2Row
  3. 3Status badge

The shared datatable has four parts:

  1. Header: column names in muted-foreground, medium weight.
  2. Rows: border-b border-border between rows, bg-muted/50 on hover. Status uses a Badge.
  3. Row actions: a ghost icon button that opens a Dropdown Menu, in the last column.
  4. Pagination: below the table, inside the same card. The current page is an outline button.

Put the table in a card (rounded-lg border border-border bg-card) so it reads as one surface.

There is one style. Add text-right and tabular-nums to number columns.

React Vue Flutter Type Default Use
Table, TableHeader, TableBody, TableRow, TableHead, TableCell same names ShadTable.list, ShadTableCell element none Table structure.
PaginationLink isActive PaginationItem :is-active ShadButton.outline boolean false Marks the current page.
href on pagination links :total, :items-per-page on Pagination none string / number none Where a page link goes, or how Vue counts pages.
import { useState, type MouseEvent } from "react"
import { Badge } from "@/components/ui/badge"
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
const releases = [
{ title: "Senja di Kota", artist: "Rara Senandika", status: "success", label: "Terbit" },
{ title: "Kaset Pertama", artist: "Bima Laras", status: "warning", label: "Menunggu" },
{ title: "Pulang Sore", artist: "Nada Kirana", status: "info", label: "Dijadwalkan" },
{ title: "Hujan Bulan Juni", artist: "Arka Wening", status: "success", label: "Terbit" },
{ title: "Lampu Kota", artist: "Sinta Maharani", status: "destructive", label: "Ditolak" },
] as const
/** Two pages of five rows; the demo shows the first page's rows on both. */
const pages = [1, 2]
export default function TableDemo() {
const [page, setPage] = useState(1)
const goTo = (next: number) => (event: MouseEvent) => {
event.preventDefault()
setPage(next)
}
return (
<div className="w-full max-w-xl rounded-lg border border-border bg-card">
<Table>
<TableHeader>
<TableRow>
<TableHead>Judul</TableHead>
<TableHead>Artis</TableHead>
<TableHead>Status</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{releases.map((r) => (
<TableRow key={r.title}>
<TableCell className="font-medium">{r.title}</TableCell>
<TableCell className="text-muted-foreground">{r.artist}</TableCell>
<TableCell>
<Badge variant={r.status}>{r.label}</Badge>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<Pagination className="border-t border-border py-2">
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#" disabled={page === 1} onClick={goTo(page - 1)} />
</PaginationItem>
{pages.map((p) => (
<PaginationItem key={p}>
<PaginationLink href="#" isActive={p === page} onClick={goTo(p)}>
{p}
</PaginationLink>
</PaginationItem>
))}
<PaginationItem>
<PaginationNext href="#" disabled={page === pages.length} onClick={goTo(page + 1)} />
</PaginationItem>
</PaginationContent>
</Pagination>
</div>
)
}
Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/table.json

Pagination is a separate item:

Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/pagination.json
  • Uses native table, th and td, so screen readers announce rows and columns.
  • Pagination is a nav; the current page has aria-current="page".
  • Give icon-only row actions an aria-label, such as “Aksi”.