Kendo Grid Server端使用数组类型列进行过滤

时间:2019-05-20 13:23:48

标签: filter server kendo-grid odata

我有这个剑道网格对我的Web服务不了解。其中一列具有带有剑道多选择器数组的自定义过滤器,因此客户端可以选择多个ItemType。网格正确显示数据,但我的服装筛选器不适用于此特定列。我从服务中收到此错误:“检测到类型不兼容的二进制运算符。对于运算符类型,发现了操作数类型'Telerik.Sitefinity.DynamicTypes.Model.ClinicFinder.Clinic.ItemType.ItemType'和'Edm.Int32' “等于”。”

我的网格定义

$("#grid").kendoGrid({
dataSource: {
    type: "odata-v4",
    transport: {
        read: {
            url: function () {                    
                return "//myservice/api/clinics?$select=Id,Title,Address,ItemType,productsystems&top=20";
            }
        }
    },
    schema: {
        model: {
            fields: {
                Title: { type: "string" },
                CountryCode: { type: "string" },
                Street: { type: "string" },
                City: { type: "string" },
                Zip: { type: "string" },
                ItemType: { type: "" } 


            }
        }
    },
    serverPaging: true,
    serverFiltering: true,        
    serverSorting: false,
    pageSize: 20
},
pageable: true,
filterable: {
    mode: "row",
    extra: false,
    showOperators: false,
    operators: {
        string: {
            contains: "contains"
        }
    }
},
sortable: false,
columns: [
    { field: "Title", title: "Clinic" },
    { field: "CountryCode", title: "Country" },
    { field: "Street", title: "Address" },
    { field: "City", title: "City"  },
    { field: "Zip", title: "Zip",  filterable: false },       
    { field: "ItemType", title: "Clinic Type", filterable: { multi: true } }
],
rowTemplate: kendo.template($("#template").html())    

});

我的过滤器功能

function filterByclinicCategory() {
var filter = { logic: "or", filters: [] };
var grid = $('#grid').data('kendoGrid');
var filterValue = $("#clinicTypeFilter").data("kendoMultiSelect").value();
var clinicCode = [];
if (filterValue.length > 0) {
    $.each(filterValue, function (i, v) {
        clinicCode.push(convertClinicTypesInCodes(v));
        filter.filters.push({
            field: "ItemType", operator: "eq", value: clinicCode, logic: "or"
        });
        grid.dataSource.filter(filter);    
    });

} else {
    $("#grid").data("kendoGrid").dataSource.filter({});
}


}

ItemType是我无法过滤的列。

我的网络服务数据

{
"@odata.context": "https://sf-admin-local.medel.com/api/wstest/$metadata#clinics(*)",
"value": [
{
"Id": "896aa08b-2f17-64e6-80bd-ff09000c6e28",
"LastModified": "2019-05-13T09:28:04Z",
"PublicationDate": "2018-06-19T14:19:13Z",
"DateCreated": "2018-06-19T14:19:13Z",
"UrlName": "??",
"Email": "",
"URL": "",
"Telephone": "",
"Title": "????????",
"officeregions": [],
"salespartnerregions": [],
"productsystems": [
"b8ec2a8b-2f17-64e6-80bd-ff09000c6e28",
"1878cb61-ac79-69d9-867b-ff01007297b6",
"1b78cb61-ac79-69d9-867b-ff01007297b6",
"36d8938b-2f17-64e6-80bd-ff09000c6e28"
],
"Area": "",
"Order": 0,
"Tags": [],
"AdditionalInformation": "",
"ImportID": 1,
"Featured": false,
"ItemType": "2",
"Address": {
"Id": "d76aa08b-2f17-64e6-80bd-ff09000c6e28",
"CountryCode": "AT",
"StateCode": "",
"City": "????",
"Zip": "6800",
"Street": "Carinagasse ?????",
"Latitude": 47.2311043,
"Longitude": 9.580079999999953,
"MapZoomLevel": 8
}
}
]
}

1 个答案:

答案 0 :(得分:0)

我设法使用 parameterMap https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/configuration/transport.parametermap对其进行修复。

我添加了一个 parameterMap:functiondata,type)函数,通过它我可以拦截和更改过滤器发出的调用。

 parameterMap: function (data, type) {               
     var c = kendo.data.transports["odata-v4"].parameterMap(data, type);
     if (c.$filter) {
     //my transformation
     c = myTransformation;
     return c;
     } else{
     return c; //not apply transformation loading the data
     }

 }