RadzenDataGrid LoadDataArgs Filter DateTypeKind assumed #1786

Closed
opened 2026-01-29 17:58:35 +00:00 by claunia · 0 comments
Owner

Originally created by @pgodwin on GitHub (Jun 11, 2025).

Describe the bug
When a datetime field is filtered on the RadzenDataGrid, the expression converts it to Zulu time regardless of the specified kind. This results in DateTime.Date being converted to the current local timezone. In my case it's +10, so my dates come through as 10:00 AM.

Eg:
A filter of:
x => (x.Date.Date == DateTime.Parse("2025-06-11T00:00:00.000Z", CultureInfo.InvariantCulture))

Results in a date of 11/06/2025 10:00:00 AM being used in the filter.

To Reproduce
The following page reproduces the error - when filtering by date, the filter fails as it's converting the timezone. It does this no matter what the filtered value DateTimeKind is.

@page "/datefilter"
@using System.Linq.Dynamic.Core
@using System.Diagnostics
@using System.Globalization
<RadzenLabel Text="DateTimeKind:" />
<RadzenDropDown 
    @bind-Value="@SelectedKind" 
    TextProperty="Text" 
    ValueProperty="Value"
    Change=@(args => grid.Reload())
    Data="@(Enum.GetValues(typeof(DateTimeKind)).Cast<DateTimeKind>().Select(t => new { Text = $"{t}", Value = t }))" />

<RadzenDataGrid @ref="grid"
    TItem="TestData"
    Data="rows"
    AllowSorting="true"
    AllowFiltering="true"
    FilterMode="FilterMode.SimpleWithMenu"
    LoadData="LoadData">
    <Columns>
        <RadzenDataGridColumn Property="Id" Title="Id" />
        <RadzenDataGridColumn Title="Date"
            Property="Date.Date" 
            FilterProperty="Date.Date" 
            FilterValue="filteredDate?.Date">
            <FilterValueTemplate>
                <RadzenDatePicker @bind-Value="@filteredDate" 
                    DateFormat="d" 
                    ShowTime="false" 
                    Kind="@SelectedKind" />
            </FilterValueTemplate>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn Title="Title" Property="Title" />
    </Columns>
</RadzenDataGrid>
<RadzenLabel Text="Filtered Date Kind" />
<RadzenText Text="@filteredDate?.Kind.ToString()" />
<RadzenLabel Text="Last Filter" />
<RadzenText Text="@lastFilter" />
<RadzenLabel Text="Parsed Date" />
<RadzenText Text="@parsedDate?.ToString()" />
<RadzenLabel Text="Parsed Date Kind" />
<RadzenText Text="@parsedDate?.Kind.ToString()" />


@code {
    private class TestData
    {
        public int Id { get; set; }
        public DateTime Date { get; set; }
        public string Title { get; set; }
    }

    private RadzenDataGrid<TestData> grid;

    private DateTime? filteredDate;

    private List<TestData> rows;

    private List<TestData> initialData;

    private string? lastFilter;

    private DateTime? parsedDate;

    private DateTimeKind SelectedKind { get; set; } = DateTimeKind.Local;

    protected override void OnInitialized()
    {
        // Build our fake dataset
        initialData = Enumerable.Range(1, 25)
            .Select(i => new TestData
                {
                    Id = i,
                    Date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, i),
                    Title = $"Title {i}"
                })
            .ToList();
    }

    private async Task LoadData(LoadDataArgs args)
    {
        if (initialData == null)
            return;

        if (filteredDate != null)
        {
            // Parse the filtered date in the same way as the expression
            parsedDate = DateTime.Parse(filteredDate.Value.Date.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), CultureInfo.InvariantCulture);
        }
               
        this.lastFilter = args.Filter;
        
        await Task.Yield();

        var data = initialData.AsQueryable();

        if (!string.IsNullOrEmpty(args.Filter))
            data = data.Where(args.Filter);

        if (!string.IsNullOrEmpty(args.OrderBy))
            data = data.OrderBy(args.OrderBy);

        rows = data.ToList();
    }

    
}

Expected behavior

  • The filter expression should probably either respect the source DateTimeKind, or be explicit in setting it as UTC time.

Screenshots
Data with dates all at midnight:
Image

Filter on date 1-Jun-2025:

Image
Parsed date is 1-Jun-2025 10:00 AM rather than the expected 1-Jun-2025 00:00.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Edge
  • Version: 131.0.2903.146
