Issue when initial filter in column is translated to odata #1704

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

Originally created by @javierlatorrep on GitHub (Apr 8, 2025).

Describe the bug
When trying to apply an initial filter to a column in the datagrid when using oData, the final filter doesn't seem to be accepted by oData, producing the request to fail giving a 400 bad request error.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://blazor.radzen.com/datagrid-odata?theme=material3
  2. Click on 'Edit source' and paste the following example.
@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind

<RadzenDataGrid 
    @ref="grid"
    KeyProperty="EmployeeID"
    IsLoading="@isLoading"
    Count="@count"
    Data="@employees"
    LoadData="@LoadData"
    FilterPopupRenderMode="PopupRenderMode.OnDemand"
    FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
    FilterMode="FilterMode.Advanced"
    AllowSorting="true"
    AllowFiltering="true"
    AllowPaging="true"
    PageSize="4"
    PagerHorizontalAlign="HorizontalAlign.Center"
    ColumnWidth="200px"
>
    <Columns>
        <RadzenDataGridColumn 
            Property="@nameof(Employee.EmployeeID)"
            Filterable="true" 
            FilterProperty="@nameof(Employee.EmployeeID)"
            FilterValue=@filteredIds 
            FilterOperator=@FilterOperator.Contains 
            Title="Id" 
            TextAlign="TextAlign.Center" 
        />
        <RadzenDataGridColumn Property="@nameof(Employee.FirstName)" Title="First Name">
            <EditTemplate Context="employee">
                <RadzenTextBox @bind-Value="employee.FirstName" />
            </EditTemplate>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

@code {
    bool isLoading;
    int count;
    ODataEnumerable<Employee> employees;
    RadzenDataGrid<Employee> grid;

    IEnumerable<int> filteredIds;

    NorthwindODataService service = new NorthwindODataService("https://services.radzen.com/odata/Northwind/");

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        // Setting an initial filter. 
        // Expecting in datagrid appearing only employees with id 1 and 2.
        filteredIds = new List<int> {1,2};
    }

    async Task LoadData(LoadDataArgs args)
    {
        isLoading = true;

        var result = await service.GetEmployees(filter: args.Filter, top: args.Top, skip: args.Skip, orderby: args.OrderBy, count: true);

        employees = result.Value.AsODataEnumerable();

        count = result.Count;

        isLoading = false;
    }
}
  1. Run the code
  2. See error in the console:

Image

Expected behavior
The datagrid data should appear filtered by Id, only showing two results. The datagrid filter should be enabled by Id field, allowing the user to update the current filter if necessary.

Desktop (please complete the following information):

  • OS: Microsoft Windows 11
  • Browser Edge Version 135.0.3179.54 (Official build) (64-bit)
  • Radzen Version: 6.4.1
Originally created by @javierlatorrep on GitHub (Apr 8, 2025). **Describe the bug** When trying to apply an initial filter to a column in the datagrid when using oData, the final filter doesn't seem to be accepted by oData, producing the request to fail giving a 400 bad request error. **To Reproduce** Steps to reproduce the behavior: 1. Go to [https://blazor.radzen.com/datagrid-odata?theme=material3](https://blazor.radzen.com/datagrid-odata?theme=material3) 2. Click on 'Edit source' and paste the following example. ``` @using RadzenBlazorDemos.Data @using RadzenBlazorDemos.Models.Northwind <RadzenDataGrid @ref="grid" KeyProperty="EmployeeID" IsLoading="@isLoading" Count="@count" Data="@employees" LoadData="@LoadData" FilterPopupRenderMode="PopupRenderMode.OnDemand" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterMode="FilterMode.Advanced" AllowSorting="true" AllowFiltering="true" AllowPaging="true" PageSize="4" PagerHorizontalAlign="HorizontalAlign.Center" ColumnWidth="200px" > <Columns> <RadzenDataGridColumn Property="@nameof(Employee.EmployeeID)" Filterable="true" FilterProperty="@nameof(Employee.EmployeeID)" FilterValue=@filteredIds FilterOperator=@FilterOperator.Contains Title="Id" TextAlign="TextAlign.Center" /> <RadzenDataGridColumn Property="@nameof(Employee.FirstName)" Title="First Name"> <EditTemplate Context="employee"> <RadzenTextBox @bind-Value="employee.FirstName" /> </EditTemplate> </RadzenDataGridColumn> </Columns> </RadzenDataGrid> @code { bool isLoading; int count; ODataEnumerable<Employee> employees; RadzenDataGrid<Employee> grid; IEnumerable<int> filteredIds; NorthwindODataService service = new NorthwindODataService("https://services.radzen.com/odata/Northwind/"); protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); // Setting an initial filter. // Expecting in datagrid appearing only employees with id 1 and 2. filteredIds = new List<int> {1,2}; } async Task LoadData(LoadDataArgs args) { isLoading = true; var result = await service.GetEmployees(filter: args.Filter, top: args.Top, skip: args.Skip, orderby: args.OrderBy, count: true); employees = result.Value.AsODataEnumerable(); count = result.Count; isLoading = false; } } ``` 4. Run the code 5. See error in the console: ![Image](https://github.com/user-attachments/assets/777052db-0b09-4df3-972c-ee7f75f4d984) **Expected behavior** The datagrid data should appear filtered by Id, only showing two results. The datagrid filter should be enabled by Id field, allowing the user to update the current filter if necessary. **Desktop (please complete the following information):** - OS: Microsoft Windows 11 - Browser Edge Version 135.0.3179.54 (Official build) (64-bit) - Radzen Version: 6.4.1
Author
Owner

@enchev commented on GitHub (Apr 9, 2025):

There are multiple problems with this code - here is a working version:

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind

<RadzenDataGrid @ref="grid"
                KeyProperty="EmployeeID"
                IsLoading="@isLoading"
                Count="@count"
                Data="@employees"
                LoadData="@LoadData"
                FilterPopupRenderMode="PopupRenderMode.OnDemand"
                FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                FilterMode="FilterMode.CheckBoxList"
                AllowSorting="true"
                AllowFiltering="true"
                AllowPaging="true"
                PageSize="4"
                PagerHorizontalAlign="HorizontalAlign.Center"
                ColumnWidth="200px">
    <Columns>
        <RadzenDataGridColumn Property="@nameof(Employee.EmployeeID)"
                              Filterable="true"
                              FilterProperty="@nameof(Employee.EmployeeID)"
                              FilterOperator=@FilterOperator.Contains
                              Title="Id"
                              TextAlign="TextAlign.Center" />
        <RadzenDataGridColumn Property="@nameof(Employee.FirstName)" Title="First Name">
            <EditTemplate Context="employee">
                <RadzenTextBox @bind-Value="employee.FirstName" />
            </EditTemplate>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

@code {
    bool isLoading;
    int count;
    ODataEnumerable<Employee> employees = Enumerable.Empty<Employee>().AsODataEnumerable();
    RadzenDataGrid<Employee> grid;

    IEnumerable<int> filteredIds;

    NorthwindODataService service = new NorthwindODataService("https://services.radzen.com/odata/Northwind/");

    async Task LoadData(LoadDataArgs args)
    {
        isLoading = true;

        var result = await service.GetEmployees(filter: args.Filter, top: args.Top, skip: args.Skip, orderby: args.OrderBy, count: true);

        employees = result.Value.AsODataEnumerable();

        count = result.Count;

        isLoading = false;
    }

    protected override Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            var column = grid.ColumnsCollection.Where(c => c.Property == "EmployeeID").FirstOrDefault();

            if (column != null)
            {
                // Setting an initial filter.
                // Expecting in datagrid appearing only employees with id 1 and 2.
                filteredIds = new List<int> { 1, 2 };

                column.SetFilterValue(filteredIds);

                grid.Reload();
            }
        }

        return base.OnAfterRenderAsync(firstRender);
    }
}

Image

@enchev commented on GitHub (Apr 9, 2025): There are multiple problems with this code - here is a working version: ``` @using RadzenBlazorDemos.Data @using RadzenBlazorDemos.Models.Northwind <RadzenDataGrid @ref="grid" KeyProperty="EmployeeID" IsLoading="@isLoading" Count="@count" Data="@employees" LoadData="@LoadData" FilterPopupRenderMode="PopupRenderMode.OnDemand" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterMode="FilterMode.CheckBoxList" AllowSorting="true" AllowFiltering="true" AllowPaging="true" PageSize="4" PagerHorizontalAlign="HorizontalAlign.Center" ColumnWidth="200px"> <Columns> <RadzenDataGridColumn Property="@nameof(Employee.EmployeeID)" Filterable="true" FilterProperty="@nameof(Employee.EmployeeID)" FilterOperator=@FilterOperator.Contains Title="Id" TextAlign="TextAlign.Center" /> <RadzenDataGridColumn Property="@nameof(Employee.FirstName)" Title="First Name"> <EditTemplate Context="employee"> <RadzenTextBox @bind-Value="employee.FirstName" /> </EditTemplate> </RadzenDataGridColumn> </Columns> </RadzenDataGrid> @code { bool isLoading; int count; ODataEnumerable<Employee> employees = Enumerable.Empty<Employee>().AsODataEnumerable(); RadzenDataGrid<Employee> grid; IEnumerable<int> filteredIds; NorthwindODataService service = new NorthwindODataService("https://services.radzen.com/odata/Northwind/"); async Task LoadData(LoadDataArgs args) { isLoading = true; var result = await service.GetEmployees(filter: args.Filter, top: args.Top, skip: args.Skip, orderby: args.OrderBy, count: true); employees = result.Value.AsODataEnumerable(); count = result.Count; isLoading = false; } protected override Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { var column = grid.ColumnsCollection.Where(c => c.Property == "EmployeeID").FirstOrDefault(); if (column != null) { // Setting an initial filter. // Expecting in datagrid appearing only employees with id 1 and 2. filteredIds = new List<int> { 1, 2 }; column.SetFilterValue(filteredIds); grid.Reload(); } } return base.OnAfterRenderAsync(firstRender); } } ``` ![Image](https://github.com/user-attachments/assets/99e53621-c681-45c3-b9b9-b8eb45fac088)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1704