I am setting filters programmatically using the "FilterRow" example from here. Everything worked perfectly until I needed to implement a filter using FilterOperator.IsContainedIn.
I have confirmed that calling GridReadEventArgs.Request.ToODataString() is rendering the query string incorrectly by placing single quotes around the FilterDescriptor Member.
The below is a working example I created using the OData Blazor demo found on the Telerik GitHub here. I did have to update Blazor-UI to v2.9 for this demo to work.
If you uncomment the line in ReadItems that removes the extra single quotes, you'll see that the page functions as it should. I've also included a couple of screenshots which have the requestUrl rendered in the browser to better visualize what I mean.
@page "/"
@inject HttpClient Http
@using Telerik.Blazor.ExtensionMethods
@using WasmApp.Shared
@using Telerik.DataSource
<
TelerikGrid
Data=@GridData
Height
=
"460px"
RowHeight
=
"60"
PageSize
=
"10"
Pageable
=
"true"
Sortable
=
"true"
FilterMode
=
"@GridFilterMode.FilterRow"
OnRead=@ReadItems
TotalCount=@Total
OnStateInit="@((GridStateEventArgs<ODataProduct> args) => OnStateInit(args))">
<
GridColumns
>
<
GridColumn
Field
=
"ProductID"
/>
<
GridColumn
Field
=
"ProductName"
/>
<
GridColumn
Field
=
"Discontinued"
/>
</
GridColumns
>
</
TelerikGrid
>
<
h4
>@appStatus</
h4
>
@code{
public List<
ODataProduct
> GridData { get; set; } = new List<
ODataProduct
>();
public int Total { get; set; } = 0;
public string appStatus { get; set; }
protected void OnStateInit(GridStateEventArgs<
ODataProduct
> args)
{
GridState<
ODataProduct
> gridState = new GridState<
ODataProduct
>()
{
FilterDescriptors = new List<
FilterDescriptorBase
>()
{
new FilterDescriptor() {Member = "ProductName", Operator = FilterOperator.IsContainedIn, Value = "Chai,Chang", MemberType = typeof(string)}
}
};
args.GridState = gridState;
}
protected async Task ReadItems(GridReadEventArgs args)
{
var baseUrl = "https://demos.telerik.com/kendo-ui/service-v4/odata/Products?";
var requestUrl = $"{baseUrl}{args.Request.ToODataString()}";
//requestUrl = requestUrl.Replace("%27ProductName%27", "ProductName");
appStatus = requestUrl;
Console.WriteLine(appStatus);
ODataResponseOrders response = await Http.GetJsonAsync<
ODataResponseOrders
>(requestUrl);
GridData = response.Products;
Total = response.Total;
}
}