PHP code example of modus-digital / livewire-datatables
1. Go to this page and download the library: Download modus-digital/livewire-datatables library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
modus-digital / livewire-datatables example snippets
declare(strict_types=1);
namespace App\Livewire\Tables;
use App\Models\User;
use ModusDigital\LivewireDatatables\Livewire\Table;
use ModusDigital\LivewireDatatables\Columns\Column;
use ModusDigital\LivewireDatatables\Columns\TextColumn;
use ModusDigital\LivewireDatatables\Filters\SelectFilter;
class UsersTable extends Table
{
protected string $model = User::class;
protected function columns(): array
{
return [
TextColumn::make('Name')
->field('name')
->sortable()
->searchable(),
TextColumn::make('Email')
->field('email')
->sortable()
->searchable(),
TextColumn::make('Status')
->field('status')
->badge()
->sortable(),
TextColumn::make('Created')
->field('created_at')
->sortable()
->format(fn($value) => $value->diffForHumans()),
];
}
protected function filters(): array
{
return [
SelectFilter::make('Status')
->options([
'active' => 'Active',
'inactive' => 'Inactive',
'banned' => 'Banned',
])
->multiple(), // <-- This is optional
];
}
}
Column::make('Name')
->field('name') // Database field (ook: 'relation.field')
->sortable() // Kolom sorteerbaar maken
->searchable() // Opnemen in globale zoek
->hidden() // Verbergen
->width('150px') // CSS breedte (bv. '150px', '20%')
->align('center') // 'left' | 'center' | 'right'
->view('custom.cell') // Custom Blade view voor de cel
->sortField('users.name') // Aparte sorteer-field (optioneel)
->format(fn ($value, $record) => strtoupper((string) $value));
TextColumn::make('Description')
->field('description')
->limit(50) // Tekst afkappen
->badge('blue') // Badge tonen (kleur vast of via Closure)
->fullWidth(); // Badge over volle breedte