Kendo UI Datasource - Filter on releated data

空扰寡人 提交于 2020-01-01 17:02:28

问题


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 ?

来源:https://stackoverflow.com/questions/24489860/kendo-ui-datasource-filter-on-releated-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!