RadzenDataGrid and FilterTemplate wont filter first time #242

Closed
opened 2026-01-29 17:34:05 +00:00 by claunia · 1 comment
Owner

Originally created by @carlberg74 on GitHub (Nov 10, 2021).

Describe the bug
Using Radzen.Blazor 3.11.12
In a RadzenDataGrid column, using ex. RadzenDatePicker in FilterTemplate to allow users to select a date, filter don't occur first time.
User selects a date and nothing happends, user then select the same date again or click or trigger event like order or filter and filter take effect.

To Reproduce
This example reproduces the issue.
Select a date and see that did not filter, and then select the same date again and see the filter occur as expected.
Id_1 and Id_2 works as expected.
Id_2 is just to use the data Template to see if that had any effect..
Id_3 and Date dont work as expected.

@data.Id
    <RadzenDataGridColumn TItem="DataRow" Property="Timestamp" Title="Date" FilterOperator="FilterOperator.GreaterThan" FilterValue="@_timestampFilter" FormatString="{0:yyyy-MM-dd HH:mm}" Width="50px">
        <FilterTemplate>
            <RadzenDatePicker @bind-Value="@_timestampFilter" DateFormat="yyyy-MM-dd" Change="@OnChange" />
        </FilterTemplate>
    </RadzenDataGridColumn>
</Columns>

@code {
RadzenDataGrid _grid;
List _rows;
DateTimeOffset _timestampFilter;
string _idFilter;

protected override async Task OnInitializedAsync()
{
    _rows = new List<DataRow>();
    for (int i = 0; i < 10; i++)
    {
        _rows.Add(new DataRow()
        {
            Id = i,
            Timestamp = DateTimeOffset.Now.AddDays(i)
        });
    }
}   
void OnChange()
{
    _grid.Reload();
}

class DataRow
{
    public int Id { get; set; }
    public DateTimeOffset Timestamp { get; set; }
}

}

Originally created by @carlberg74 on GitHub (Nov 10, 2021). **Describe the bug** Using Radzen.Blazor 3.11.12 In a RadzenDataGrid column, using ex. RadzenDatePicker in FilterTemplate to allow users to select a date, filter don't occur first time. User selects a date and nothing happends, user then select the same date again or click or trigger event like order or filter and filter take effect. **To Reproduce** This example reproduces the issue. Select a date and see that did not filter, and then select the same date again and see the filter occur as expected. Id_1 and Id_2 works as expected. Id_2 is just to use the data Template to see if that had any effect.. Id_3 and Date dont work as expected. <div style="margin: 25px;"> <RadzenDataGrid AllowFiltering="true" AllowColumnResize="true" FilterMode="FilterMode.Simple" PageSize="50" AllowPaging="true" AllowSorting="true" Data="@_rows" TItem="DataRow" @ref="_grid" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" LogicalFilterOperator="LogicalFilterOperator.And"> <Columns> <RadzenDataGridColumn TItem="DataRow" Property="Id" Title="ID_1" Width="30px" TextAlign="TextAlign.Center" /> <RadzenDataGridColumn TItem="DataRow" Property="Id" Title="ID_2" Width="30px" TextAlign="TextAlign.Center"> <Template Context="data"> <!-- this just to remove the stupid tooltip that only shows the value of the cell, would be nice to have a property to turn this off.. :) --> <div title=""> @data.Id </div> </Template> </RadzenDataGridColumn> <RadzenDataGridColumn TItem="DataRow" Property="Id" Title="ID_3" Width="30px" TextAlign="TextAlign.Center" FilterValue="_idFilter"> <FilterTemplate> <RadzenTextBox @bind-Value="@_idFilter" Change="@OnChange" /> </FilterTemplate> </RadzenDataGridColumn> <RadzenDataGridColumn TItem="DataRow" Property="Timestamp" Title="Date" FilterOperator="FilterOperator.GreaterThan" FilterValue="@_timestampFilter" FormatString="{0:yyyy-MM-dd HH:mm}" Width="50px"> <FilterTemplate> <RadzenDatePicker @bind-Value="@_timestampFilter" DateFormat="yyyy-MM-dd" Change="@OnChange" /> </FilterTemplate> </RadzenDataGridColumn> </Columns> </RadzenDataGrid> </div> @code { RadzenDataGrid<DataRow> _grid; List<DataRow> _rows; DateTimeOffset _timestampFilter; string _idFilter; protected override async Task OnInitializedAsync() { _rows = new List<DataRow>(); for (int i = 0; i < 10; i++) { _rows.Add(new DataRow() { Id = i, Timestamp = DateTimeOffset.Now.AddDays(i) }); } } void OnChange() { _grid.Reload(); } class DataRow { public int Id { get; set; } public DateTimeOffset Timestamp { get; set; } } }
Author
Owner

@enchev commented on GitHub (Nov 10, 2021):

The binding is not updated yet at the time Reload() is executed. You can do:

    bool reload = false;
    void OnChange()
    {
        reload = true;
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (reload)
        {
            reload = false;
            await _grid.Reload();
        }

        await base.OnAfterRenderAsync(firstRender);
    }
@enchev commented on GitHub (Nov 10, 2021): The binding is not updated yet at the time Reload() is executed. You can do: ``` bool reload = false; void OnChange() { reload = true; } protected override async Task OnAfterRenderAsync(bool firstRender) { if (reload) { reload = false; await _grid.Reload(); } await base.OnAfterRenderAsync(firstRender); } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#242