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 NameSKUPriceQty
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 NameSKUPriceQty
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 NamePriceQuantity
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 NameSKUPriceQty
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)

IDProduct NameSKUPrice
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

PropTypeDefaultDescription
columnsEditableTableColumn[]Column definitions (required)
dataT[]Array of row data objects (required)
onChange(data: T[]) => voidCalled when data changes (required)
rowKeystring'id'Property to use as row key
addablebooleanfalseShow add row button
deletablebooleanfalseShow delete button per row
onAddRow() => TFactory function for new rows
stripedbooleanfalseAlternate row background colors
classNamestringAdditional CSS classes

EditableTableColumn Type

PropTypeDefaultDescription
keystringProperty key in data object (required)
labelstringColumn header text (required)
type'text' | 'number' | 'email' | 'url' | 'date''text'Input type
widthstringCSS width value
align'left' | 'center' | 'right''left'Cell alignment
editablebooleantrueWhether column is editable
validate(value) => string | nullValidation function
format(value) => stringDisplay formatter
placeholderstringInput 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 accessibility

Keyboard Navigation

KeyAction
TabNavigate between cells
EnterStart editing / Save changes
EscapeCancel edit

Notes

  • Focus management between cells
  • Validation errors announced
  • Delete confirmation for row removal