Core functionality: Pagination, Sorting, Search, Column Visibility, Row Selection
Ahmet Yılmaz | ahmet.yilmaz@example.com | Admin | Active | IT | 15.01.2022 | ₺85.000,00 | ||
Ayşe Demir | ayse.demir@example.com | Manager | Active | Sales | 20.06.2021 | ₺75.000,00 | ||
Mehmet Kaya | mehmet.kaya@example.com | Developer | Active | IT | 10.03.2023 | ₺65.000,00 | ||
Fatma Şahin | fatma.sahin@example.com | User | Pending | HR | 05.01.2024 | ₺55.000,00 | ||
Ali Çelik | ali.celik@example.com | Developer | Active | IT | 12.09.2022 | ₺70.000,00 | ||
Zeynep Arslan | zeynep.arslan@example.com | Manager | Active | Marketing | 08.11.2021 | ₺78.000,00 | ||
Mustafa Yıldız | mustafa.yildiz@example.com | User | Inactive | Sales | 18.05.2020 | ₺52.000,00 | ||
Elif Özkan | elif.ozkan@example.com | Developer | Active | IT | 22.07.2023 | ₺68.000,00 | ||
Hasan Aydın | hasan.aydin@example.com | Admin | Active | IT | 14.02.2020 | ₺90.000,00 | ||
Selin Koç | selin.koc@example.com | Manager | Active | HR | 30.04.2022 | ₺72.000,00 |
Pagination
Bottom-right: Change page size (10/20/50/100) and navigate pages
Sorting
Click column headers - first click: ascending, second: descending, third: reset
Global Search
Top-left search box - searches across all visible columns
Column Visibility
Top-right "Columns" button - show/hide columns dynamically
Row Selection
Checkboxes - select multiple rows, header checkbox selects all
Row Actions
Action menu (•••) - contextual actions for each row
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
| Prop | Type | Default | Description |
|---|---|---|---|
| data | T[] | - | Array of data objects |
| columns | ColumnDef[] | - | Column definitions |
| enablePagination | boolean | false | Enable pagination controls |
| enableSorting | boolean | false | Enable column sorting |
| enableGlobalFilter | boolean | false | Enable global search |
| enableColumnVisibility | boolean | false | Show column toggle |
| enableRowSelection | boolean | false | Enable row checkboxes |
| onRowClick | Function | - | Row click handler |
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)}
/>
)
}