To determine if any filters are enabled in Filament, you can use the filters() method provided by the Filament\Tables\Concerns\HasFilters trait. This method returns an instance of Filament\Tables\Filters which has a hasFilters() method that you can use to check if any filters are active.
Here's an example of how you can customize the emptyState() messages based on the state of the filters:
use Filament\Tables\Concerns\HasFilters;
use Filament\Tables\Filters;
class YourTable extends Table
{
use HasFilters;
// ...
public function configureFilters(Filters $filters): void
{
// Configure your filters here
}
public function emptyStateHeading(): string
{
if ($this->filters()->hasFilters()) {
return 'Change your filters before creating a new record';
}
return 'Create a new record if it does not exist';
}
public function emptyStateDescription(): string
{
if ($this->filters()->hasFilters()) {
return 'Please modify your filters to find the desired records';
}
return 'Click the create button to add a new record';
}
}
In this example, we're using the hasFilters() method to check if any filters are active. If filters are active, we display a message guiding the user to change their filters. Otherwise, we display a message guiding the user to create a new record.
Make sure to replace YourTable with the actual name of your table class.