F
Filament4mo ago
adnn

How to use shouldDeselectAllRecordsWhenTableFiltered?

I want to keep the selections and NOT clear them when a user searches inside the table, came accross this https://github.com/filamentphp/filament/issues/5776 but not sure how I am supposed to use it?
GitHub
Table : Selected elements are deselected when using search · Issue ...
Package filament/filament Package Version v2.17.4 Laravel Version v9.52.0 Livewire Version v2.12.0 PHP Version PHP 8.1.0 Problem description When using search and select rows, changing the search i...
4 Replies
Tieme
Tieme4mo ago
Just add this to the table
return $table
->shouldDeselectAllRecordsWhenFiltered(false)
return $table
->shouldDeselectAllRecordsWhenFiltered(false)
adnn
adnn4mo ago
public static function table(Table $table): Table
{
return $table

->columns([
Tables\Columns\TextColumn::make('server_id')
->searchable(),
Tables\Columns\TextColumn::make('type')
->searchable(),

Tables\Columns\TextColumn::make('name')
->searchable(),

Tables\Columns\TextColumn::make('ip_address')
->searchable(),

Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable(),
])
->shouldDeselectAllRecordsWhenFiltered(false);

}
public static function table(Table $table): Table
{
return $table

->columns([
Tables\Columns\TextColumn::make('server_id')
->searchable(),
Tables\Columns\TextColumn::make('type')
->searchable(),

Tables\Columns\TextColumn::make('name')
->searchable(),

Tables\Columns\TextColumn::make('ip_address')
->searchable(),

Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable(),
])
->shouldDeselectAllRecordsWhenFiltered(false);

}
returns App\Filament\Resources\ServerResource::table(): Return value must be of type Filament\Tables\Table, true returned am i doing something wrong?
dhanar98
dhanar984mo ago
@adnn make sure
use Filament\Tables;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Filament\Tables;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
this classes are imported in the top of the file I tried it is working fine
adnn
adnn4mo ago
They are imported, still getting the same error. Here's the full code just in case I messed up somewhere