DataTable

Data Display
Block

Powerful table component with sorting, searching, pagination, and row selection.

Built With

1 component

This block uses the following UI components from the design system:

Preview

Complete table with search, sorting, pagination, and actions

Name
Email
Role
Status
Actions
Alice Johnsonalice@example.comAdmin
Active
Bob Smithbob@example.comUser
Active
Charlie Browncharlie@example.comUser
Inactive
Diana Princediana@example.comManager
Active
Ethan Huntethan@example.comUser
Active

Simple Table

Basic table without search or pagination

Project
Tasks
Completed
Status
Marketing Strategy4238Active
Content Pipeline2825Active
Product Launch5612Active
Team Operations1515Completed

Minimal Header

Table without header background color

Project
Tasks
Completed
Status
Marketing Strategy4238Active
Content Pipeline2825Active
Product Launch5612Active
Team Operations1515Completed

Selectable Rows

Table with row selection enabled

Project
Tasks
Completed
Status
Marketing Strategy4238Active
Content Pipeline2825Active
Product Launch5612Active
Team Operations1515Completed

Props

DataTable component API reference

PropTypeDefaultDescription
columnsDataTableColumn[]Array of column definitions (required)
dataT[]Array of data objects (required)
selectablebooleanfalseEnable row selection
searchablebooleantrueEnable search functionality
paginationbooleantrueEnable pagination
pageSizenumber5Number of rows per page
headerBgbooleantrueShow header background
actionsDataTableAction[]Array of row actions
onSelectionChange(selected: T[]) => voidCallback when selection changes
classNamestringAdditional CSS classes

Column Definition

interface DataTableColumn {
  key: string              // Data key to display
  label: string            // Column header label
  sortable?: boolean       // Enable sorting (default: true)
  render?: (value: any, row: T) => ReactNode  // Custom cell renderer
}

Action Definition

interface DataTableAction {
  label: string            // Action label (tooltip)
  icon: ReactNode          // Icon to display
  onClick: (row: T, index: number) => void  // Click handler
}

Usage

Import and implementation example

import { DataTable } from '@/blocks/data-display/data-table'
import { Badge } from '@/components/ui/badge'
import { Edit2, Trash2 } from 'lucide-react'

export default function Example() {
  const columns = [
    { key: 'name', label: 'Name' },
    { key: 'email', label: 'Email' },
    {
      key: 'status',
      label: 'Status',
      render: (value) => (
        <Badge variant={value === 'Active' ? 'success' : 'default'}>
          {value}
        </Badge>
      ),
    },
  ]

  const actions = [
    {
      label: 'Edit',
      icon: <Edit2 className="w-4 h-4" />,
      onClick: (row) => console.log('Edit', row),
    },
    {
      label: 'Delete',
      icon: <Trash2 className="w-4 h-4" />,
      onClick: (row) => console.log('Delete', row),
    },
  ]

  return (
    <DataTable
      columns={columns}
      data={users}
      selectable
      searchable
      pagination
      pageSize={10}
      actions={actions}
      onSelectionChange={(selected) => console.log(selected)}
    />
  )
}

Features

Built-in functionality

  • Sorting: Click column headers to sort
  • Search: Filter rows by any column
  • Pagination: Navigate through large datasets
  • Row selection: Single and multi-select
  • Custom renderers: Rich content in cells
  • Row actions: Icon buttons per row
  • Header variants: With or without background
  • Dark mode: Full dark mode support

Accessibility

Accessibility considerations

ARIA Attributes

Uses semantic table elementColumn headers use th with scopeSelection checkboxes have aria-label

Keyboard Navigation

KeyAction
TabNavigate interactive elements
SpaceToggle row selection
EnterActivate action buttons

Notes

  • Search input is labeled
  • Pagination controls are keyboard accessible
  • Sort state is communicated to screen readers
  • Selection count is announced