DataTable - Basic Features

Core functionality: Pagination, Sorting, Search, Column Visibility, Row Selection

Basic FeaturesClient-Side20 Records
🎯 Interactive Demo
Test all basic features in action - 20 users loaded
Ahmet Yılmaz
ahmet.yilmaz@example.comAdminActiveIT15.01.2022₺85.000,00
Ayşe Demir
ayse.demir@example.comManagerActiveSales20.06.2021₺75.000,00
Mehmet Kaya
mehmet.kaya@example.comDeveloperActiveIT10.03.2023₺65.000,00
Fatma Şahin
fatma.sahin@example.comUserPendingHR05.01.2024₺55.000,00
Ali Çelik
ali.celik@example.comDeveloperActiveIT12.09.2022₺70.000,00
Zeynep Arslan
zeynep.arslan@example.comManagerActiveMarketing08.11.2021₺78.000,00
Mustafa Yıldız
mustafa.yildiz@example.comUserInactiveSales18.05.2020₺52.000,00
Elif Özkan
elif.ozkan@example.comDeveloperActiveIT22.07.2023₺68.000,00
Hasan Aydın
hasan.aydin@example.comAdminActiveIT14.02.2020₺90.000,00
Selin Koç
selin.koc@example.comManagerActiveHR30.04.2022₺72.000,00
✨ Enabled Features
Click and interact with these features
1

Pagination

Bottom-right: Change page size (10/20/50/100) and navigate pages

2

Sorting

Click column headers - first click: ascending, second: descending, third: reset

3

Global Search

Top-left search box - searches across all visible columns

4

Column Visibility

Top-right "Columns" button - show/hide columns dynamically

5

Row Selection

Checkboxes - select multiple rows, header checkbox selects all

6

Row Actions

Action menu (•••) - contextual actions for each row

💡 Implementation Tips

Column Headers: Use DataTableColumnHeader for sortable columns

Selection: Call createSelectionColumn() as first column

Custom Cells: Use cell property for Badge, icons, formatting

Type Safety: Define ColumnDef<YourType>[] for autocomplete

⚙️ Props Reference
DataTable component props used in this example
PropTypeDefaultDescription
dataT[]-Array of data objects
columnsColumnDef[]-Column definitions
enablePaginationbooleanfalseEnable pagination controls
enableSortingbooleanfalseEnable column sorting
enableGlobalFilterbooleanfalseEnable global search
enableColumnVisibilitybooleanfalseShow column toggle
enableRowSelectionbooleanfalseEnable row checkboxes
onRowClickFunction-Row click handler
💻 Code Example
Complete implementation of this page
import { DataTable, DataTableColumnHeader, createSelectionColumn } from '@hascanb/arf-ui-kit/datatable-kit'
import { ColumnDef } from '@tanstack/react-table'

type User = {
  id: string
  name: string
  email: string
  role: string
  status: string
}

const columns: ColumnDef<User>[] = [
  createSelectionColumn<User>(), // Checkbox column
  {
    accessorKey: 'name',
    header: ({ column }) => (
      <DataTableColumnHeader column={column} title="Name" />
    ),
    cell: ({ row }) => <div className="font-medium">{row.getValue('name')}</div>
  },
  {
    accessorKey: 'email',
    header: ({ column }) => (
      <DataTableColumnHeader column={column} title="Email" />
    )
  },
  {
    accessorKey: 'status',
    header: ({ column }) => (
      <DataTableColumnHeader column={column} title="Status" />
    ),
    cell: ({ row }) => (
      <Badge variant={row.getValue('status') === 'Active' ? 'default' : 'secondary'}>
        {row.getValue('status')}
      </Badge>
    )
  }
]

export default function UsersPage() {
  const [selectedRows, setSelectedRows] = useState({})
  
  return (
    <DataTable
      data={users}
      columns={columns}
      enablePagination
      enableSorting
      enableGlobalFilter
      enableColumnVisibility
      enableRowSelection
      rowSelection={selectedRows}
      onRowSelectionChange={setSelectedRows}
      onRowClick={(row) => console.log('Clicked:', row.original)}
    />
  )
}