I am using GridColumn configured in the following way:
<GridColumn Field=@nameof(CompletedView.Time) HeaderText="When" Type="ColumnType.DateTime" AutoFit="true"> ...
Where CompletedView.Time is a DateTimeOffset.
When filtering this column an exception occurs:
System.InvalidCastException: Unable to cast object of type 'System.DateTimeOffset' to type 'System.Nullable`1[System.DateTime]'.
at void Syncfusion.Blazor.Grids.Internal.FilterMenuRenderer<TContent>.BuildRenderTree(RenderTreeBuilder __builder)+(RenderTreeBuilder __builder3) => { }
at void Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(int sequence, RenderFragment fragment)
at void Syncfusion.Blazor.Popups.SfDialog.BuildRenderTree(RenderTreeBuilder __builder)+(RenderTreeBuilder __builder2) => { } [1]
at void Microsoft.AspNetCore.Components.CascadingValue<TValue>.Render(RenderTreeBuilder builder)
at void Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, out Exception renderFragmentException)
How do I bind a DateTimeOffset to the SfGrid? Thank you for any assistance you can provide.
Hi
Mike-E,
Before proceeding with the reporting problem, we require some additional
clarification from your end. Please share the below details to proceed further
at our end.
Above-requested details will be very helpful in validating the reported query at our end and providing a solution as early as possible. Thanks for your understanding.
Regards,
Prathap Senthil
Hi Prathap,
Thank you very much for your investigation and assistance. It would be quite a bit of work on my end to provide you a sample. Perhaps it is easier to ask you: have you been able to verify on your end that the grid works with DateTimeOffset as a property type using the GridColumn configuration as above?
Please note that I am using EntityFramework as the backend provider. I will see if I can get you a sample.
Thank you for any further assistance you can provide.
Here is the model used. It's the `Created` property that I am trying to filter on:
public sealed class SummaryView
{
public Guid Identity { get; init; }
public DateTimeOffset Created { get; set; }
public string Name { get; set; } = default!;
public Guid Author { get; set; }
public string AuthorName { get; set; } = default!;
public uint Purchaser { get; set; }
public string PurchaserName { get; set; } = default!;
public uint Seller { get; set; }
public string SellerName { get; set; } = default!;
public TransactionType Type { get; set; }
public decimal Value { get; init; }
}
For the column filter settings, this is being used:
new FilterSettings { Operator = Operator.GreaterThanOrEqual, Type = FilterType.Menu }
Hi @Prathap are you able to provide a sample with a filter between `DateTime?` and DateTimeOffset using the settings above? I can try seeing if I can reproduce it from there on my side if so. Thank you for your continued assistance.
Thanks for the patience.
We have confirmed that this an issue and logged a defect report titled “Exception
occurs when reopening menu filter for non-nullable DateTimeOffset column” This
fix will be included in our weekly patch release, which is expected to be
rolled out on July 1st , 2025. You can now track the status of your
request, review the proposed resolution timeline, and contact us for any
further inquiries through this link.
Exception
occurs when reopening menu filter for non-nullable DateTimeOffset column in
Blazor | Feedback Portal
Disclaimer: “Inclusion of this solution in
the weekly release may change due to other factors including but not limited to
QA checks and works reprioritization”
We will get back to you once the release is rolled out. Thanks for your
understanding.
Woohoo! Thank you so much for your patience as well @Prathap and team. I am so very happy that this was confirmed on your side and wasn't something particular about my codebase. I am glad to see that it will be fixed so quickly as well. Thank you again for all your efforts out there!
Hi Mike-E,
Welcome. We will get back to you once the release is rolled out. Until then we appreciate your patience.
Regards,
Monisha
Thanks for your patience,
We are glad to announce that, we have included the fix for the issue “Exception occurs when reopening menu filter for non-nullable DateTimeOffset column” in our 30.1.38 release. So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the NuGet package for the latest fixes and features below.
NuGet : https://www.nuget.org/packages/Syncfusion.Blazor.Grid
Root
cause
: Type casting done to convert to
DateTimeOffset.
Action Taken: Removed Casting and used the value
as it is always.
Great! Thank you so much Prathap for your efforts. I can confirm that filtering works as expected now. 👍
Hi Mike-E,
We are happy to hear that the provided solution was helpful. Please get back to us if you need any other assistance.
Regards,
Sanjay Kumar Suresh