Originally created by @pgodwin on GitHub (Jun 11, 2025). <!-- IMPORTANT: Read this first!!! 1. If you own a Radzen Professional or Еnterprise subscription you can report your issue or ask us a question via email at info@radzen.com. Radzen staff will reply within 24 hours (Professional) or 16 hours (Enterprise) 2. The Radzen staff guarantees a response to issues in this repo only to paid subscribers. 3. If you have a HOW TO question start a new forum thread in the Radzen Community forum: https://forum.radzen.com. Radzen staff will close issues that are HOWTO questions. 4. Please adhere to the issue template. Specify all the steps required to reproduce the issue or link a project which reproduces it easily (without requiring extra steps such as restoring a database). --> **Describe the bug** When a datetime field is filtered on the RadzenDataGrid, the expression converts it to Zulu time regardless of the specified kind. This results in DateTime.Date being converted to the current local timezone. In my case it's +10, so my dates come through as 10:00 AM. Eg: A filter of: `x => (x.Date.Date == DateTime.Parse("2025-06-11T00:00:00.000Z", CultureInfo.InvariantCulture))` Results in a date of `11/06/2025 10:00:00 AM` being used in the filter. **To Reproduce** The following page reproduces the error - when filtering by date, the filter fails as it's converting the timezone. It does this no matter what the filtered value DateTimeKind is. ```csharp @page "/datefilter" @using System.Linq.Dynamic.Core @using System.Diagnostics @using System.Globalization <RadzenLabel Text="DateTimeKind:" /> <RadzenDropDown @bind-Value="@SelectedKind" TextProperty="Text" ValueProperty="Value" Change=@(args => grid.Reload()) Data="@(Enum.GetValues(typeof(DateTimeKind)).Cast<DateTimeKind>().Select(t => new { Text = $"{t}", Value = t }))" /> <RadzenDataGrid @ref="grid" TItem="TestData" Data="rows" AllowSorting="true" AllowFiltering="true" FilterMode="FilterMode.SimpleWithMenu" LoadData="LoadData"> <Columns> <RadzenDataGridColumn Property="Id" Title="Id" /> <RadzenDataGridColumn Title="Date" Property="Date.Date" FilterProperty="Date.Date" FilterValue="filteredDate?.Date"> <FilterValueTemplate> <RadzenDatePicker @bind-Value="@filteredDate" DateFormat="d" ShowTime="false" Kind="@SelectedKind" /> </FilterValueTemplate> </RadzenDataGridColumn> <RadzenDataGridColumn Title="Title" Property="Title" /> </Columns> </RadzenDataGrid> <RadzenLabel Text="Filtered Date Kind" /> <RadzenText Text="@filteredDate?.Kind.ToString()" /> <RadzenLabel Text="Last Filter" /> <RadzenText Text="@lastFilter" /> <RadzenLabel Text="Parsed Date" /> <RadzenText Text="@parsedDate?.ToString()" /> <RadzenLabel Text="Parsed Date Kind" /> <RadzenText Text="@parsedDate?.Kind.ToString()" /> @code { private class TestData { public int Id { get; set; } public DateTime Date { get; set; } public string Title { get; set; } } private RadzenDataGrid<TestData> grid; private DateTime? filteredDate; private List<TestData> rows; private List<TestData> initialData; private string? lastFilter; private DateTime? parsedDate; private DateTimeKind SelectedKind { get; set; } = DateTimeKind.Local; protected override void OnInitialized() { // Build our fake dataset initialData = Enumerable.Range(1, 25) .Select(i => new TestData { Id = i, Date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, i), Title = $"Title {i}" }) .ToList(); } private async Task LoadData(LoadDataArgs args) { if (initialData == null) return; if (filteredDate != null) { // Parse the filtered date in the same way as the expression parsedDate = DateTime.Parse(filteredDate.Value.Date.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), CultureInfo.InvariantCulture); } this.lastFilter = args.Filter; await Task.Yield(); var data = initialData.AsQueryable(); if (!string.IsNullOrEmpty(args.Filter)) data = data.Where(args.Filter); if (!string.IsNullOrEmpty(args.OrderBy)) data = data.OrderBy(args.OrderBy); rows = data.ToList(); } } ``` **Expected behavior** * The filter expression should probably either respect the source DateTimeKind, or be explicit in setting it as UTC time. **Screenshots** Data with dates all at midnight: ![Image](https://github.com/user-attachments/assets/6853b153-5548-404e-998b-5700be9eb609) Filter on date 1-Jun-2025: ![Image](https://github.com/user-attachments/assets/4574b3c2-b1da-4e5b-9f35-3ebb2f1f5ba7) Parsed date is 1-Jun-2025 10:00 AM rather than the expected 1-Jun-2025 00:00. **Desktop (please complete the following information):** - OS: Windows 11 - Browser: Edge - Version: 131.0.2903.146
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1786