DataTable

Ready

A powerful table component with sorting, searching, pagination, and row selection.

Full Featured Table

Complete table with search, sorting, pagination, row selection, 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
Showing 1 to 5 of 8

Simple Table

Basic table without search or pagination

Product
Category
Price
Stock
MacBook ProLaptops$2,49912
iPhone 15Phones$99948
iPad AirTablets$59924
AirPods ProAudio$24967

Minimal Table

Table without header background color

Product
Category
Price
Stock
MacBook ProLaptops$2,49912
iPhone 15Phones$99948
iPad AirTablets$59924
AirPods ProAudio$24967

Selectable Rows

Table with row selection enabled

Product
Category
Price
Stock
MacBook ProLaptops$2,49912
iPhone 15Phones$99948
iPad AirTablets$59924
AirPods ProAudio$24967

API Reference

Props and configuration options

DataTable Props

PropTypeDefaultDescription
columnsDataTableColumn[]requiredArray of column definitions
dataT[]requiredArray of data objects
selectablebooleanfalseEnable row selection
searchablebooleantrueEnable search functionality
paginationbooleantrueEnable pagination
pageSizenumber5Number of rows per page
actionsDataTableAction[][]Array of row actions
classNamestring-Additional CSS classes
onSelectionChangefunction-Callback when selection changes

Column Definition

PropertyTypeRequiredDescription
keystringYesData key to display
labelstringYesColumn header label
sortablebooleanNoEnable sorting (default: true)
renderfunctionNoCustom cell renderer

Action Definition

PropertyTypeRequiredDescription
labelstringYesAction label (tooltip)
iconReactNodeYesIcon to display
onClickfunctionYesClick handler (row, index)

Usage Example

How to use the DataTable component

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

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),
  },
]

<DataTable
  columns={columns}
  data={users}
  selectable
  searchable
  pagination
  pageSize={10}
  actions={actions}
/>