petecoop / filament-toolbar-filters
Lift selected Filament table filters into the toolbar.
Package info
github.com/petecoop/filament-toolbar-filters
pkg:composer/petecoop/filament-toolbar-filters
Requires
- php: ^8.3
- filament/filament: ^5.0
- illuminate/support: ^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^11.0
- pestphp/pest: ^5.0
- pestphp/pest-plugin-laravel: ^5.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Move selected filters into the toolbar.
There have been a few attempts for more configurable filters in Filament e.g. #20150. And it looks like it will get an official implementation in #20140, until then this is my implementation to relocate a few filters.
Installation
composer require petecoop/filament-toolbar-filters
Add the plugin to your Panel:
use Petecoop\FilamentToolbarFilters\ToolbarFiltersPlugin; public function panel(Panel $panel): Panel { return $panel // ... ->plugin(ToolbarFiltersPlugin::make()); }
Usage
Define your filters normally and choose which ones to display in the toolbar using toolbarFilters.
use Filament\Tables\Filters\Filter; return $table ->columns([ // ... ]) ->filters([ Filter::make('is_verified') ->label('Verified') ->toggle() ->query(static fn (Builder $query): Builder => $query->whereNotNull('email_verified_at')), Filter::make('another_filter'), ]) ->toolbarFilters(['is_verified']);
Position
The default is TablesRenderHook::TOOLBAR_GROUPING_SELECTOR_AFTER, inside the
start of the toolbar after the grouping selector. It works when search is absent
as well. You can choose another hook when registering the panel plugin:
use Filament\Tables\View\TablesRenderHook; ToolbarFiltersPlugin::make() ->renderHook(TablesRenderHook::TOOLBAR_SEARCH_BEFORE)
Use a hook inside the table toolbar.
Current constraints
- The macro sets all table filters to apply immediately (
deferFilters(false)). A deferred menu combined with immediate toolbar filters is not supported. - The macro uses
filtersFormSchema()andfiltersTriggerAction()internally. Custom callbacks for these methods are not currently supported: callbacks set beforetoolbarFilters()are replaced, and callbacks set afterwards replace the plugin's callbacks. This can break toolbar rendering and indicator suppression, or leave an empty filter menu trigger visible.