The Table component provides a structured way to display tabular data with proper styling and responsive behavior. It's designed for data tables, comparison tables, and any structured information display.
import { table } from '@dashflowx/core'export default function TableExample() {return (<table><thead><tr><th>Name</th><th>Email</th><th>Role</th></tr></thead><tbody><tr><td>John Doe</td><td>john@example.com</td><td>Admin</td></tr><tr><td>Jane Smith</td><td>jane@example.com</td><td>User</td></tr></tbody></table>)}
Preview:
| Name | Role | |
|---|---|---|
| John Doe | john@example.com | Admin |
| Jane Smith | jane@example.com | User |
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | '' | Additional CSS classes |
import { table } from '@dashflowx/core'export default function BasicTable() {return (<table><thead><tr><th>Name</th><th>Email</th><th>Role</th></tr></thead><tbody><tr><td>John Doe</td><td>john@example.com</td><td>Admin</td></tr><tr><td>Jane Smith</td><td>jane@example.com</td><td>User</td></tr></tbody></table>)}
Preview:
| Name | Role | |
|---|---|---|
| John Doe | john@example.com | Admin |
| Jane Smith | jane@example.com | User |
import { table } from '@dashflowx/core'export default function CustomStyledTable() {return (<table className="border border-blue-500 rounded-lg p-4"><thead><tr><th>Name</th><th>Email</th><th>Role</th></tr></thead><tbody><tr><td>John Doe</td><td>john@example.com</td><td>Admin</td></tr><tr><td>Jane Smith</td><td>jane@example.com</td><td>User</td></tr></tbody></table>)}
Preview:
| Name | Role | |
|---|---|---|
| John Doe | john@example.com | Admin |
| Jane Smith | jane@example.com | User |
import { table } from '@dashflowx/core'export default function DataTable() {const data = [{ name: 'John Doe', email: 'john@example.com', role: 'Admin' },{ name: 'Jane Smith', email: 'jane@example.com', role: 'User' },{ name: 'Bob Johnson', email: 'bob@example.com', role: 'User' }];return (<table><thead><tr><th>Name</th><th>Email</th><th>Role</th></tr></thead><tbody>{data.map((row, index) => (<tr key={index}><td>{row.name}</td><td>{row.email}</td><td>{row.role}</td></tr>))}</tbody></table>)}
import { table } from '@dashflowx/core'export default function ComparisonTable() {return (<table><thead><tr><th>Feature</th><th>Basic Plan</th><th>Pro Plan</th><th>Enterprise Plan</th></tr></thead><tbody><tr><td>Storage</td><td>5GB</td><td>50GB</td><td>Unlimited</td></tr><tr><td>Users</td><td>1</td><td>10</td><td>Unlimited</td></tr><tr><td>Support</td><td>Email</td><td>Priority</td><td>24/7</td></tr></tbody></table>)}
const userManagementTable = (<table><thead><tr><th>Name</th><th>Email</th><th>Role</th><th>Actions</th></tr></thead><tbody><tr><td>John Doe</td><td>john@example.com</td><td>Admin</td><td><button>Edit</button><button>Delete</button></td></tr></tbody></table>);
const productComparison = (<table><thead><tr><th>Feature</th><th>Product A</th><th>Product B</th><th>Product C</th></tr></thead><tbody><tr><td>Price</td><td>$99</td><td>$199</td><td>$299</td></tr></tbody></table>);
const financialData = (<table><thead><tr><th>Month</th><th>Revenue</th><th>Expenses</th><th>Profit</th></tr></thead><tbody><tr><td>January</td><td>$10,000</td><td>$7,000</td><td>$3,000</td></tr></tbody></table>);
const inventoryTable = (<table><thead><tr><th>Product</th><th>SKU</th><th>Stock</th><th>Price</th></tr></thead><tbody><tr><td>Laptop</td><td>LAP001</td><td>25</td><td>$999</td></tr></tbody></table>);
Use clear and descriptive table headers.
// ✅ Good - Clear headers<thead><tr><th>Full Name</th><th>Email Address</th><th>User Role</th></tr></thead>// ❌ Avoid - Unclear headers<thead><tr><th>Name</th><th>Email</th><th>Role</th></tr></thead>
Maintain consistent data formatting across rows.
// ✅ Good - Consistent formatting<tbody><tr><td>John Doe</td><td>john@example.com</td><td>Admin</td></tr></tbody>// ❌ Avoid - Inconsistent formatting<tbody><tr><td>John Doe</td><td>john@example.com</td><td>admin</td></tr></tbody>
Make tables responsive for different screen sizes.
// ✅ Good - Responsive<table className="w-full overflow-x-auto" />// ❌ Avoid - Fixed width<table className="w-96" />
Ensure tables are accessible to all users.
// ✅ Good - Accessible<table><thead><tr><th scope="col">Name</th><th scope="col">Email</th></tr></thead></table>// ❌ Avoid - Not accessible<table><thead><tr><th>Name</th><th>Email</th></tr></thead></table>
Use proper styling for better readability.
// ✅ Good - Proper styling<table className="border-collapse border border-gray-300" />// ❌ Avoid - Poor styling<table />
You can customize the table appearance using CSS classes:
<table className="border border-gray-300 rounded-lg p-4" />
Use different themes for different contexts:
// Light theme<table className="bg-white border-gray-200" />// Dark theme<table className="bg-gray-900 border-gray-700 text-white" />// Brand theme<table className="bg-blue-50 border-blue-200" />
Use different sizes for different emphasis levels:
// Small table<table className="text-sm" />// Standard table<table className="text-base" />// Large table<table className="text-lg" />
Load table data dynamically:
const [tableData, setTableData] = useState([]);useEffect(() => {// Load data from APIloadTableData().then(setTableData);}, []);
Implement sortable columns:
const [sortConfig, setSortConfig] = useState({ key: null, direction: 'asc' });const handleSort = (key) => {setSortConfig({ key, direction: sortConfig.direction === 'asc' ? 'desc' : 'asc' });};
Add filtering functionality:
const [filter, setFilter] = useState('');const filteredData = data.filter(item =>item.name.toLowerCase().includes(filter.toLowerCase()));
- Td: For table cells
- Th: For table headers
- Tr: For table rows
- Card: For table containers
- Button: For table actions
For the complete API reference and advanced usage patterns, see the Table API documentation.
