Pass function inside table filters().
Is it possible to pass a function that returns array inside the ->filters() since my filters are dynamic.
16 Replies
No... but maybe you can implement dynamic filters by overriding
getTableFilters()
on your page class instead. Never tried but I'm curious.This is a v2 question
V2 docs the same
I understand... What do you think can be useful on this page to solve the issue?
You may customize the database query that retrieves options using the third parameter of the relationship() method..
@alexander7479 @pboivin Sorry to say but i don't really understand .Could you elaborate?
Create model relationship, then use this relationship in filter and also customize the query..
Okay, let me work it out.Thank you.
Can you describe how your filters are dynamic? What changes according to what...
I have a utilities table ( eg gym,internet,garbage etc ) This utilities can be CRUDed .I want to have filters for each of this so that if the active utility is say garbage, the tenants table should now filter tenants who have this utility.
So at first, the 'tenant' filter is not visible and if I select a value in the 'utility' filter, then the 'tenant' filter appears?
Or is it the values that change? All filters are visible but when I select 'internet', the values in the 'tenant' select are limited to the tenants that have internet?
Yes sure the second option * All filters are visible but when I select 'internet', the values in the 'tenant' select are limited to the tenants that have internet? *
@pboivin Sorry for responding late.Had internet challenges.
@lodeki No worries. I'm not sure you'll be able to do this with
relationship()
... I have a feeling that a custom filter form will give you more flexibility :
https://beta.filamentphp.com/docs/2.x/tables/filters#custom-filter-formsI used the SelectFilter . It did the trick .Thank you.