Kendo UI Datasource - Filter on releated data

2020-07-24 03:57发布

问题:

I am having trouble filtering a kendo data source on related data (many to many). I am using ASP.NET WebAPI2 and DataSourceRequest to catch the request on the server. The data is then fetched using the .ToDataSourceResult() extension method on an IQueryable.

I am aware of this article http://blogs.telerik.com/kendoui/posts/12-11-29/the_facts_on_using_kendo_ui_with_asp_net_webapi

My Data is structured as follows:-

Customer -> CustomerAddress -> Address

Where CustomerAddress is the join table between the Customer & Address tables. There is a navigational property on the Customer and also on the CustomerAddress.

Kendo datasource is as follows:-

var customers = new kendo.data.DataSource({
transport: {
    read: {
        url: "api/customers", type: "GET"
    }
},
pageSize: 10,
page: 1,
serverPaging: true,
serverFiltering: true,
type: "webapi",
schema: {
    data: "Data",
    total: "Total",
    errors: "Errors",
    model: {
        id: "CustomerID"
    }
}
});

The filter need to be applied on a field in the Address table. ie. AddressLine1 = "{search param}"

I have tried the following:-

var filters = {
logic: "or",
filters: [
  {field: "FirstName",operator: "contains",value: "xyz"},
  {field: "LastName",operator: "contains",value: "xyz"}, 
  {field: "CustomerAddress.Address.AddressLine1",operator: "contains",value: "xyz"}, 
]
};
customers.filter(filters);

Out of these the first 2 filters work absolutely fine. I have done a .Include() on the queryable and the address information is loaded fine.

How do I do this using the kendo DataSourceRequest ?