RadzenDataGrid doesn't know it's using OData until after first load #840

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

Originally created by @evandixon on GitHub (May 4, 2023).

Describe the bug
In PagedDataBoundComponent.ReloadOnFirstRender, if Data is null on the first render, Reload will be called. RadzenDataGrid's implementation of Reload handles filtering and ordering. RadzenDataGrid.GetOrderBy gets the columns to order by, and calls IsOData to determine the format of the order. IsOData depends on knowing Data's type, which is null because that's required to trigger the reload on first render. Until f5b7ddcf0e, an alternative was to set Data to IEnumerable.Empty<MyClass>().AsODataEnumerable() as a hint for IsOData, but now that solution results in the grid not loading on first render.

To Reproduce
Steps to reproduce the behavior:

  1. Create a view model with an object such as the following:
public class GridItem
{
    public MyClass ViewModel { get; set; }
}

public class MyClass
{
    public string SomeProperty { get; set; }
}
  1. Create a RadzenDataGrid with TItem="GridItem" with null Data and a LoadData delegate that uses OData to get data. Add a column referencing the property ViewModel.SomeProperty with SortOrder="SortDirection.Ascending".
  2. In the implementation of LoadData, observe how LoadDataArgs.OrderBy equals np(ViewModel.SomeProperty) asc. The "np" is a result of the grid thinking OrderBy is going to be used in a dynamic linq expression. (See RadzenDataGridColumn.GetSortOrderAsString)

Expected behavior
The LoadData implementation receives a LoadDataArgs.OrderBy equal to "ViewModel/SomeProperty asc" and not "np(ViewModel.SomeProperty) asc", perhaps by setting Data to Enumerable.Empty().AsODataEnumerable() or by having a separate parameter on the grid to force IsOData to true.

Originally created by @evandixon on GitHub (May 4, 2023). <!-- 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** In PagedDataBoundComponent.ReloadOnFirstRender, if Data is null on the first render, Reload will be called. RadzenDataGrid's implementation of Reload handles filtering and ordering. RadzenDataGrid.GetOrderBy gets the columns to order by, and calls IsOData to determine the format of the order. IsOData depends on knowing Data's type, which is null because that's required to trigger the reload on first render. Until https://github.com/radzenhq/radzen-blazor/commit/f5b7ddcf0e99e1a42f3359b11fef637032892a5d, an alternative was to set Data to `IEnumerable.Empty<MyClass>().AsODataEnumerable()` as a hint for IsOData, but now that solution results in the grid not loading on first render. **To Reproduce** Steps to reproduce the behavior: 1. Create a view model with an object such as the following: ``` public class GridItem { public MyClass ViewModel { get; set; } } public class MyClass { public string SomeProperty { get; set; } } ``` 2. Create a RadzenDataGrid with `TItem="GridItem"` with null Data and a LoadData delegate that uses OData to get data. Add a column referencing the property `ViewModel.SomeProperty` with `SortOrder="SortDirection.Ascending"`. 3. In the implementation of LoadData, observe how `LoadDataArgs.OrderBy` equals `np(ViewModel.SomeProperty) asc`. The "np" is a result of the grid thinking OrderBy is going to be used in a dynamic linq expression. (See RadzenDataGridColumn.GetSortOrderAsString) **Expected behavior** The LoadData implementation receives a LoadDataArgs.OrderBy equal to "ViewModel/SomeProperty asc" and not "np(ViewModel.SomeProperty) asc", perhaps by setting Data to Enumerable.Empty<GridItem>().AsODataEnumerable() or by having a separate parameter on the grid to force IsOData to true.
Author
Owner

@enchev commented on GitHub (May 5, 2023):

Hi @evandixon,

In my opinion empty ODataEnumerable and explicit call of Reload() to invoke LoadData might work for you.

@enchev commented on GitHub (May 5, 2023): Hi @evandixon, In my opinion empty ODataEnumerable and explicit call of Reload() to invoke LoadData might work for you.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#840