Table
A table shows records in rows and columns; every Sosialoka product lays out its datatables the same way.
When to use
Section titled “When to use”- 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.
| Judul | Artis | Status |
|---|---|---|
| Senja di Kota | Rara Senandika | Terbit |
| Kaset Pertama | Bima Laras | Menunggu |
| Pulang Sore | Nada Kirana | Dijadwalkan |
| Hujan Bulan Juni | Arka Wening | Terbit |
| Lampu Kota | Sinta Maharani | Ditolak |
| Judul | Artis | Status |
|---|---|---|
| Senja di Kota | Rara Senandika | Terbit |
| Kaset Pertama | Bima Laras | Menunggu |
| Pulang Sore | Nada Kirana | Dijadwalkan |
| Hujan Bulan Juni | Arka Wening | Terbit |
| Lampu Kota | Sinta Maharani | Ditolak |
Do and don’t
Section titled “Do and don’t”Anatomy
Section titled “Anatomy”- 1Header row on muted
- 2Row
- 3Status badge
The shared datatable has four parts:
- Header: column names in
muted-foreground, medium weight. - Rows:
border-b border-borderbetween rows,bg-muted/50on hover. Status uses a Badge. - Row actions: a ghost icon button that opens a Dropdown Menu, in the last column.
- Pagination: below the table, inside the same card. The current page is an
outlinebutton.
Put the table in a card (rounded-lg border border-border bg-card) so it reads as one surface.
Variants
Section titled “Variants”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> )}<script setup lang="ts">import { Badge } from "@/components/ui/badge"import { Pagination, PaginationContent, PaginationItem, 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</script>
<template> <div class="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> <TableRow v-for="r in releases" :key="r.title"> <TableCell class="font-medium">{{ r.title }}</TableCell> <TableCell class="text-muted-foreground">{{ r.artist }}</TableCell> <TableCell><Badge :variant="r.status">{{ r.label }}</Badge></TableCell> </TableRow> </TableBody> </Table> <Pagination v-slot="{ page }" :items-per-page="5" :total="10" :default-page="1" class="border-t border-border py-2"> <PaginationContent v-slot="{ items }"> <PaginationPrevious /> <template v-for="(item, index) in items" :key="index"> <PaginationItem v-if="item.type === 'page'" :value="item.value" :is-active="item.value === page"> {{ item.value }} </PaginationItem> </template> <PaginationNext /> </PaginationContent> </Pagination> </div></template>// shadcn_ui has no pagination widget: put ShadButton.outline (current page) and ShadButton.ghost below the table.import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
const releases = [ (title: 'Senja di Kota', artist: 'Rara Senandika', status: 'Terbit'), (title: 'Kaset Pertama', artist: 'Bima Laras', status: 'Menunggu'), (title: 'Pulang Sore', artist: 'Nada Kirana', status: 'Dijadwalkan'),];
class TableDemo extends StatelessWidget { const TableDemo({super.key});
@override Widget build(BuildContext context) { return ConstrainedBox( constraints: const BoxConstraints(maxWidth: 576, maxHeight: 320), child: ShadTable.list( // Fixed widths for the title and artist; the status column takes the rest, so badges never clip. columnSpanExtent: (index) => switch (index) { 0 => const FixedTableSpanExtent(200), 1 => const FixedTableSpanExtent(180), _ => const RemainingTableSpanExtent(), }, header: const [ ShadTableCell.header(child: Text('Judul')), ShadTableCell.header(child: Text('Artis')), ShadTableCell.header(child: Text('Status')), ], children: releases.map( (r) => [ ShadTableCell(child: Text(r.title, style: const TextStyle(fontWeight: FontWeight.w500))), ShadTableCell(child: Text(r.artist)), ShadTableCell(child: ShadBadge.outline(child: Text(r.status))), ], ), ), ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/table.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/table.jsonPagination is a separate item:
npx shadcn@latest add https://design.sosialoka.tech/r/react/pagination.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/pagination.jsonAccessibility
Section titled “Accessibility”- Uses native
table,thandtd, so screen readers announce rows and columns. - Pagination is a
nav; the current page hasaria-current="page". - Give icon-only row actions an
aria-label, such as “Aksi”.
