Show Empty Table Until Users Search/Filter Data v4

Filament 4

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

FilamentExamples ThumbBase (5)

Get the Source Code:

How it works

Let's start by adding tabs functionality to the table. To do this, let's modify our ListOrders file:

app/Filament/Resources/Orders/Pages/ListOrders.php

// ...
 
public function getTabs(): array
{
return [
'all' => Tab::make(),
'completed' => Tab::make()
->modifyQueryUsing(fn(Builder $query) => $query->where('status', OrderStatus::Completed->value)),
'refunded' => Tab::make()
->modifyQueryUsing(fn(Builder $query) => $query->where('status', OrderStatus::Refunded->value)),
];
}
 
// ...

Once that is done, let's modify the OrdersTable file to add the logic that will prevent the table from displaying any entries unless searched or filtered:

app/Filament/Resources/Orders/Tables/OrdersTable.php

use Illuminate\Database\Eloquent\Builder;
use App\Filament\Resources\Orders\Pages\ListOrders;
 
// ...

Next, we will add:

  • Logic to hide records until Filters or Search is applied
  • Explain how this works
  • Explain how to create this for Filters only or Search only
The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.
Get the Source Code: All 113 Premium Examples for $99