Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ralphmrivera's avatar

Determining the state of filters in order to customize emptyState() messages in Filament.

Hi,

I'm trying to customize the ->emptyStateDescription() and ->emptyStateHeading() messages in a Filament table based on whether or not filters are active. If there are no filters active, I want to guide the user to create a new record if their record does not exist. But if a filter is active, I want to guide them to change their filters before creating a new record.

Currently, I'm using a single view, like this:

->emptyStateHeading(fn() => new HtmlString(view('empty-state-heading')))
->emptyStateDescription(fn() => new HtmlString(view('empty-state-description')))

However, I don't know how to check if any filters are enabled.

0 likes
1 reply
LaryAI's avatar
Level 58

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.

Please or to participate in this conversation.