filament/tables
Powerful table builder for Filament admin panels. Add searchable, sortable, filterable tables with actions, bulk actions, and column types. Integrates cleanly with Eloquent and supports pagination, customization, and responsive layouts.
Installation
composer require filament/tables
Ensure filament/support and livewire/livewire are also installed (core dependencies).
Basic Usage
Add the HasTable trait to a Livewire component:
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
class UserTable extends Table implements HasTable
{
protected static ?string $model = User::class;
public function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name'),
TextColumn::make('email'),
])
->filters([
// Add filters here
]);
}
}
First Render Use the table in a Livewire component:
use Filament\Tables\Table;
class UsersPage extends Component
{
public function table(Table $table): Table
{
return $table->resource(UserTable::class);
}
}
Key Files to Explore
config/filament.php (global table settings)app/Providers/FilamentServiceProvider.php (publish config/views if needed)resources/views/filament/tables/ (customize default views)Column Definitions
TextColumn, BooleanColumn, SelectColumn, etc.) for type-specific rendering.TextColumn::make('status')
->badge()
->color(fn (string $state): string => match ($state) {
'active' => 'success',
'inactive' => 'danger',
})
Actions & Bulk Actions
Table::make()
->actions([
Action::make('edit')
->icon('heroicon-o-pencil')
->url(fn ($record) => route('users.edit', $record)),
])
->bulkActions([
Tables\Actions\BulkAction::make('delete')
->requiresConfirmation()
->action(fn (Collection $records) => User::whereKey($records->pluck('id'))->delete()),
])
Filters & Search
->filters([
SelectFilter::make('status')
->options(['active', 'inactive'])
->label('User Status'),
DateRangeFilter::make('created_at')
->label('Created Date'),
])
->searchable(['name', 'email'])
Pagination & Sorting
Table methods:
->paginate(10)
->defaultSort('name', 'asc')
Relationships
RelationshipManager or nested tables:
BelongsToManyColumn::make('roles')
->relationship('roles', 'name')
->searchable()
->searchable(['scout'])
protected function getTable(): Table
{
$table = parent::getTable();
$table->hook('rendered', fn () => $this->dispatch('table-rendered'));
return $table;
}
resources/views/filament/tables/.Model Binding Issues
$model is set statically (e.g., protected static ?string $model = User::class).->query(fn (Builder $query) => $query->where('type', $this->type)).Column Visibility
->hidden() sparingly:
TextColumn::make('secret_key')->hidden()
Filter Performance
->query() that aren’t optimized (e.g., LIKE on large text fields).->default() to pre-set filter values:
SelectFilter::make('status')->default('active')
Livewire State Bloat
->paginate(20) or ->lazy() for big tables.CSRF Token Conflicts
\DB::enableQueryLog();
$this->table->getQuery()->toSql(); // Inspect the final query
$table->hook('building', fn () => \Log::debug('Table building...'));
php artisan view:clear
php artisan filament:cache-reset
Custom Columns
Create a new column class by extending Filament\Tables\Columns\Column:
class CustomColumn extends Column
{
protected string $view = 'filament.tables.columns.custom';
}
Table Modifiers
Use TableModifier to alter table behavior:
$table->modify(fn (Table $table) => $table->disableActions());
Plugin System
Register plugins in FilamentServiceProvider:
Filament::registerTablePlugin(
TablePlugin::make()
->modifyTableQueryUsing(fn (Builder $query) => $query->where('is_active', true))
);
Localization
Override translations in config/filament.php or publish views:
php artisan vendor:publish --tag=filament-tables-views
Testing
Use Filament\Tables\Tests\Concerns\InteractsWithTables for unit tests:
use Filament\Tables\Tests\Concerns\InteractsWithTables;
class UserTableTest extends TestCase
{
use InteractsWithTables;
public function test_table_columns()
{
$this->assertTableColumn('name', UserTable::class);
}
}
How can I help you explore Laravel packages today?