F
Filamentβ€’2mo ago
Philipp

Inject custom filters in render hook TOOLBAR_START

Dear all, I want to add some custom filter tabs in the table builder on the line left of the search field. They should serve as something like a quick filter for my users. I found already that the only way to inject something in that place is via render hooks. I was able to successfully add the render hook by injecting the html via a ServiceProvider, like so:
FilamentView::registerRenderHook(
TablesRenderHook::TOOLBAR_START,
fn(): string => 'Here goes HTML for the quick filters',
);
FilamentView::registerRenderHook(
TablesRenderHook::TOOLBAR_START,
fn(): string => 'Here goes HTML for the quick filters',
);
Because I have many different table builders across my application, I would like to add those quick filters not through the central ServiceProvider, but instead right where the Table component is used. I tried doing it table(), but failed, because nothing like this exists πŸ™‚
public static function table(Table $table): Table {
$table
->addRenderHook() // something like this does not exist
->columns([])
...
}
public static function table(Table $table): Table {
$table
->addRenderHook() // something like this does not exist
->columns([])
...
}
Next stop was registering the render hook in mount().
public function mount()
{
FilamentView::registerRenderHook(
TablesRenderHook::TOOLBAR_START,
function(): string {
return \Illuminate\Support\Facades\View::make('components.test')->render();
},
scopes: [static::class]
);
}
public function mount()
{
FilamentView::registerRenderHook(
TablesRenderHook::TOOLBAR_START,
function(): string {
return \Illuminate\Support\Facades\View::make('components.test')->render();
},
scopes: [static::class]
);
}
It works, kind of, but it just doesn't feel right. So my question: Can anybody point me in the right direction? How are you solving this? Please note: I am using Table Builder as a standalone component, not with full Filament. That removes the option of using this approach: https://filamentphp.com/docs/3.x/panels/resources/listing-records#using-tabs-to-filter-the-records. Also, for layout reasons, I really want to use the space next to the table search bar and not something that goes above the table.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server