1. Go to this page and download the library: Download redot/livewire-datatable 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/ */
redot / livewire-datatable example snippets
namespace App\Http\Livewire;
use Redot\LivewireDatatable\Datatable;
class UsersTable extends Datatable
{
// ...
}
use Redot\LivewireDatatable\Column;
class UsersTable extends Datatable
{
public function columns(): array
{
return [
Column::make('Name', 'name')
->sortable()
->searchable(),
Column::make('Email', 'email')
->sortable()
->searchable(),
Column::make('Username')
->resolve(fn ($row) => Str::slug($row->name)),
Column::make('Created At', 'created_at')
->sortable()
->searchable()
->format(fn ($value) => $value->format('d/m/Y H:i:s'))
];
}
}
use App\Models\User;
class UsersTable extends Datatable
{
// ...
public function query(): Builder
{
return User::query();
}
}
use Redot\LivewireDatatable\Action;
class UsersTable extends Datatable
{
// ...
public function actions(): array
{
return [
Action::view('users.show'),
Action::edit('users.edit'),
Action::delete('users.destroy'),
];
}
}