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

jmrufus's avatar

filamentphp filters

Hello.

I'm starting to use filters in filamentphp and I would like to know if there is a way to apply a filter and have it remain applied until it is removed manually even if I change sections.

Regards.

0 likes
5 replies
JeffreyW's avatar

Hello,

You can use session-based filtering. This will store the filter state in the session, allowing the filter to remain applied across page reloads or navigation within the application.

Here’s how you can achieve this:

  1. Define a filter in your Filament resource using the ->query() method. You can store the selected filter values in the session.

  2. To make sure the filter remains applied when you navigate, you can save the filter value in the session. This can be done by customizing your resource's query method or using the before or after hooks to check the session for filter states.

  3. Persist the filter state across sections. You can use JavaScript or Laravel session-based logic to store the selected filter values in the session. When you change sections, the session will remember the filter and apply it automatically.

To remove the filter, you can add a reset button or a clear filter option that will clear the session value for that filter, which can be handled by a route or an action.

Hope this helps

laithz's avatar

@JeffreyW Is there a widget specific setting to disable this? My dashboard is remembering the applied filters and I'd like to disable that.

jmrufus's avatar

Hi Jeffrey,

Thanks for your help.

Can you provide me with an example?

Best regards.

Merklin's avatar

In the boot method of your Panel service provider, you can set some default values for the filters like:

// Configure default options for table filters
        Table::configureUsing(function (Table $table): void {
            $table->persistFiltersInSession();
            $table->striped();
            $table->extremePaginationLinks();
            $table->filtersTriggerAction(fn (Action $action) => $action->button()->label(__('Filters')));
            $table->defaultSort('created_at', 'desc')->persistSortInSession();
            $table->filters([], layout: FiltersLayout::AboveContentCollapsible);
        });

this will apply these settings globally. If you want them in a particular Resource only, use the code again in that resource boot method. As for the original question, $table->persistFiltersInSession(); is what you need.

1 like

Please or to participate in this conversation.