RadzenDataGrid - wrong filter format when OData source is null #967

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

Originally created by @giusepanzuto on GitHub (Aug 26, 2023).

Hi all,

I followed the filter API tutorial on https://blazor.radzen.com/datagrid-filter-api with a grid that uses an odata API to load data.
Unfortunately, when the grid calls LoadData the first time the source is null, and the filter received in the arguments isn't in odata format.

I expected a filter in this format:

'tolower(WorkOrderCode) eq tolower('AAA') and contains(tolower(SerialNumber), tolower('BBB'))'

But instead, I received this format:

(WorkOrderCode == null ? "" : WorkOrderCode).ToLower() == "AA3333".ToLower()

The issue is caused by the method IsOData which return false if Data is null

internal bool IsOData()
{
    if(isOData == null && Data != null)
    {
        isOData = typeof(ODataEnumerable<TItem>).IsAssignableFrom(Data.GetType());
    }
    return isOData != null ? isOData.Value : false;
}

Honestly, I cannot say whether this is a real problem, but it is certainly a situation that can waste a lot of time.
The solution (workaround?) is to initialise Data with a new, empty instance of ODataEnumerable. For example:

ODataEnumerable<WorkOrder> _workOrders = new(Enumerable.Empty<WorkOrder>());
Thanks
G.

Originally created by @giusepanzuto on GitHub (Aug 26, 2023). Hi all, I followed the filter API tutorial on https://blazor.radzen.com/datagrid-filter-api with a grid that uses an odata API to load data. Unfortunately, when the grid calls LoadData the first time the source is null, and the filter received in the arguments isn't in odata format. I expected a filter in this format: `'tolower(WorkOrderCode) eq tolower('AAA') and contains(tolower(SerialNumber), tolower('BBB'))'` But instead, I received this format: `(WorkOrderCode == null ? "" : WorkOrderCode).ToLower() == "AA3333".ToLower()` The issue is caused by the method IsOData which return false if Data is null ``` internal bool IsOData() { if(isOData == null && Data != null) { isOData = typeof(ODataEnumerable<TItem>).IsAssignableFrom(Data.GetType()); } return isOData != null ? isOData.Value : false; } ``` Honestly, I cannot say whether this is a real problem, but it is certainly a situation that can waste a lot of time. The solution (workaround?) is to initialise Data with a new, empty instance of ODataEnumerable. For example: `ODataEnumerable<WorkOrder> _workOrders = new(Enumerable.Empty<WorkOrder>()); ` Thanks G.
Author
Owner

@enchev commented on GitHub (Aug 28, 2023):

The empty instance of ODataEnumerable is the only way to handle this and unfortunately we don’t have any other solutions.

@enchev commented on GitHub (Aug 28, 2023): The empty instance of ODataEnumerable is the only way to handle this and unfortunately we don’t have any other solutions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#967