filter - 带有数组类型列的 Kendo Grid Server 端过滤
问题描述
我让这个剑道网格对我的网络服务视而不见。其中一列有一个带有 kendo 多选器数组的自定义过滤器,因此客户端可以选择多个 ItemType。网格正确显示数据,但我的服装过滤器不适用于此特定列。我从服务中收到此错误:“检测到类型不兼容的二元运算符。发现操作数类型 'Telerik.Sitefinity.DynamicTypes.Model.ClinicFinder.Clinic.ItemType.ItemType' 和 'Edm.Int32' 用于运算符类型 'Equal' 。”
我的网格定义
$("#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
}
}
]
}
解决方案
我设法使用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
}
}
推荐阅读
- python - 使用 pip install 安装 ssl 时遇到问题:“SyntaxError: Missing parentheses in call to 'print'”
- sql-server - 如何从 Powershell 执行存储过程?
- docker - docker-compose 如何将我的服务名称映射到 IP 地址?
- javascript - 如何将序列化的多维数组从 C# 传递到 Javascript
- blazor - 将导航参数传递给 blazor 中的导航或布局组件
- python - 如何避免列表理解中重复元素的重复计算索引
- xamarin - 为什么在使用 Xamarin Android 应用程序中的 APK 时 GStreamer 播放会受到影响?
- nestjs - 是否可以创建一个也是请求范围的自定义提供程序?
- python - 为什么我不能正确分配给 3d 列表?
- javascript - CKEditor 5 (ckeditor-angular) 的通用文件上传器