odata-fluent-query
odata-fluent-query copied to clipboard
Let null or undefined into filter expressions
Can you consider letting to pass null or undefined into FilterXXX methods, in which case filter should turn into no operation.
In this case following query.filter(t => t.date.equals(myDate)) will add date filter, provided myDate has a value.
Hey, sorry for the delay!
Wouldn't it work if your model is of type Date | null?
In my case myDate value is of type Date|null|undefined.
My goal was to conditionally add filters.
It is not the same as to compare value against null or undefined.
With suggested feature one could compose filters like:
...
filter(t => t.x.equals(myX)).
filter(t => t.y.equals(myY))
...
At present I have to write:
if (myX != null)
{
query = query.filter(t => t.x.equals(myX));
}
if (myY != null)
{
query = query.filter(t => t.y.equals(myY));
}
Sorry, it's a bit confusing. Do you want to return null inside the filter function to not include the filter? Something like:
query.filter(t => myX ? t.x.equals(myX) : null)
And if it returns null it should be ignored?
Yes, something like this.
Consider, that I have some form fields, and I want to filter my results by only those I explicitly filled with values.
So, to build query I somehow need to ignore some of filters.
Ultimately: query.filter(t => t.x.equals(myX)) could beheave is if no any filter applied if myX === undefined
@vnesterovsky I want to take a deeper look into this, do you think you can share a stackblitz or github project reproducing this?