Data Table
A table you can sort, filter, select rows in and page through. Same markup and props in every style: switch the style in the header to see it change.
Basic
Sort by a header, filter by text, select rows and page through 12 invoices, five at a time. In HTML, add data-vin-data-table (and data-page-size) and include vinui.js; every row is in the markup and the script hides the ones on other pages.
| Status | ||||
|---|---|---|---|---|
| INV-1042 | Asha Rao | Paid | ₹12,400 | |
| INV-1041 | Ben Carter | Pending | ₹8,250 | |
| INV-1040 | Chen Wei | Overdue | ₹3,100 | |
| INV-1039 | Divya Nair | Paid | ₹15,000 | |
| INV-1038 | Elena Petrova | Paid | ₹4,720 | |
| INV-1037 | Farid Haddad | Pending | ₹9,900 | |
| INV-1036 | Grace Kim | Paid | ₹2,350 | |
| INV-1035 | Hiro Tanaka | Overdue | ₹6,480 | |
| INV-1034 | Isla Murphy | Paid | ₹18,200 | |
| INV-1033 | Jonas Weber | Pending | ₹5,600 | |
| INV-1032 | Kavya Iyer | Paid | ₹7,300 | |
| INV-1031 | Liam Byrne | Paid | ₹11,050 |
<div class="vin-data-table" data-vin-data-table data-page-size="5" style="max-width: 720px">
<div class="vin-data-table__toolbar">
<div class="vin-input vin-input-group vin-data-table__search">
<span class="vin-input-group__addon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg></span>
<input type="search" class="vin-input-group__input" placeholder="Filter invoices…" aria-label="Filter invoices">
</div>
</div>
<div class="vin-table-wrap" role="region" aria-label="Invoices" tabindex="0">
<table class="vin-table">
<thead>
<tr>
<th scope="col" class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select all rows"></th>
<th scope="col"><button type="button" class="vin-data-table__sort">Invoice<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
<th scope="col"><button type="button" class="vin-data-table__sort">Customer<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
<th scope="col">Status</th>
<th scope="col" class="vin-table__num"><button type="button" class="vin-data-table__sort">Amount<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
</tr>
</thead>
<tbody>
<tr><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1042"></td><td>INV-1042</td><td>Asha Rao</td><td><span class="vin-badge vin-badge--success">Paid</span></td><td class="vin-table__num">₹12,400</td></tr>
<tr><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1041"></td><td>INV-1041</td><td>Ben Carter</td><td><span class="vin-badge vin-badge--warning">Pending</span></td><td class="vin-table__num">₹8,250</td></tr>
<tr><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1040"></td><td>INV-1040</td><td>Chen Wei</td><td><span class="vin-badge vin-badge--danger">Overdue</span></td><td class="vin-table__num">₹3,100</td></tr>
<tr><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1039"></td><td>INV-1039</td><td>Divya Nair</td><td><span class="vin-badge vin-badge--success">Paid</span></td><td class="vin-table__num">₹15,000</td></tr>
<tr><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1038"></td><td>INV-1038</td><td>Elena Petrova</td><td><span class="vin-badge vin-badge--success">Paid</span></td><td class="vin-table__num">₹4,720</td></tr>
<tr hidden><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1037"></td><td>INV-1037</td><td>Farid Haddad</td><td><span class="vin-badge vin-badge--warning">Pending</span></td><td class="vin-table__num">₹9,900</td></tr>
<tr hidden><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1036"></td><td>INV-1036</td><td>Grace Kim</td><td><span class="vin-badge vin-badge--success">Paid</span></td><td class="vin-table__num">₹2,350</td></tr>
<tr hidden><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1035"></td><td>INV-1035</td><td>Hiro Tanaka</td><td><span class="vin-badge vin-badge--danger">Overdue</span></td><td class="vin-table__num">₹6,480</td></tr>
<tr hidden><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1034"></td><td>INV-1034</td><td>Isla Murphy</td><td><span class="vin-badge vin-badge--success">Paid</span></td><td class="vin-table__num">₹18,200</td></tr>
<tr hidden><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1033"></td><td>INV-1033</td><td>Jonas Weber</td><td><span class="vin-badge vin-badge--warning">Pending</span></td><td class="vin-table__num">₹5,600</td></tr>
<tr hidden><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1032"></td><td>INV-1032</td><td>Kavya Iyer</td><td><span class="vin-badge vin-badge--success">Paid</span></td><td class="vin-table__num">₹7,300</td></tr>
<tr hidden><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select INV-1031"></td><td>INV-1031</td><td>Liam Byrne</td><td><span class="vin-badge vin-badge--success">Paid</span></td><td class="vin-table__num">₹11,050</td></tr>
</tbody>
</table>
</div>
<div class="vin-data-table__footer">
<p class="vin-data-table__status" aria-live="polite">0 of 12 selected</p>
<nav class="vin-pagination" aria-label="Pagination">
<ul class="vin-pagination__list">
<li><button type="button" class="vin-btn vin-btn--outline vin-btn--sm" disabled><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 6-6 6 6 6"/></svg> Previous</button></li>
<li><span class="vin-pagination__status">Page 1 of 3</span></li>
<li><button type="button" class="vin-btn vin-btn--outline vin-btn--sm">Next <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 6 6 6-6 6"/></svg></button></li>
</ul>
</nav>
</div>
</div>| Status | ||||
|---|---|---|---|---|
| INV-1042 | Asha Rao | Paid | ₹12,400 | |
| INV-1041 | Ben Carter | Pending | ₹8,250 | |
| INV-1040 | Chen Wei | Overdue | ₹3,100 | |
| INV-1039 | Divya Nair | Paid | ₹15,000 | |
| INV-1038 | Elena Petrova | Paid | ₹4,720 | |
| INV-1037 | Farid Haddad | Pending | ₹9,900 | |
| INV-1036 | Grace Kim | Paid | ₹2,350 | |
| INV-1035 | Hiro Tanaka | Overdue | ₹6,480 | |
| INV-1034 | Isla Murphy | Paid | ₹18,200 | |
| INV-1033 | Jonas Weber | Pending | ₹5,600 | |
| INV-1032 | Kavya Iyer | Paid | ₹7,300 | |
| INV-1031 | Liam Byrne | Paid | ₹11,050 |
import { DataTable } from "@/components/vin/data-table";
import { Badge } from "@/components/vin/badge";
type Invoice = { id: string; customer: string; status: "Paid" | "Pending" | "Overdue"; amount: number };
const invoices: Invoice[] = [
{ id: "INV-1042", customer: "Asha Rao", status: "Paid", amount: 12400 },
{ id: "INV-1041", customer: "Ben Carter", status: "Pending", amount: 8250 },
{ id: "INV-1040", customer: "Chen Wei", status: "Overdue", amount: 3100 },
{ id: "INV-1039", customer: "Divya Nair", status: "Paid", amount: 15000 },
{ id: "INV-1038", customer: "Elena Petrova", status: "Paid", amount: 4720 },
{ id: "INV-1037", customer: "Farid Haddad", status: "Pending", amount: 9900 },
{ id: "INV-1036", customer: "Grace Kim", status: "Paid", amount: 2350 },
{ id: "INV-1035", customer: "Hiro Tanaka", status: "Overdue", amount: 6480 },
{ id: "INV-1034", customer: "Isla Murphy", status: "Paid", amount: 18200 },
{ id: "INV-1033", customer: "Jonas Weber", status: "Pending", amount: 5600 },
{ id: "INV-1032", customer: "Kavya Iyer", status: "Paid", amount: 7300 },
{ id: "INV-1031", customer: "Liam Byrne", status: "Paid", amount: 11050 },
];
const tone = { Paid: "success", Pending: "warning", Overdue: "danger" } as const;
const inr = (n: number) => "₹" + n.toLocaleString("en-IN");
export function DataTableBasic() {
return (
<DataTable
label="Invoices"
data={invoices}
rowKey="id"
selectable
filterable
filterPlaceholder="Filter invoices…"
pageSize={5}
columns={[
{ key: "id", header: "Invoice" },
{ key: "customer", header: "Customer" },
{ key: "status", header: "Status", sortable: false, cell: (r) => <Badge variant={tone[r.status]}>{r.status}</Badge> },
{ key: "amount", header: "Amount", numeric: true, cell: (r) => inr(r.amount), filterValue: (r) => inr(r.amount) },
]}
style={{ maxWidth: 720 }}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import DataTable, { type DataTableColumn } from "@/components/vin/data-table.vue";
import Badge from "@/components/vin/badge.vue";
type Invoice = { id: string; customer: string; status: "Paid" | "Pending" | "Overdue"; amount: number };
const invoices: Invoice[] = [
{ id: "INV-1042", customer: "Asha Rao", status: "Paid", amount: 12400 },
{ id: "INV-1041", customer: "Ben Carter", status: "Pending", amount: 8250 },
{ id: "INV-1040", customer: "Chen Wei", status: "Overdue", amount: 3100 },
{ id: "INV-1039", customer: "Divya Nair", status: "Paid", amount: 15000 },
{ id: "INV-1038", customer: "Elena Petrova", status: "Paid", amount: 4720 },
{ id: "INV-1037", customer: "Farid Haddad", status: "Pending", amount: 9900 },
{ id: "INV-1036", customer: "Grace Kim", status: "Paid", amount: 2350 },
{ id: "INV-1035", customer: "Hiro Tanaka", status: "Overdue", amount: 6480 },
{ id: "INV-1034", customer: "Isla Murphy", status: "Paid", amount: 18200 },
{ id: "INV-1033", customer: "Jonas Weber", status: "Pending", amount: 5600 },
{ id: "INV-1032", customer: "Kavya Iyer", status: "Paid", amount: 7300 },
{ id: "INV-1031", customer: "Liam Byrne", status: "Paid", amount: 11050 },
];
const tone = { Paid: "success", Pending: "warning", Overdue: "danger" } as const;
const inr = (n: number) => "₹" + n.toLocaleString("en-IN");
const columns: DataTableColumn<Invoice>[] = [
{ key: "id", header: "Invoice" },
{ key: "customer", header: "Customer" },
{ key: "status", header: "Status", sortable: false },
{ key: "amount", header: "Amount", numeric: true, cell: (r) => inr(r.amount), filterValue: (r) => inr(r.amount) },
];
</script>
<template>
<DataTable
label="Invoices"
:data="invoices"
row-key="id"
selectable
filterable
filter-placeholder="Filter invoices…"
:page-size="5"
:columns="columns"
style="max-width: 720px"
>
<template #cell-status="{ row }"><Badge :variant="tone[row.status]">{{ row.status }}</Badge></template>
</DataTable>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import DataTable from "$lib/components/vin/data-table.svelte";
import Badge from "$lib/components/vin/badge.svelte";
type Invoice = { id: string; customer: string; status: "Paid" | "Pending" | "Overdue"; amount: number };
const invoices: Invoice[] = [
{ id: "INV-1042", customer: "Asha Rao", status: "Paid", amount: 12400 },
{ id: "INV-1041", customer: "Ben Carter", status: "Pending", amount: 8250 },
{ id: "INV-1040", customer: "Chen Wei", status: "Overdue", amount: 3100 },
{ id: "INV-1039", customer: "Divya Nair", status: "Paid", amount: 15000 },
{ id: "INV-1038", customer: "Elena Petrova", status: "Paid", amount: 4720 },
{ id: "INV-1037", customer: "Farid Haddad", status: "Pending", amount: 9900 },
{ id: "INV-1036", customer: "Grace Kim", status: "Paid", amount: 2350 },
{ id: "INV-1035", customer: "Hiro Tanaka", status: "Overdue", amount: 6480 },
{ id: "INV-1034", customer: "Isla Murphy", status: "Paid", amount: 18200 },
{ id: "INV-1033", customer: "Jonas Weber", status: "Pending", amount: 5600 },
{ id: "INV-1032", customer: "Kavya Iyer", status: "Paid", amount: 7300 },
{ id: "INV-1031", customer: "Liam Byrne", status: "Paid", amount: 11050 },
];
const tone = { Paid: "success", Pending: "warning", Overdue: "danger" } as const;
const inr = (n: number) => "₹" + n.toLocaleString("en-IN");
</script>
{#snippet status(r: Invoice)}<Badge variant={tone[r.status]}>{r.status}</Badge>{/snippet}
{#snippet amount(r: Invoice)}{inr(r.amount)}{/snippet}
<DataTable
label="Invoices"
data={invoices}
rowKey="id"
selectable
filterable
filterPlaceholder="Filter invoices…"
pageSize={5}
columns={[
{ key: "id", header: "Invoice" },
{ key: "customer", header: "Customer" },
{ key: "status", header: "Status", sortable: false, cell: status },
{ key: "amount", header: "Amount", numeric: true, cell: amount, filterValue: (r) => inr(r.amount) },
]}
style="max-width: 720px"
/>Sorting only
Starts sorted by commits, highest first. Click a header to sort by it; click again to reverse.
| Tom Okafor | Engineering | 2021-09-02 | 1,290 |
| Sara Lind | Engineering | 2022-01-17 | 642 |
| Lucía Ortiz | Product | 2022-11-05 | 215 |
| Meera Shah | Design | 2023-04-11 | 184 |
| Ravi Menon | Docs | 2024-06-30 | 97 |
<div class="vin-data-table" data-vin-data-table style="max-width: 560px">
<div class="vin-table-wrap" role="region" aria-label="Contributors" tabindex="0">
<table class="vin-table">
<thead>
<tr>
<th scope="col"><button type="button" class="vin-data-table__sort">Name<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
<th scope="col"><button type="button" class="vin-data-table__sort">Role<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
<th scope="col"><button type="button" class="vin-data-table__sort">Joined<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
<th scope="col" class="vin-table__num" aria-sort="descending"><button type="button" class="vin-data-table__sort">Commits<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
</tr>
</thead>
<tbody>
<tr><td>Tom Okafor</td><td>Engineering</td><td>2021-09-02</td><td class="vin-table__num">1,290</td></tr>
<tr><td>Sara Lind</td><td>Engineering</td><td>2022-01-17</td><td class="vin-table__num">642</td></tr>
<tr><td>Lucía Ortiz</td><td>Product</td><td>2022-11-05</td><td class="vin-table__num">215</td></tr>
<tr><td>Meera Shah</td><td>Design</td><td>2023-04-11</td><td class="vin-table__num">184</td></tr>
<tr><td>Ravi Menon</td><td>Docs</td><td>2024-06-30</td><td class="vin-table__num">97</td></tr>
</tbody>
</table>
</div>
</div>| Tom Okafor | Engineering | 2021-09-02 | 1,290 |
| Sara Lind | Engineering | 2022-01-17 | 642 |
| Lucía Ortiz | Product | 2022-11-05 | 215 |
| Meera Shah | Design | 2023-04-11 | 184 |
| Ravi Menon | Docs | 2024-06-30 | 97 |
import { DataTable } from "@/components/vin/data-table";
const people = [
{ name: "Meera Shah", role: "Design", commits: 184, joined: "2023-04-11" },
{ name: "Tom Okafor", role: "Engineering", commits: 1290, joined: "2021-09-02" },
{ name: "Sara Lind", role: "Engineering", commits: 642, joined: "2022-01-17" },
{ name: "Ravi Menon", role: "Docs", commits: 97, joined: "2024-06-30" },
{ name: "Lucía Ortiz", role: "Product", commits: 215, joined: "2022-11-05" },
];
export function DataTableSorting() {
return (
<DataTable
label="Contributors"
data={people}
rowKey="name"
defaultSort={{ key: "commits", direction: "descending" }}
columns={[
{ key: "name", header: "Name" },
{ key: "role", header: "Role" },
{ key: "joined", header: "Joined" },
{ key: "commits", header: "Commits", numeric: true, cell: (r) => r.commits.toLocaleString("en-US") },
]}
style={{ maxWidth: 560 }}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import DataTable, { type DataTableColumn } from "@/components/vin/data-table.vue";
type Person = { name: string; role: string; commits: number; joined: string };
const people: Person[] = [
{ name: "Meera Shah", role: "Design", commits: 184, joined: "2023-04-11" },
{ name: "Tom Okafor", role: "Engineering", commits: 1290, joined: "2021-09-02" },
{ name: "Sara Lind", role: "Engineering", commits: 642, joined: "2022-01-17" },
{ name: "Ravi Menon", role: "Docs", commits: 97, joined: "2024-06-30" },
{ name: "Lucía Ortiz", role: "Product", commits: 215, joined: "2022-11-05" },
];
const columns: DataTableColumn<Person>[] = [
{ key: "name", header: "Name" },
{ key: "role", header: "Role" },
{ key: "joined", header: "Joined" },
{ key: "commits", header: "Commits", numeric: true, cell: (r) => r.commits.toLocaleString("en-US") },
];
</script>
<template>
<DataTable
label="Contributors"
:data="people"
row-key="name"
:default-sort="{ key: 'commits', direction: 'descending' }"
:columns="columns"
style="max-width: 560px"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import DataTable from "$lib/components/vin/data-table.svelte";
type Person = { name: string; role: string; commits: number; joined: string };
const people: Person[] = [
{ name: "Meera Shah", role: "Design", commits: 184, joined: "2023-04-11" },
{ name: "Tom Okafor", role: "Engineering", commits: 1290, joined: "2021-09-02" },
{ name: "Sara Lind", role: "Engineering", commits: 642, joined: "2022-01-17" },
{ name: "Ravi Menon", role: "Docs", commits: 97, joined: "2024-06-30" },
{ name: "Lucía Ortiz", role: "Product", commits: 215, joined: "2022-11-05" },
];
</script>
{#snippet commits(r: Person)}{r.commits.toLocaleString("en-US")}{/snippet}
<DataTable
label="Contributors"
data={people}
rowKey="name"
sort={{ key: "commits", direction: "descending" }}
columns={[
{ key: "name", header: "Name" },
{ key: "role", header: "Role" },
{ key: "joined", header: "Joined" },
{ key: "commits", header: "Commits", numeric: true, cell: commits },
]}
style="max-width: 560px"
/>Selection
Two rows start selected, so the header checkbox shows a dash (mixed). Clicking it selects every row.
| Asha Rao | asha@example.com | Owner | |
| Ben Carter | ben@example.com | Admin | |
| Chen Wei | chen@example.com | Member | |
| Divya Nair | divya@example.com | Member |
<div class="vin-data-table" data-vin-data-table style="max-width: 560px">
<div class="vin-table-wrap" role="region" aria-label="Team members" tabindex="0">
<table class="vin-table">
<thead>
<tr>
<th scope="col" class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select all rows"></th>
<th scope="col"><button type="button" class="vin-data-table__sort">Name<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
<th scope="col"><button type="button" class="vin-data-table__sort">Email<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
<th scope="col"><button type="button" class="vin-data-table__sort">Role<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m8 9 4-4 4 4"/><path d="m16 15-4 4-4-4"/></svg></button></th>
</tr>
</thead>
<tbody>
<tr><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select Asha Rao"></td><td>Asha Rao</td><td>asha@example.com</td><td>Owner</td></tr>
<tr><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select Ben Carter"></td><td>Ben Carter</td><td>ben@example.com</td><td>Admin</td></tr>
<tr data-selected><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select Chen Wei" checked></td><td>Chen Wei</td><td>chen@example.com</td><td>Member</td></tr>
<tr data-selected><td class="vin-data-table__select"><input type="checkbox" class="vin-checkbox" aria-label="Select Divya Nair" checked></td><td>Divya Nair</td><td>divya@example.com</td><td>Member</td></tr>
</tbody>
</table>
</div>
<div class="vin-data-table__footer">
<p class="vin-data-table__status" aria-live="polite">2 of 4 selected</p>
</div>
</div>| Asha Rao | asha@example.com | Owner | |
| Ben Carter | ben@example.com | Admin | |
| Chen Wei | chen@example.com | Member | |
| Divya Nair | divya@example.com | Member |
import { DataTable } from "@/components/vin/data-table";
const members = [
{ email: "asha@example.com", name: "Asha Rao", role: "Owner" },
{ email: "ben@example.com", name: "Ben Carter", role: "Admin" },
{ email: "chen@example.com", name: "Chen Wei", role: "Member" },
{ email: "divya@example.com", name: "Divya Nair", role: "Member" },
];
export function DataTableSelection() {
return (
<DataTable
label="Team members"
data={members}
rowKey="email"
selectable
defaultSelected={["chen@example.com", "divya@example.com"]}
columns={[
{ key: "name", header: "Name" },
{ key: "email", header: "Email" },
{ key: "role", header: "Role" },
]}
style={{ maxWidth: 560 }}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import DataTable from "@/components/vin/data-table.vue";
const members = [
{ email: "asha@example.com", name: "Asha Rao", role: "Owner" },
{ email: "ben@example.com", name: "Ben Carter", role: "Admin" },
{ email: "chen@example.com", name: "Chen Wei", role: "Member" },
{ email: "divya@example.com", name: "Divya Nair", role: "Member" },
];
const columns = [
{ key: "name", header: "Name" },
{ key: "email", header: "Email" },
{ key: "role", header: "Role" },
];
</script>
<template>
<DataTable
label="Team members"
:data="members"
row-key="email"
selectable
:default-selected="['chen@example.com', 'divya@example.com']"
:columns="columns"
style="max-width: 560px"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import DataTable from "$lib/components/vin/data-table.svelte";
const members = [
{ email: "asha@example.com", name: "Asha Rao", role: "Owner" },
{ email: "ben@example.com", name: "Ben Carter", role: "Admin" },
{ email: "chen@example.com", name: "Chen Wei", role: "Member" },
{ email: "divya@example.com", name: "Divya Nair", role: "Member" },
];
</script>
<DataTable
label="Team members"
data={members}
rowKey="email"
selectable
selected={["chen@example.com", "divya@example.com"]}
columns={[
{ key: "name", header: "Name" },
{ key: "email", header: "Email" },
{ key: "role", header: "Role" },
]}
style="max-width: 560px"
/>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add data-tableimport { DataTable, dataTableStatus } from "@/components/vin/data-table";import DataTable, { dataTableStatus } from "@/components/vin/data-table.vue";import DataTable, { dataTableStatus } from "$lib/components/vin/data-table.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.
API
From spec/data-table.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
columnsWhat each column shows. Columns sort unless sortable is false; numeric right-aligns them. | { key; header; cell?; sortValue?; filterValue?; sortable?; numeric? }[] | — | th[scope=col] > button.vin-data-table__sort (th.vin-table__num for numbers) |
dataThe rows. Sorting, filtering and paging happen in the browser. | T[] | — | — |
rowKeyIdentifies each row, for selection. | keyof T | (row: T) => string | number | — | — |
labelNames the table's scrolling region (and the filter box). | string | — | aria-label on .vin-table-wrap[role=region] |
pageSizeRows per page; 0 shows them all. The pager is Pagination's simple version. | number | 0 | data-page-size on .vin-data-table; nav.vin-pagination in .vin-data-table__footer |
selectableA checkbox per row and a "select all" checkbox in the header, which shows a dash when some rows are selected. | boolean | false | th / td.vin-data-table__select > input.vin-checkbox; tr[data-selected] |
defaultSelected / onSelectionChangeRows selected at first, and a callback with the keys after each change. | (string | number)[] | — | — |
filterableA search box that hides rows whose text doesn't match. | boolean | false | .vin-data-table__toolbar > .vin-input.vin-input-group.vin-data-table__search > input[type=search] |
filterLabel / filterPlaceholderThe filter box's name (default "Filter invoices") and placeholder. | string | — | — |
defaultSortSort on first render. Clicking a header sorts ascending, then descending. | { key: string; direction: "ascending" | "descending" } | — | aria-sort on the th |
rowLabelName of a row's checkbox. Default: "Select" + the first column. | (row: T) => string | — | — |
emptyText | ReactNode | No results. | tr.vin-data-table__empty > td[colspan] |
sort value (HTML)In HTML, cells sort by their text (numbers like ₹12,400 sort as numbers). Put data-value on a cell to sort by something else. | attribute | — | td[data-value="12400"] |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<DataTable> | .vin-data-table.vin-data-table__toolbar.vin-data-table__search.vin-data-table__sort.vin-data-table__select.vin-data-table__empty.vin-data-table__footer.vin-data-table__status |
Accessibility
- A real table with th[scope] headers. Sortable headers hold a button, and the sorted column has aria-sort="ascending" or "descending", so screen readers say how it's sorted.
- The sort arrows are hidden from screen readers; the button's name is the column name.
- Each row checkbox has a name ("Select INV-1042"). The header checkbox is "Select all rows" and is mixed (indeterminate) when some are selected.
- The status line ("2 of 12 selected") is a polite live region, so changes are announced.
- The filter box is a labelled search input; paging uses Pagination's Previous / Next buttons, which are disabled at the ends.
- On small screens the table scrolls sideways inside its focusable region instead of squashing the columns.
Customize
Saved in this browser. Style and accent are in the header.