I am seeing an issue when attempting to filter on a DateTime (or DateTimeOffset) field, where using the Url Adaptor with a Grid.
Here's how the Grid is defined:
<SfGrid @ref="Grid" AllowPaging="true" AllowResizing="true" AllowReordering="true" AllowFiltering="true" AllowSorting="true" AllowMultiSorting="true" Height="100%" TValue="CommandItem" Toolbar="@(new List<string>() { "ExcelExport", "ColumnChooser" })" ShowColumnChooser="true" AllowExcelExport="true">
<SfDataManager Url="@_gridUrl" CrossDomain="true" Adaptor="Adaptors.UrlAdaptor"> </SfDataManager> <GridPageSettings PageCount="5" PageSizes="@AppDefaults.DataGridPageSizes" PageSize="50"> </GridPageSettings>
<GridFilterSettings Type ="Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings> <GridColumns>
<GridColumn Field=@nameof(CommandItem.CommandId) HeaderText="Id" Width="300">
</GridColumn>
<GridColumn Field=@nameof(CommandItem.CreatedOn) HeaderText="Created" Type="ColumnType.Date" Format="dd/MM/yyyy HH:mm:ss tt"></GridColumn>In the rendered UI, I can see the date rendered correctly, and I can also define the filter:The Created column has the right date, and if I open the filter menu, I can set a filter (say, Greater Than 20/06/2021):
On the API side (.NET 5), I have this as the controller action:
[HttpPost]
[Route("ui/list2")]
public async Task<GridResult<CommandItem>> GetCommandsForGridAsync([FromBody] DataManagerRequest model)
{
var q = _dbContext.CommandResults.AsQueryable();
if (model.Where != null)
{
q = QueryableOperation.PerformFiltering(q, model.Where, model.Where[0].Condition);
}
// other stuff
// then return the response
}And this is what the browser is posting to the controller action:
No matter what I do (DateTime or DateTimeOffset), whenever the CreatedOn date is in the Where "predicates" list on the request, I get the following error:
System.InvalidCastException: Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at Syncfusion.Blazor.Internal.SfBaseUtils.ChangeType(Object dataValue, Type conversionType, Boolean isClientChange)
at Syncfusion.Blazor.Data.QueryableOperation.PredicateBuilder[T](IQueryable`1 dataSource, List`1 whereFilter, String condition, ParameterExpression paramExpression, Type type)
at Syncfusion.Blazor.Data.QueryableOperation.PredicateBuilder[T](IQueryable`1 dataSource, List`1 whereFilter, String condition, ParameterExpression paramExpression, Type type)
at Syncfusion.Blazor.Data.QueryableOperation.PerformFiltering[T](IQueryable`1 dataSource, List`1 whereFilter, String condition)
at Project.Api.Core.Areas.v1.Core.CommandController.GetCommandsForGridAsync(DataManagerRequest model) in
In short, trying to perform an out-of-the-box filter on a DateTime (or DateTimeOffset - I have tried both) results in an exception "
Object must implement IConvertible
".
How does one filter by Dates in the Grid component, when using the UrlAdaptor?