Directory
- Welcome
Table Component
The Table component offers two flexible approaches for creating tables: a high-level component for simple data display and a composable API for complex custom tables.
Key Features
-
Two Usage Methods: High-level component or composable parts
-
Rich Styling: Striped rows, borders, and hover states
-
Accessibility: Semantic markup and ARIA support
-
Dynamic Data: Support for headers, body, and footer
Basic Usage
Method 1: High-Level Component
Perfect for simple data tables:
<Table headers={{ columns: ['Name', 'Role', 'Department'], }} body={[ ['John Doe', 'Developer', 'Engineering'], ['Jane Smith', 'Designer', 'Creative'], ['Mike Johnson', 'Manager', 'Operations'], ]}/>
Method 2: Composable Parts
For more complex tables with custom markup:
<Table.Root striped borders="all"> <Table.Header> <Table.Row> <Table.Head>Name</Table.Head> <Table.Head>Role</Table.Head> <Table.Head>Department</Table.Head> </Table.Row> </Table.Header> <Table.Body> <Table.Row> <Table.Cell>John Doe</Table.Cell> <Table.Cell>Developer</Table.Cell> <Table.Cell>Engineering</Table.Cell> </Table.Row> </Table.Body></Table.Root>
Component API
High-Level Component Props
Prop | Type | Default | Description |
---|---|---|---|
headers | object | Column and row headers configuration | |
body | array[][] | Table data in 2D array format | |
caption | object | Optional caption with positioning | |
footer | boolean | array[][] | Footer rows configuration | |
colorKey | array | Color legend configuration | |
striped | boolean | false | Enable striped rows |
borders | "none" | "horizontal" | "vertical" | "all" | all | Border style |
textAlign | "top" | "bottom" | "center" | center | Cell content alignment |
Composable Parts
Component | Props | Description |
---|---|---|
Table.Root | striped, borders, textAlign | Main table wrapper |
Table.Header | class | Table header section |
Table.Body | class | Table body section |
Table.Row | cloneable, class | Table row |
Table.Cell | class | Table cell |
Table.Head | class | Header cell |
Table.Footer | class | Footer section |
JavaScript API
The Table component includes built-in methods for dynamic row management:
const table = await Ready(document.querySelector<TableElement>('table-wrapper'));
// Add new rowtable.appendRow(['John Doe', 'Developer', 'Engineering']);
// Remove specific rowtable.removeRow(1);
// Clear all rowstable.clearRows();
Implementation Example
---import { Table } from '@/components/NST-components/UI/table/TableParts.astro';
const data = [ { id: 'INV001', status: 'Paid', method: 'Credit Card', amount: '$250.00' }, { id: 'INV002', status: 'Pending', method: 'PayPal', amount: '$150.00' }, { id: 'INV003', status: 'Paid', method: 'Bank Transfer', amount: '$350.00' } ];
---
<Table.Root striped borders="all" textAlign="center"> <Table.Header> <Table.Row> <Table.Head>Invoice</Table.Head> <Table.Head>Status</Table.Head> <Table.Head>Method</Table.Head> <Table.Head>Amount</Table.Head> </Table.Row> </Table.Header> <Table.Body> {data.map((row) => ( <Table.Row> <Table.Cell>{row.id}</Table.Cell> <Table.Cell>{row.status}</Table.Cell> <Table.Cell>{row.method}</Table.Cell> <Table.Cell>{row.amount}</Table.Cell> </Table.Row> ))} </Table.Body></Table.Root>
Target | Impact | |
---|---|---|
FCP | < 2s | |
TTI | < 3.5s | Critical |
CLS | < 0.1 | Medium |
Target | Impact | |
---|---|---|
FCP | < 2s | |
TTI | < 3.5s | Critical |
CLS | < 0.1 | Medium |
Result | Good |
Limited Time Launch Sale
Build better data displays with our AstroJS starter template. Get the Table component and many more UI components ready to use in your next project.
GET 60% OFF!