Editable Table
Data Display
Forms
Data table with inline cell editing, validation, row management, and custom formatting.
Preview
Click on any cell to edit its value
| Product Name | SKU | Price | Qty |
|---|---|---|---|
Laptop Pro | LAP-001 | $1299.99 | 15 |
Wireless Mouse | MOU-002 | $49.99 | 50 |
USB-C Hub | HUB-003 | $79.99 | 30 |
Add & Delete Rows
Enable row management with addable and deletable props
| Product Name | SKU | Price | Qty | |
|---|---|---|---|---|
Laptop Pro | LAP-001 | $1299.99 | 15 | |
Wireless Mouse | MOU-002 | $49.99 | 50 | |
USB-C Hub | HUB-003 | $79.99 | 30 |
With Validation
Add validation rules to columns
| Product Name | Price | Quantity |
|---|---|---|
Laptop Pro | $1299.99 | 15 |
Wireless Mouse | $49.99 | 50 |
USB-C Hub | $79.99 | 30 |
Striped Rows
Alternating row colors for better readability
| Product Name | SKU | Price | Qty |
|---|---|---|---|
Laptop Pro | LAP-001 | $1299.99 | 15 |
Wireless Mouse | MOU-002 | $49.99 | 50 |
USB-C Hub | HUB-003 | $79.99 | 30 |
Read-Only Columns
Mix of editable and non-editable columns (SKU is read-only)
| ID | Product Name | SKU | Price |
|---|---|---|---|
| 1 | Laptop Pro | LAP-001 | $1299.99 |
| 2 | Wireless Mouse | MOU-002 | $49.99 |
| 3 | USB-C Hub | HUB-003 | $79.99 |
Props
EditableTable component API reference
| Prop | Type | Default | Description |
|---|---|---|---|
columns | EditableTableColumn[] | — | Column definitions (required) |
data | T[] | — | Array of row data objects (required) |
onChange | (data: T[]) => void | — | Called when data changes (required) |
rowKey | string | 'id' | Property to use as row key |
addable | boolean | false | Show add row button |
deletable | boolean | false | Show delete button per row |
onAddRow | () => T | — | Factory function for new rows |
striped | boolean | false | Alternate row background colors |
className | string | — | Additional CSS classes |
EditableTableColumn Type
| Prop | Type | Default | Description |
|---|---|---|---|
key | string | — | Property key in data object (required) |
label | string | — | Column header text (required) |
type | 'text' | 'number' | 'email' | 'url' | 'date' | 'text' | Input type |
width | string | — | CSS width value |
align | 'left' | 'center' | 'right' | 'left' | Cell alignment |
editable | boolean | true | Whether column is editable |
validate | (value) => string | null | — | Validation function |
format | (value) => string | — | Display formatter |
placeholder | string | — | Input placeholder text |
Usage
Import and implementation example
import { EditableTable, EditableTableColumn } from '@/blocks/data-display/editable-table'
interface ProductRow {
id: number
name: string
price: number
sku: string
}
export default function Example() {
const [data, setData] = useState<ProductRow[]>([
{ id: 1, name: 'Product 1', price: 99.99, sku: 'SKU-001' },
])
const columns: EditableTableColumn[] = [
{ key: 'name', label: 'Name', type: 'text' },
{ key: 'price', label: 'Price', type: 'number', align: 'right' },
{ key: 'sku', label: 'SKU', editable: false }, // Read-only
]
return (
<>
{/* Basic table */}
<EditableTable
columns={columns}
data={data}
onChange={setData}
/>
{/* With add/delete functionality */}
<EditableTable
columns={columns}
data={data}
onChange={setData}
addable
deletable
onAddRow={() => ({
id: Date.now(),
name: '',
price: 0,
sku: `SKU-${Date.now()}`,
})}
/>
{/* With validation and formatting */}
<EditableTable
columns={[
{
key: 'price',
label: 'Price',
type: 'number',
format: (v) => `$${Number(v).toFixed(2)}`,
validate: (v) => Number(v) < 0 ? 'Must be positive' : null,
},
]}
data={data}
onChange={setData}
/>
{/* Striped rows */}
<EditableTable
columns={columns}
data={data}
onChange={setData}
striped
/>
</>
)
}Features
Built-in functionality
- Inline editing: Uses EditableCell for seamless cell editing
- Type support: Text, number, email, url, and date inputs
- Row management: Add and delete rows with callbacks
- Column validation: Custom validation per column
- Custom formatting: Display formatted values while editing raw data
- Read-only columns: Mix editable and non-editable columns
- Striped rows: Alternating backgrounds for readability
- Dark mode: Full dark mode support
Accessibility
Accessibility considerations
ARIA Attributes
Uses semantic table elementsCells have proper scope attributesEditable cells use EditableCell accessibilityKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Navigate between cells |
| Enter | Start editing / Save changes |
| Escape | Cancel edit |
Notes
- Focus management between cells
- Validation errors announced
- Delete confirmation for row removal