ยท assem ยท Advanced Techniques

Filament hiding records in table until filtered or searched

If you have too many records in a single table to show immediately, you can hide them until a filter/search is applied.

How to hide all table records in Filament until search or filters are used - picture
->modifyQueryUsing(function (Builder $query, $livewire) {
    $hasFilters = collect($livewire->tableFilters)
        ->filter(fn($filter) => !empty($filter['values']))
        ->isNotEmpty();
    return ($livewire->hasTableSearch() || $hasFilters) ? $query : $query->whereRaw('1 = 0');
})
React
Share post

Stay ahead in the Filament Mastery adventure

Join our community of Filament PHP enthusiasts! Get exclusive tips, tutorials, and updates delivered straight to your inbox.