Table
Displays tabular data. Supports row selection and striped rows.
View in Storybook (opens in a new tab)
Installation
import { Table } from "@ginga-ui/core";Basic usage
A simple table example.
| Name | Type | Modified | Size |
|---|---|---|---|
| Documents | Folder | Dec 1, 2024 | 1.2 GB |
| Images | Folder | Nov 28, 2024 | 894 MB |
| README.md | Markdown file | Dec 15, 2024 | 4 KB |
| package.json | JSON file | Dec 10, 2024 | 2 KB |
table.tsx
import { Table } from "@ginga-ui/core";
export function BasicExample() {
return <Table data={sampleData} columns={columns} aria-label="File list" />;
}Striped
Specify striped to add a background color to even rows, making rows easier to follow.
| Name | Type | Modified | Size |
|---|---|---|---|
| Documents | Folder | Dec 1, 2024 | 1.2 GB |
| Images | Folder | Nov 28, 2024 | 894 MB |
| README.md | Markdown file | Dec 15, 2024 | 4 KB |
| package.json | JSON file | Dec 10, 2024 | 2 KB |
table.tsx
import { Table } from "@ginga-ui/core";
export function StripedExample() {
return (
<Table
data={sampleData}
columns={columns}
striped
aria-label="Striped file list"
/>
);
}Row selection
A table with selectable rows.
| Name | Type | Modified | Size | |
|---|---|---|---|---|
| Documents | Folder | Dec 1, 2024 | 1.2 GB | |
| Images | Folder | Nov 28, 2024 | 894 MB | |
| README.md | Markdown file | Dec 15, 2024 | 4 KB | |
| package.json | JSON file | Dec 10, 2024 | 2 KB |
table.tsx
import { Table } from "@ginga-ui/core";
export function WithSelectionExample() {
return (
<Table
data={sampleData}
columns={columns}
selectionMode="multiple"
aria-label="Selectable file list"
onSelectionChange={(keys) => console.log("Selected:", keys)}
/>
);
}User table
A practical example of a user data table.
| Name | Email address | Role |
|---|---|---|
| John Smith | john@example.com | Admin |
| Emily Johnson | emily@example.com | Editor |
| Michael Brown | michael@example.com | Viewer |
table.tsx
import { Table } from "@ginga-ui/core";
export function UserTableExample() {
return <Table data={userData} columns={userColumns} aria-label="User list" />;
}Empty state
Use emptyMessage to set the message shown when there is no data.
| Name | Type | Modified | Size |
|---|---|---|---|
No files yet | |||
table.tsx
import { Table } from "@ginga-ui/core";
export function EmptyStateExample() {
return (
<Table
data={[]}
columns={columns}
emptyMessage="No files yet"
aria-label="Empty table"
/>
);
}Props
Table
children cannot be passed. Pass rows with data and columns with columns.
| Name | Type | Default | Description |
|---|---|---|---|
data | T[] | - | Required. Rows to display. |
columns | TableColumn<T>[] | - | Required. Column definitions. See TableColumn below. |
aria-label | string | - | Required. Accessible name of the table. |
getRowKey | (row: T, index: number) => Key | - | Returns the key of a row. When omitted, the row's id is used, or the index if there is no id. |
selectionMode | "none" | "single" | "multiple" | "none" | Row selection mode. A checkbox column is added when rows can be selected. |
onSelectionChange | (selectedRows: T[], keys: Selection) => void | - | Called with the selected rows and their keys when the selection changes. |
showHeader | boolean | true | Shows the header row. When false, it is hidden visually but still read by screen readers. |
striped | boolean | false | Alternates the background color of rows. |
emptyMessage | ReactNode | - | Content shown when data is empty. |
Also accepts the props of React Aria's Table (opens in a new tab).
TableColumn<T>
| Name | Type | Default | Description |
|---|---|---|---|
key | string | - | Required. Unique key of the column. |
header | ReactNode | - | Required. Header content. |
accessor | keyof T | ((row: T) => ReactNode) | - | Required. Property name of the row to show, or a function that returns the cell content. |
isRowHeader | boolean | - | Uses this column as the row header. When no column sets it, the first column is used. |
allowsSorting | boolean | - | Makes the column sortable. Handle sorting with sortDescriptor and onSortChange. |