Hi Radzen Team,
I am using a datagrid connected with an OData source and I want to add a default (boolean) column filter for "Inactive" items in a certain case.
But the OData service does not accept the generated URI, as there is no valid OData filter set in this case. When comparing the URI with the programatic filter and when clicking in the UI I have different generated URIs:
Filtering API
https://...?$count=true&$top=8&$skip=0&$filter=Activated == False
When set via UI
https://...?$count=true&$top=8&$skip=0&$filter=Activated eq false
I have to manually adjust the 'args.Filter' in LoadData() to get it working.
Is this an issue or did i missed something?
protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var column = grid.ColumnsCollection.Where(c => c.Property == "Activated").FirstOrDefault();
if (column != null)
{
column.SetFilterOperator(FilterOperator.Equals);
column.SetFilterValue(false);
await grid.Reload();
}
}
await base.OnAfterRenderAsync(firstRender);
}
protected async Task LoadData(LoadDataArgs args)
{
isLoading = true;
DataServiceQuery<TItem> query = CreateDataQuery();
query = query.AddQueryOption("$skip", args.Skip);
if (!string.IsNullOrEmpty(args.Filter))
{
// This fixes the issue but is no general solution
args.Filter = args.Filter
.Replace("==", "eq")
.Replace("False", "false")
.Replace("True", "true");
query = query.AddQueryOption("$filter", args.Filter);
}
if (!string.IsNullOrEmpty(args.OrderBy))
query = query.AddQueryOption("$orderby", args.OrderBy);
await Console.Out.WriteLineAsync(query.RequestUri.ToString());
QueryOperationResponse<TItem> response =
(QueryOperationResponse<TItem>)(await query.ExecuteAsync());
data = (ODataEnumerable<TItem>?)response.ToList().AsODataEnumerable();
count = (int)response.Count;
isLoading = false;
}