Creating tables
Use an inline definition for a small, page-specific table:
use InertiaX\Components\Table\Columns\NumberColumn;use InertiaX\Components\Table\Columns\TextColumn;use InertiaX\Facades\InertiaX;
InertiaX::table('users') ->data($users) ->addColumns([ NumberColumn::make('id')->numberCast('int')->visible(false), TextColumn::make('name')->searchable()->sortable(), ]);$users is the query for this page. Include the row’s primary key among the columns, even when
it is hidden. See Data sources for other key fields.
Reuse a table class
Section titled “Reuse a table class”Move shared columns and settings into a class:
<?php
namespace App\Tables;
use InertiaX\Components\Table\Columns\NumberColumn;use InertiaX\Components\Table\Columns\TextColumn;use InertiaX\Components\Table\Table;
class UsersTable extends Table{ protected static int $defaultPageSize = 25;
protected function columns(): array { return [ NumberColumn::make('id')->numberCast('int')->visible(false), TextColumn::make('name')->searchable()->sortable(), TextColumn::make('email')->copyable(), ]; }}Supply the query when returning the table:
use App\Tables\UsersTable;use Inertia\Inertia;
return Inertia::render('Users/Index', [ UsersTable::make('users')->data($users),]);Render it with <InertiaX prop="users" />. The name passed to make() identifies this instance,
so the same class can serve multiple tables.
Override one instance
Section titled “Override one instance”UsersTable::make('users') ->data($users) ->replaceColumn(TextColumn::make('email', 'Work email')->copyable()) ->pageSize(50);Fluent calls apply after the class definition. A class can also declare its own
data() method and
filters() method.
See Table inheritance for composing definitions and Table API for the full builder reference.