1. Go to this page and download the library: Download digit7s/inertia-table 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/ */
digit7s / inertia-table example snippets
namespace App\Tables;
use App\Models\User;
use Digit7s\InertiaTable\Column;
use Digit7s\InertiaTable\Columns\DateColumn;
use Digit7s\InertiaTable\Columns\TextColumn;
use Digit7s\InertiaTable\InertiaTable;
use Illuminate\Database\Eloquent\Builder;
class UsersTable extends InertiaTable
{
protected ?string $model = User::class;
public function query(): Builder
{
return User::query();
}
public function columns(): array
{
return [
Column::make('id', 'ID')->sortable(),
TextColumn::make('name')->searchable()->sortable(),
TextColumn::make('email')->searchable(),
TextColumn::make('roles.name', 'Role')->searchable(),
DateColumn::make('created_at', 'Joined')->sortable(),
];
}
}
use App\Tables\UsersTable;
use Inertia\Inertia;
public function index()
{
return Inertia::render('Users/Index', [
'users' => (new UsersTable())->toInertia(),
]);
}
use Digit7s\InertiaTable\Columns\TagsColumn;
TagsColumn::make('tags')
->labelKey('name')
->badgeClass('bg-blue-500 text-white');
public function query(): Builder
{
$this->rowLink(fn (User $user) => route('users.show', $user->id));
return User::query();
}
use Digit7s\InertiaTable\Action;
use Digit7s\InertiaTable\Columns\ActionColumn;
public function columns(): array
{
return [
TextColumn::make('name'),
ActionColumn::new(),
];
}
public function actions(): array
{
return [
Action::make('edit', 'Edit')
->icon('Pencil')
->url(fn (User $user) => route('users.edit', $user->id)),
Action::make('delete', 'Delete')
->icon('Trash')
->method('delete')
->
use Digit7s\InertiaTable\BulkAction;
public function bulkActions(): array
{
return [
BulkAction::make('delete', 'Delete Selected')
->icon('Trash')
->
use Digit7s\InertiaTable\Exports\CsvExport;
public function exports(): array
{
return [
CsvExport::make('products.csv')
->label('Export CSV')
->onlyVisibleColumns()
->withCurrentFilters()
->withCurrentSort(),
];
}