Display

Data table

Shows rows of data people can sort, search and page through.

Installation

npx sinaui add data-table

Examples

Sortable

Click a column heading to sort by it (numbers largest first); click again to reverse, a third time to clear. Numbers line up on the right.

Most borrowed works
The Compendious Book on CalculationAl-Khwārizmī8201,204
Book of OpticsIbn al-Haytham1021866
The Canon of MedicineIbn Sīnā10252,310
Kitāb al-TaṣrīfAl-Zahrāwī1000547
Tabula RogerianaAl-Idrīsī1154391
Book of Ingenious Mechanical DevicesAl-Jazarī1206978

<script lang="ts">
	import DataTable, { type Column } from '#lib/ui/DataTable.svelte';

	type Work = { title: string; author: string; written: number; loans: number };

	const works: Work[] = [
		{
			title: 'The Compendious Book on Calculation',
			author: 'Al-Khwārizmī',
			written: 820,
			loans: 1204
		},
		{ title: 'Book of Optics', author: 'Ibn al-Haytham', written: 1021, loans: 866 },
		{ title: 'The Canon of Medicine', author: 'Ibn Sīnā', written: 1025, loans: 2310 },
		{ title: 'Kitāb al-Taṣrīf', author: 'Al-Zahrāwī', written: 1000, loans: 547 },
		{ title: 'Tabula Rogeriana', author: 'Al-Idrīsī', written: 1154, loans: 391 },
		{
			title: 'Book of Ingenious Mechanical Devices',
			author: 'Al-Jazarī',
			written: 1206,
			loans: 978
		}
	];

	const nf = new Intl.NumberFormat();
	const columns: Column<Work>[] = [
		{ accessorKey: 'title', header: 'Title' },
		{ accessorKey: 'author', header: 'Author' },
		{ accessorKey: 'written', header: 'Written (CE)', meta: { align: 'end' } },
		{
			accessorKey: 'loans',
			header: 'Loans',
			cell: (c) => nf.format(c.getValue<number>()),
			meta: { align: 'end' }
		}
	];
</script>

<DataTable caption="Most borrowed works" data={works} {columns} />

The search looks through every column, ignoring case and accents. Page controls appear only when there's more than one page.

Scholars of the Golden Age
Jābir ibn ḤayyānAlchemyKūfa721
Al-KhwārizmīMathematicsBaghdad780
Al-KindīPhilosophyBaghdad801
Thābit ibn QurraMathematicsBaghdad826
Al-RāzīMedicineRayy865
Al-FārābīPhilosophyBaghdad872
Al-ZahrāwīSurgeryCórdoba936
Ibn al-HaythamOpticsCairo965

1–8 of 16

<script lang="ts">
	import DataTable, { type Column } from '#lib/ui/DataTable.svelte';

	type Scholar = { name: string; field: string; city: string; born: number };

	// Birth years are approximate for most; "c." is left out so the column sorts as numbers.
	const scholars: Scholar[] = [
		{ name: 'Jābir ibn Ḥayyān', field: 'Alchemy', city: 'Kūfa', born: 721 },
		{ name: 'Al-Khwārizmī', field: 'Mathematics', city: 'Baghdad', born: 780 },
		{ name: 'Al-Kindī', field: 'Philosophy', city: 'Baghdad', born: 801 },
		{ name: 'Thābit ibn Qurra', field: 'Mathematics', city: 'Baghdad', born: 826 },
		{ name: 'Al-Rāzī', field: 'Medicine', city: 'Rayy', born: 865 },
		{ name: 'Al-Fārābī', field: 'Philosophy', city: 'Baghdad', born: 872 },
		{ name: 'Al-Zahrāwī', field: 'Surgery', city: 'Córdoba', born: 936 },
		{ name: 'Ibn al-Haytham', field: 'Optics', city: 'Cairo', born: 965 },
		{ name: 'Al-Bīrūnī', field: 'Astronomy', city: 'Ghazni', born: 973 },
		{ name: 'Ibn Sīnā', field: 'Medicine', city: 'Bukhara', born: 980 },
		{ name: 'Omar Khayyām', field: 'Mathematics', city: 'Nīshāpūr', born: 1048 },
		{ name: 'Al-Idrīsī', field: 'Geography', city: 'Palermo', born: 1100 },
		{ name: 'Ibn Rushd', field: 'Philosophy', city: 'Córdoba', born: 1126 },
		{ name: 'Al-Jazarī', field: 'Engineering', city: 'Diyarbakır', born: 1136 },
		{ name: 'Naṣīr al-Dīn al-Ṭūsī', field: 'Astronomy', city: 'Marāgha', born: 1201 },
		{ name: 'Ibn al-Nafīs', field: 'Medicine', city: 'Cairo', born: 1213 }
	];

	const columns: Column<Scholar>[] = [
		{ accessorKey: 'name', header: 'Scholar' },
		{ accessorKey: 'field', header: 'Field' },
		{ accessorKey: 'city', header: 'City' },
		{ accessorKey: 'born', header: 'Born (CE)', meta: { align: 'end' } }
	];
</script>

<DataTable
	caption="Scholars of the Golden Age"
	hideCaption
	searchLabel="Search scholars"
	data={scholars}
	{columns}
	pageSize={8}
/>

Columns

Columns are TanStack ColumnDefs; the Column<Row> type fills in the table's features for you. Format numbers and dates in cell with Intl, and set meta: { align: 'end' } on numeric columns.

Props

PropTypeDefault
captionstring (required)
hideCaptionbooleanfalse
dataRow[]
columnsColumn<Row>[]
searchLabelstringno search box
pageSizenumber10
emptystring'No matching rows'

Accessibility

  • A real <table> with a caption and column headers, so screen readers can move by row and column and read each cell with its heading.
  • Sortable headings are buttons, and the sorted column carries aria-sort. After sorting or searching, screen readers hear the result, for example “5 rows, sorted by Born, descending”.
  • A table wider than the screen scrolls sideways, and can be focused to scroll with arrow keys.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme