Using the odata "expand" with DataSourceRequest?

1 Answer 197 Views
Grid
Jstemper
Top achievements
Rank 2
Bronze
Iron
Jstemper asked on 22 Jun 2021, 07:04 PM

Is it possible via the DataSourceRequest to generate the string to bring back sub objects and even sub sub objects?

It does not seem to fit in the  FilterDescriptor.

 

1 Answer, 1 is accepted

Sort by
0
Stamo Gochev
Telerik team
answered on 25 Jun 2021, 12:21 PM

Hi,

$expand (with filters) is part of the enhancements of OData v4 standard and is not targeted by the current version of the "ToODataString()" method (as well as other things like $search).

However, you can modify the string returned from "ToODataString()" to include it, e.g.:

var baseUrl = "...odata/products?";

// results in something similar to "$filter=(CategoryId%20eq%202)";
var filterPart = args.Request.ToODataString();

// results in something similar to "$expand=Category($filter=(CategoryId%20eq%202)"
var odatUrl = $"{baseUrl}?$expand=Category({filterPart});

The above idea can be modified to fit the exact project requirements.

Regards,
Stamo Gochev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Jstemper
Top achievements
Rank 2
Bronze
Iron
Answers by
Stamo Gochev
Telerik team
Share this question
or