ODataFilter is always null

I have the following grid. I want to pass the ODataFilter through to my API as a string (I am not using OData controllers).

In my LoadSomeData method the args.ODataFilter is always empty. Why is this?

<RadzenGrid TItem=EventSummary
			FilterCaseSensitivity=FilterCaseSensitivity.CaseInsensitive
			AllowPaging=true
			AllowFiltering=true
			PageSize=@ItemsPerPage
			Count=@State.Value.TotalSearchCount
			AllowSorting=true
			LoadData=@LoadSomeData
			FilterDelay=1000
			Data=@State.Value.EventSummaries
			ColumnWidth="200px">
	<Columns>
		<RadzenGridColumn TItem=@EventSummary
						  Property=@nameof(EventSummary.EnergyType)
						  Title="Energy type" />
		<RadzenGridColumn TItem=@EventSummary
						  Property=@nameof(EventSummary.UtcTime)
						  Title="Date">
			<Template Context="data">
				@String.Format("{0:d}", data.UtcTime)
			</Template>
		</RadzenGridColumn>
		<RadzenGridColumn TItem=@EventSummary
						  Property=@nameof(EventSummary.Description)
						  Title="Description" />
	</Columns>
</RadzenGrid>



		private void LoadSomeData(LoadDataArgs args)
		{
			System.Diagnostics.Debug.WriteLine("=================================== " + args?.Filter);
			System.Diagnostics.Debug.WriteLine("=================================== " + args?.ODataFilter);
		}

This property is obsolete and will be removed. You can get the current filter expression from Filter.

Is that an odata expression? I tried using it as an odata filter but the library I use says it is invalid.

Also, is there a way I can get the values entered into the filter boxes without having to parse a string?

We have AsODataEnumerable() extension method for IEnumerable which will return ODataEnumerable<T> . If you bind the grid using the extension method you will have OData expression in Filter property, if not Dynamic Linq expression. If you want to get the column filter values you can loop ColumnsCollection property and check FilterValue column property.

I've updated this demo to use the described approach in my previous reply:
https://blazor.radzen.com/datagrid-loaddata

Hi

I need the filter as an OData filter expression because it is passed to my API (along with various other properties) and then Commuinity.OData.Linq parses it. I'm using the DevExpress grid at the moment and it works fine, but it doesn't have a push approach for paged data. Your grid supports both pull and push (which I require) but I am unable to do the server-side OData filtering.

Is this possible?

The Filter property of the LoadDataArgs contains the filter in OData format:

What else do you need?

The value I see in version 2.1.18.0 is:

((Name == null ? "" : Name) == null ? "" : (Name == null ? "" : Name)).Contains("Person")

How did you get it as proper OData?

You need to use AsODataEnumerable() similar to our demo. See my previous reply in this thread.

Hi

The AsODataEnumerable is retrieved from the result of calling a service (not shown).

I need the OData syntax filter in order to call to a pre-defined API in order to get my data.

AsODataEnumerable() is our extension methods that will create ODataEnumerable<T> wrapper over any IEnuemreable<T> and will tell the DataGrid to use OData syntax for filtering, sorting, etc.

I'm not sure if I am not explaining my requirement properly, or if I am not understanding the answer. Let me try rewording.

API contract

public class FindClients
{
  public string ODataFilter { get; set; }
  public string ODataOrderBy { get; set; }
  public int Skip { get; set; }
  public int Take { get; set; }
}

Blazor client

private asyc Task SomeEventCalledByYourGridWhenFiltersOrOrderingOrPageNumberChanges(YourGridArgs args)
{
  var request = new FindClients
  {
    ODataFilter = ???,
    ODataOrdering = ????,
    Skip = (this is available in args),
    Take = (this is available in args)
  }
  var response = HttpClient.PostJsonAsync<FindClientsResponse>(.....etc......, request);
}

When your grid changes filters or ordering, and before I have any data from the server API, how do I get the filter and order in OData syntax to pass to my API? The API is not an OData endpoint, it just expects order and filter to be in OData syntax.

Many thanks.

Did you check our demo? Does it work for you as you would expect? As @enchev said you have to set the Data property of the Radzen DataGrid to something which is ODataEnumerable (which you can obtain via the AsODataEnumerable extension method which Radzen provides). Try the demo project and put a breakpoint in the LoadData event handler.

Hi

Your demo seems to work fine, but in my code the value I receive for the filter is not in OData format.

JSON serialized content of your demo
LoadDataArgs: {"Skip":0,"Top":4,"OrderBy":null,"Filter":"contains(LastName, \u0027Fuller\u0027)"}

JSON serialized content of LoadDataArgs in our app
LoadDataArgs: {"Skip":0,"Top":4,"OrderBy":null,"Filter":"((LastName== null ? \u0022\u0022 : LastName) == null ? \u0022\u0022 : (LastName== null ? \u0022\u0022 : LastName)).Contains(\u0022Fuller\u0022)"}

Is the difference because your demo is server-side and our app is client-side WASM? Or perhaps there was some config in your demo that we are missing?

I finally understand what your solution is.

I cannot simply pass an IEnumerable<T> as the data source if I want the filter in OData format. I have to use your AsODataEnumerable() extension and the grid will check if the source is ODataEnumerable<T> and, if so, then return the filter in OData format instead.

I would never have suspected this, and even when you told me about it I still struggled to understand what the approach is.

Having a property called something like UseODataFilters on the grid would be a much better approach I think.

Thanks for your help!