Add tablefilter to querystring programatically
I haven't found a solution in the discussions or discord yet.
My goal is to have some buttons above the table which should prefill the table filters. And update also the querystring.
I don't want to use the querystring direclty (href to some url with the querystring). I would like to use some methods from the HasFilters trait. But I couldn't find a proper one. I only found removeTableFilter but am searching for like addTableFilter.
Is there another way of prefilling the table filters to build multiple "sets" for some quick buttons above the table?
Solution:Jump to solution
If you're on Filament v3 you can look at Tabs. https://filamentphp.com/docs/3.x/panels/resources/listing-records#using-tabs-to-filter-the-records
13 Replies
Or is there no easy way and I have to use something like this: https://filamentphp.com/plugins/kenneth-sese-filter-sets
?
Filament
Filter Sets by Kenneth Sese - Filament
Let your users combine their filters, searches, column order, and more into convenient and easily accessible filter sets.
The thing is I don't need to let the user build their own filter sets. I only need 3-4 static ones for all
to be more specific: I want to use getTableHeaderActions() method and add an action which prefills some filter form elements.
Solution
If you're on Filament v3 you can look at Tabs. https://filamentphp.com/docs/3.x/panels/resources/listing-records#using-tabs-to-filter-the-records
Just FYI, you don't need to allow users to create their own filter sets. You can define them like you want and not let users make their own
I'll also mention that Filament Tabs doesn't fill out the filters for you. It just scopes the eloquent query. That may be enough for your needs, but I'll add that Filter Sets v3 I'll be releasing soon will also allow you to define filters you want to show up in the filters form.
Hi thanks for your quick respond. Yes I just bought the plug-in , because I need favorites in other scenarios .
Yes I just read that developer filters won‘t set the filters , only the scopes.
But when I add global user filters for all it will sync with the filters right?
Great , time for me to switch to filament 3 then 😂
Oh that was you! hahaha!
Correct...Global user filters will sync with the filters
Then you can disable filter set creation if you don't want the user to be able to create
Thanks for the plug-in though.
Just had some trouble because I come from a legacy project which shifted to laravel 10 and my user_id was still unsignedInteger instead of bigInt 😅
And as I mentioned in v3 I hope to release soon, you'll be able to do filter sets in code but ALSO set filters to sync with the form
no hurry , it will take me some time to shift to filament 3 😜
I‘ll mark this thread as answered as you mentioned the tabs and gave more hints on your package. Thank you a lot !
ahh...legacy...always fun
Oh and since you're on Filament v2, it might be easier to refer to Filter Sets v1 docs: https://v2.filamentphp.com/plugins/filter-sets
Filament
Filter Sets by Kenneth Sese - Plugins - Filament
Filter Sets lets your users save their filters, search queries, column order, and more into easily accessible filter sets
Thanks again. Didn’t find the correct link first 🙏
And time for me to scroll through your code to see how you did it ☺️
good luck with that! 😬 🤣