-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional filters and allow_nil #283
Comments
You are doing it right as far as I know ruby. Fortunately, ruby is not javascript and doesn't distinguish between I don't know any better solution than you have because only |
Would you be open to change to this? I could try implementing something that keeps track of which filters are set from params / defaults, and which are not. |
I am open to a good change. It would be ideal if you form your proposal here before "implementing something" that may not look good at the end. |
I've had just a cursory glance of the source, so it's only a vague idea at the moment. I'm thinking along the lines of modifying Since it's a breaking change, and possibly not very obvious one at that, you'd have to enable the behaviour on a per-filter basis with a new option, or a top-level opt-in (my preference). If this sounds about right, I'll spend some more time getting to know the existing codebase, and then formulate a more concrete proposal. |
I don't see a way to make it work without some conventions: you need to define a special value that you will treat as There is a The idea that filter value may return something different from the type specified in filter definition is hard to understand for general user who is familiar with datagrid internals. The thing we can do in you case is apply a cosmetics like in your
Overall I don't see a generalization of this for each filter type yet. |
I've ran into a specific case - I'd like to allow for one of the filter values to be
nil
, but also for that filter to not be ran.My use case is running dynamically constructed filters through datagrid instances to fetch data. For example, let's assume we have
UsersGrid
that allows filtering byreferrer_id
.Given following params, I'd like to select:
{}
- all users, as referrer is of no concern here;{ referrer_id: nil }
- only those users that are not referred by anyone;{ referrer_id: 123 }
- only those with specific referrer value.Currently, datagrid can't seem to distinguish between 1 & 2, because the attribute reader would return
nil
in both cases.My current workaround is to set the default to some invalid value, and then skip filter when encountering that value:
Am I missing some better way to handle this case?
The text was updated successfully, but these errors were encountered: