RadzenDropDownDataGrid not applying rz-state-highlight when data is a mapped IEnumerable #1879

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

Originally created by @ivaano on GitHub (Oct 9, 2025).

Describe the bug
The RadzenDropDownDataGrid component does not apply the rz-state-highlight class to the selected item in the grid when the Data property is bound to a lazily evaluated IEnumerable resulting from a LINQ Select mapping (e.g., from a model to a DTO). The selected item is correctly displayed in the dropdown, but there is no visual indicator (highlight) in the grid. Materializing the IEnumerable to a List using .ToList() resolves the issue.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Blazor component with a RadzenDropDownDataGrid.
  2. Bind the Data property to an IEnumerable obtained from a LINQ Select operation that maps a model (e.g., Category) to a DTO (e.g., CategoryDto).
  3. Implement the LoadData event to asynchronously load data and perform the mapping.
  4. Set ValueProperty="Id", TextProperty="Name", and use @bind-Value to bind the selected value.
  5. Select an item from the dropdown.
  6. Observe that the selected item is displayed in the dropdown, but the rz-state-highlight class is not applied to the corresponding row in the grid.

Example code

@page "/testdrop"
@using System.Linq

<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.Center" Gap="0.5rem" class="rz-p-12">
    <RadzenLabel Text="Select Value" Component="Category" />
    <RadzenDropDownDataGrid
        Data="@_categories"
        TValue="int"
        LoadData="@LoadCategories"
        Count="@_categoriesCount"
        IsLoading="@_isLoadingCategories"
        AllowClear="true"
        AllowFiltering="true"
        TextProperty="Name"
        ValueProperty="Id"
        Name="Category"
        @bind-Value="CategoryId"
    />
</RadzenStack>

@code {
    IEnumerable<CategoryDto> _categories;
    private int _categoriesCount;
    private bool _isLoadingCategories;
    int CategoryId;

    private async Task LoadCategories(LoadDataArgs args)
    {
        _isLoadingCategories = true;
        await Task.Yield();
        
        var entities = GetData();
        var mappedData = entities.Select(MapEntityToDto);
        // var mappedData = entities.Select(MapEntityToDto).ToList(); // Fixes the issue
        
        _categories = mappedData;
        _categoriesCount = _categories.Count();
        _isLoadingCategories = false;
    }
    
    private CategoryDto MapEntityToDto(Category entity)
    {
        return new CategoryDto
        {
            Id = entity.Id,
            Name = entity.Name
        };
    }

    private IEnumerable<Category> GetData()
    {
        return
        [
            new Category { Id = 1, Name = "Appliance" },
            new Category { Id = 2, Name = "Electronics" },
            new Category { Id = 3, Name = "Betunias" }
        ];
    }

    public class Category
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public class CategoryDto
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

Expected behavior
The RadzenDropDownDataGrid should apply the rz-state-highlight class to the selected item's row in the grid, providing a visual indicator of the selection, regardless of whether the Data property is bound to a lazy IEnumerable or a materialized List.

Screenshots

Image

materializing the IEnumerable fixes the issue:

Image

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser chrome, firefox
  • Version 8.0.4

Additional context
Add any other context about the problem here.

Originally created by @ivaano on GitHub (Oct 9, 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** The `RadzenDropDownDataGrid` component does not apply the `rz-state-highlight` class to the selected item in the grid when the Data property is bound to a lazily evaluated IEnumerable<T> resulting from a LINQ Select mapping (e.g., from a model to a DTO). The selected item is correctly displayed in the dropdown, but there is no visual indicator (highlight) in the grid. Materializing the IEnumerable<T> to a List<T> using .ToList() resolves the issue. **To Reproduce** Steps to reproduce the behavior: 1. Create a Blazor component with a RadzenDropDownDataGrid. 2. Bind the Data property to an IEnumerable<T> obtained from a LINQ Select operation that maps a model (e.g., Category) to a DTO (e.g., CategoryDto). 3. Implement the LoadData event to asynchronously load data and perform the mapping. 4. Set ValueProperty="Id", TextProperty="Name", and use @bind-Value to bind the selected value. 5. Select an item from the dropdown. 6. Observe that the selected item is displayed in the dropdown, but the rz-state-highlight class is not applied to the corresponding row in the grid. Example code ```c# @page "/testdrop" @using System.Linq <RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.Center" Gap="0.5rem" class="rz-p-12"> <RadzenLabel Text="Select Value" Component="Category" /> <RadzenDropDownDataGrid Data="@_categories" TValue="int" LoadData="@LoadCategories" Count="@_categoriesCount" IsLoading="@_isLoadingCategories" AllowClear="true" AllowFiltering="true" TextProperty="Name" ValueProperty="Id" Name="Category" @bind-Value="CategoryId" /> </RadzenStack> @code { IEnumerable<CategoryDto> _categories; private int _categoriesCount; private bool _isLoadingCategories; int CategoryId; private async Task LoadCategories(LoadDataArgs args) { _isLoadingCategories = true; await Task.Yield(); var entities = GetData(); var mappedData = entities.Select(MapEntityToDto); // var mappedData = entities.Select(MapEntityToDto).ToList(); // Fixes the issue _categories = mappedData; _categoriesCount = _categories.Count(); _isLoadingCategories = false; } private CategoryDto MapEntityToDto(Category entity) { return new CategoryDto { Id = entity.Id, Name = entity.Name }; } private IEnumerable<Category> GetData() { return [ new Category { Id = 1, Name = "Appliance" }, new Category { Id = 2, Name = "Electronics" }, new Category { Id = 3, Name = "Betunias" } ]; } public class Category { public int Id { get; set; } public string Name { get; set; } } public class CategoryDto { public int Id { get; set; } public string Name { get; set; } } } ``` **Expected behavior** The RadzenDropDownDataGrid should apply the rz-state-highlight class to the selected item's row in the grid, providing a visual indicator of the selection, regardless of whether the Data property is bound to a lazy IEnumerable<T> or a materialized List<T>. **Screenshots** <img width="620" height="341" alt="Image" src="https://github.com/user-attachments/assets/ea8e03b6-ba98-4dc4-b3b1-092883f59d5b" /> **materializing the IEnumerable fixes the issue:** <img width="540" height="323" alt="Image" src="https://github.com/user-attachments/assets/72a0fe5e-4e16-4202-a510-9c983afb6d57" /> **Desktop (please complete the following information):** - OS: Windows 11 - Browser chrome, firefox - Version 8.0.4 **Additional context** Add any other context about the problem here.
Author
Owner

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

Since IEnumerable returns new object instances (with different hash codes) on each component lifecycle, object comparisons will always fail.

@enchev commented on GitHub (Oct 9, 2025): Since IEnumerable returns new object instances (with different hash codes) on each component lifecycle, object comparisons will always fail.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1879