Use a custom operator on FilterForm
Is it possible to expand FilterForm to allow other types of operators like using
ilike
or <%
during filtering?
I believe that this item will give a solution for that https://github.com/ash-project/ash/issues/374 but AFAIK this is not done yet.
So, for now is there a workaround?GitHub
Custom predicates & operators · Issue #374 · ash-project/ash
These would be exposed to the expression syntax in code, and can be made available over api extensions as well. I'm thinking something like this: support a custom configured list of functions t...
8 Replies
You can add calculations to the resource and filter on the calculation
The filterform supports “arguments” which are the arguments on the calculation.
Can you give me an example on how to use these arguments? This is what I tried but i can't figure out how to pass the argument to the filter form:
If you want to provide arguments when you
add_predicate
that might take a small addition to AshPhoenix.FilterForm
but inside the predicate form would do something like this:
We'd need to add an opt here like
:arguments
https://github.com/ash-project/ash_phoenix/blob/v1.2.13/lib/ash_phoenix/filter_form/filter_form.ex#L914GitHub
ash_phoenix/filter_form.ex at v1.2.13 · ash-project/ash_phoenix
https://hexdocs.pm/ash_phoenix. Contribute to ash-project/ash_phoenix development by creating an account on GitHub.
I can try to create a PR for this, but I'm not sure what the opt
:arguments
would take, the argument, at least for the calculation I did, should be the value that the user is typing in the input anywayGot it, then you just need to add the predicate, and then when rendering that predicate you'd add inputs for the arguments
Yeah, I can't figure out how exactly I should be doing that.. I tried adding the component value inside the arguments struct manually:
But this doesn't work, not only seems like a very ugly hack, but it will also keep the
:and
operator and make the query break when running it. 🤔🤔 So there isn't a way to do it programatically like I mentioned (that would need to be added to the filter form
add_predicate
)
What you would be doing is adding them as inputs in the html form