I need to apply a filter from my code to a DateTime column in a RadZenDataGrid using ColumnsCollection. This works perfectly for string and int types, for example, but I can't seem to get it to work for the DateTime type.
I can’t figure out the expected type and format for the FilterValue property in this case. I’m using FilterOperator.Equals for the ad hoc property. I’ve tried a direct assignment like
col.FilterValue = myDateTimeVar;
or
col.SetFilterValue(myDateTimeVar);
but neither method yields the correct result.
It seems that the resulting args.Filters string passed to LoadData by the RadzenDataGrid component is not interpreted correctly during the Linq filtering process when dealing with a DateTime column.
Does anyone have any feedback on this situation?
Regards
Use SetFilterValueAsync() instead of direct assignment, and consider using FilterOperator.GreaterThanOrEquals with a date range instead of FilterOperator.Equals for DateTime columns since FilterOperator.Equals does exact DateTime comparison including time component.
Thank you for the clarification.
I was able to achieve my goal with the code below, though I should mention that my objective was to compare timestamps with second precision only!
I hadn’t been able to perform an equality comparison, likely due to the DateTime format and the conversions performed behind the scenes by the Radzen component—converting DateTime to text and/or vice versa—to generate the Linq filtering code that I retrieve in LoadData. This likely populates DateTime properties beyond the second property level, causing the comparison to fail.
In the range approach proposed by @Enchev, a naive approach using the GreaterThanOrEquals and LessThanOrEquals operators doesn’t work either, likely for the same reason. So I use strict LessThan for the second operator parameter and add a second to the target date.
For second-level precision, this works perfectly !
I noticed that the SetFilterValueAsync() method triggers a Reload() of the grid, so LoadData is called twice.
@Enchev, do you think there is a major drawback to using the non-async method SetFilterValue() followed by grid.Reload() just once?