Unable to filter on DateTime (DateTimeOffset) due to error: Object must implement IConvertible

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?


3 Replies

RN Rahul Narayanasamy Syncfusion Team July 8, 2021 12:56 PM UTC

Hi Brendan,  

Greetings from Syncfusion. 

Query:  Unable to filter on DateTime (DateTimeOffset) due to error: Object must implement IConvertible 

We have checked your query and we have confirmed it as a bug and logged the defect report “Problem with Date column filtering when date field type as DateTimeOffset” for the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our upcoming bi-weekly release which is expected to be rolled out on or before mid of August, 2021. 
      
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.   
     

Until then we appreciate your patience.  

Regards,  
Rahul  



RN Rahul Narayanasamy Syncfusion Team October 4, 2021 01:28 PM UTC

Hi Brendan,    

Sorry for the inconvenience caused.    

Due to some unforeseen circumstances, we could not able to include the fix for this issue “Problem with Date column filtering when date field type as DateTimeOffset” in our mentioned weekly release. But we have planned to include the fix for this issue in our upcoming bi-weekly release which is expected to be rolled out on or before the mid of October, 2021.    

You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.          
      

We will update you once the issue was fixed. Until then we appreciate your patience.    

Regards,    
Rahul   
 



RN Rahul Narayanasamy Syncfusion Team November 9, 2021 06:04 AM UTC

Hi Brendan,    
  
We are glad to announce that our latest release(19.3.0.48) has been successfully rolled out. We have included the fix for this issue “Problem with Date column filtering when date field type as DateTimeOffset” in our latest version release. So please upgrade to our latest version to resolve the problem. 
 
 
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.    
     
Regards,               
Rahul 
 


Loader.
Up arrow icon