Kendo Grid Серверная фильтрация со столбцом типа массива - PullRequest
0 голосов
/ 20 мая 2019

Эта сетка кендо закрыта для моего веб-сервиса. В одном из столбцов есть пользовательский фильтр с мультиселекторным массивом kendo, поэтому клиент может выбрать несколько типов 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())    

});

Функция My Filter

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 голосов
/ 27 мая 2019

Мне удается исправить это, используя 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
     }

 }
...