Filament Clickable Column Filter

Submitted by techenby - 6 months ago

Sometimes, you want to click a column to refine the results of a table further without going through the filter menu on a Filament table.

// Step one: create a filter
SelectFilter::make('user')
    ->relationship('user', 'name')
    ->searchable() // added so all records aren't loaded initally
    
// Step two: add action to column
TextColumn::make('user.name')
    ->label('Owner')
    ->action(function ($livewire, $record) {
        $livewire->tableFilters['user'] = ['value' => $record->user_id];
    })