radzenhq / radzen-blazor

Radzen Blazor is a set of 90+ free native Blazor UI components packed with DataGrid, Scheduler, Charts and robust theming including Material design and FluentUI.
https://www.radzen.com
MIT License
3.52k stars 785 forks source link

RadzenDataFilter returns unexpected filter strings #1642

Closed kerajel closed 2 months ago

kerajel commented 2 months ago
public class Order
{
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTime Date { get; set; }
}

<RadzenDataFilter @ref="Filter" Auto="false" Data="@(Enumerable.Empty<OrderPresetFilter>())" TItem="OrderPresetFilter">
    <Properties>
        <RadzenDataFilterProperty Property="Order.Id" Title="Order Id" />
        <RadzenDataFilterProperty Property="Order.Name" Title="Order Name" />
        <RadzenDataFilterProperty Property="Order.Date" Title="Order Date" />
    </Properties>
</RadzenDataFilter>

<RadzenButton Text="Apply Filter" Click="@OnClick" />
<RadzenTextBox @bind-Value="oDataFilterString" ReadOnly="true" Style="width: 100%; margin-top: 10px;" Placeholder="OData Filter String" />
<RadzenTextBox @bind-Value="dynamicLinqFilterString" ReadOnly="true" Style="width: 100%; margin-top: 10px;" Placeholder="Dynamic LINQ Filter String" />

@code {
    public RadzenDataFilter<OrderPresetFilter> Filter;
    private string oDataFilterString;
    private string dynamicLinqFilterString;

    public class OrderPresetFilter
    {
        public Order Order { get; set; }
    }

    public void OnClick()
    {
        oDataFilterString = Filter.ToODataFilterString();
        dynamicLinqFilterString = Filter.ToFilterString();
    }
}

To Reproduce Steps to reproduce the behavior:

  1. Filter Order.Date by selecting 'Order Date' in the filter, operator Equals, value 08-08-2024 from the date time picker.
  2. Observe the following values in the text boxes:

Observed Values

enchev commented 2 months ago

Sub properties in OData format are described with slash (/) not dot (.): https://services.odata.org/v4/OData/OData.svc/Suppliers?$filter=Address/Street%20eq%20%27NE%20228th%27

Dates are not quoted: https://services.odata.org/V4/OData/OData.svc/Products?$filter=ReleaseDate%20gt%202006-12-30T23:59:59.99Z

kerajel commented 2 months ago

This is weird because System.Linq.Dynamic.Core can't consume either of these queries. Is Radzen supposed to work with some other library?

And when you say that dates are not quoted, does it apply to LINQ specification or odata? Because the second example shows linq-compatible string, not odata string.

When I filter DateTime using RadzenDataGrid I see the following in the LoadDataArgs: Filter: CreatedAt = DateTime("2024-08-14") You see, in this case date is quoted, and System.Linq.Dynamic.Core can consume it contrary to the string produced by RadzenDataFilter

enchev commented 2 months ago

Indeed dates for Dynamic LINQ expression should be quoted - the expression added by this pull request is wrong: https://github.com/radzenhq/radzen-blazor/commit/1051bfa6611dfe6e50071f1a8dd505716e497e59

I'll fix it.