1. Go to this page and download the library: Download yuisalabs/voltia-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/ */
yuisalabs / voltia-datatable example snippets
namespace App\Tables;
use Illuminate\Database\Eloquent\Builder;
use App\Models\User;
use Yuisalabs\VoltiaDatatable\Table;
use Yuisalabs\VoltiaDatatable\Column;
use Yuisalabs\VoltiaDatatable\Filters\SelectFilter;
use Yuisalabs\VoltiaDatatable\Filters\DateRangeFilter;
class UserTable extends Table
{
public function query(): Builder
{
return User::query();
}
public function columns(): array
{
return [
Column::make('id', 'ID')
->sortable(),
Column::make('name', 'Name')
->sortable()
->searchable(),
Column::make('email', 'Email')
->sortable()
->searchable(),
Column::make('status', 'Status')
->sortable()
->format(fn ($row, $value) => ucfirst($value)),
Column::make('created_at', 'Created At')
->sortable()
->format(fn ($row, $value) => $value?->format('Y-m-d H:i:s')),
];
}
protected function filters(): array
{
return [
'status' => new SelectFilter('status', [
'active' => 'Active',
'inactive' => 'Inactive',
'pending' => 'Pending',
]),
'created_at' => new DateRangeFilter('created_at'),
];
}
}
namespace App\Http\Controllers;
use App\Tables\UserTable;
use Inertia\Inertia;
class UserController extends Controller
{
public function index(UserTable $datatable)
{
return Inertia::render('Users/Index', [
'datatable' => $datatable->make(),
]);
}
}