DataGrid selection not work with IQueryable #1418

Closed
opened 2026-01-29 17:53:24 +00:00 by claunia · 2 comments
Owner

Originally created by @franklupo on GitHub (Oct 3, 2024).

With data IQueryable the selection disappears when scroll.
For testing copy source in https://blazor.radzen.com/datagrid-virtualization?theme=fluent and run

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inherits DbContextPage

<RadzenDataGrid Data="@orderDetails" AllowVirtualization="true" Style="height:400px"
                AllowFiltering="true" FilterPopupRenderMode="PopupRenderMode.OnDemand" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" LogicalFilterOperator="LogicalFilterOperator.Or"
                AllowSorting="true"
                @bind-Value=@selectedEmployees>
    <Columns>
        <RadzenDataGridColumn Property="@nameof(OrderDetail.OrderID)" Title="OrderID" />
        <RadzenDataGridColumn Property="@nameof(OrderDetail.ProductID)" Title="ProductID" />
        <RadzenDataGridColumn Property="@nameof(OrderDetail.UnitPrice)" Title="Unit Price">
            <Template Context="detail">
                @String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", detail.UnitPrice)
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn Property="@nameof(OrderDetail.Quantity)" Title="Quantity" />
        <RadzenDataGridColumn Property="@nameof(OrderDetail.Discount)" Title="Discount">
            <Template Context="detail">
                @String.Format("{0}%", detail.Discount * 100)
            </Template>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

@code {
    IQueryable<OrderDetail> orderDetails;
    IList<OrderDetail> selectedEmployees;

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

  orderDetails = Enumerable.Range(1, 100).Select(a => new OrderDetail
  {
      OrderID = a,
      ProductID = a
  }).AsQueryable();

//        orderDetails = dbContext.OrderDetails;
    }
}
Originally created by @franklupo on GitHub (Oct 3, 2024). With data IQueryable the selection disappears when scroll. For testing copy source in https://blazor.radzen.com/datagrid-virtualization?theme=fluent and run ```c# @using RadzenBlazorDemos.Data @using RadzenBlazorDemos.Models.Northwind @using Microsoft.EntityFrameworkCore @inherits DbContextPage <RadzenDataGrid Data="@orderDetails" AllowVirtualization="true" Style="height:400px" AllowFiltering="true" FilterPopupRenderMode="PopupRenderMode.OnDemand" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" LogicalFilterOperator="LogicalFilterOperator.Or" AllowSorting="true" @bind-Value=@selectedEmployees> <Columns> <RadzenDataGridColumn Property="@nameof(OrderDetail.OrderID)" Title="OrderID" /> <RadzenDataGridColumn Property="@nameof(OrderDetail.ProductID)" Title="ProductID" /> <RadzenDataGridColumn Property="@nameof(OrderDetail.UnitPrice)" Title="Unit Price"> <Template Context="detail"> @String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", detail.UnitPrice) </Template> </RadzenDataGridColumn> <RadzenDataGridColumn Property="@nameof(OrderDetail.Quantity)" Title="Quantity" /> <RadzenDataGridColumn Property="@nameof(OrderDetail.Discount)" Title="Discount"> <Template Context="detail"> @String.Format("{0}%", detail.Discount * 100) </Template> </RadzenDataGridColumn> </Columns> </RadzenDataGrid> @code { IQueryable<OrderDetail> orderDetails; IList<OrderDetail> selectedEmployees; protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); orderDetails = Enumerable.Range(1, 100).Select(a => new OrderDetail { OrderID = a, ProductID = a }).AsQueryable(); // orderDetails = dbContext.OrderDetails; } } ```
Author
Owner

@enchev commented on GitHub (Oct 4, 2024):

dbContext.OrderDetails is also IQueryable however the selection will work normally. In your case you return different data item with different HashCode every time when collection is accessed - no selection can be preserved with such binding.

@enchev commented on GitHub (Oct 4, 2024): dbContext.OrderDetails is also IQueryable however the selection will work normally. In your case you return different data item with different HashCode every time when collection is accessed - no selection can be preserved with such binding.
Author
Owner

@franklupo commented on GitHub (Oct 4, 2024):

Ok, is it possible to specify a key property to keep the selection?

@franklupo commented on GitHub (Oct 4, 2024): Ok, is it possible to specify a key property to keep the selection?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1418