用字段类型对象过滤kendo ui网格 [英] filter kendo ui grid with filed type object
问题描述
我有这个网格
$("#address-grid").kendoGrid({
dataSource: {
transport: {
read: {
url: "operations/get_sales_reps_addresses.php?salesRepsId=" + salesRepsId,
type: "GET"
},
update: {
url: "operations/edit_address.php?salesRepsId=" + salesRepsId,
type: "POST",
complete: function (e) {
$("#address-grid").data("kendoGrid").dataSource.read();
}
},
destroy: {
url: "operations/delete_address.php",
type: "POST",
complete: function (e) {
$("address-grid").data("kendoGrid").dataSource.read();
}
},
create: {
url: "operations/add_address.php?salesRepsId=" + salesRepsId,
type: "POST",
complete: function (e) {
$("#address-grid").data("kendoGrid").dataSource.read();
}
},
},
schema: {
data: "data",
total: "data.length", //total amount of records
model: {
id: "SalesRepId",
fields: {
AddressType: {
defaultValue: {
AddressTypeid: 1,
AddressTypeName: "Work"
}
},
Country: {
defaultValue: {
CountryId: 38,
CountryName: "Canada"
}
},
State: {
defaultValue: {
StateId: 4223,
StateName: "British Colombia"
}
},
City: {
defaultValue: {
CityId: 59450,
CityName: "Vancouver"
}
},
PostalCode: {
type: "string"
},
AddressText: {
type: "string"
},
IsMainAddress: {
type: "boolean"
},
AddressId: {
type: "integer"
}
}
}
},
pageSize: 3,
},
ignoreCase: true,
height: 250,
filterable: true,
sortable: true,
pageable: true,
reorderable: false,
groupable: false,
batch: true,
navigatable: true,
toolbar: ["create", "save", "cancel"],
editable: true,
columns: [{
field: "AddressType",
title: "Type",
editor: AddressTypeDropDownEditor,
template: "#=AddressType.AddressTypeName#",
}, {
field: "Country",
title: "Country",
editor: CountryDropDownEditor,
template: "#=Country.CountryName#",
}, {
field: "State",
title: "State",
editor: StateDropDownEditor,
template: "#=State.StateName#",
}, {
field: "City",
title: "City",
editor: CityTypeDropDownEditor,
template: "#=City.CityName#",
}, {
field: "PostalCode",
title: "Postal Code",
}, {
field: "AddressText",
title: "Address",
}, {
field: "IsMainAddress",
title: "Main?",
width: 65,
template: function (e) {
if (e.IsMainAddress == true) {
return '<img align="center" src ="images/check-icon.png" />';
} else {
return '';
}
}
// hidden: true
}, {
command: "destroy",
title: " ",
width: 90
},
]
});
问题是,当我尝试按国家或州或城市进行过滤时,我得到了一个错误
The problem is when I try to filter by Country or State or City I got an error
TypeError:" .toLowerCase不是函数
TypeError: "".toLowerCase is not a function
我尝试将国家/地区"类型更改为字符串,我使用comobox,所以值未定义.我还尝试将类型更改为对象",值显示正确,但无法过滤.我遇到了同样的错误(toLowerCase)
I tried to change the type of Country to string, I use comobox, so the values were undefined. I also tried to change the type to Object, the values displayed correctly but I couldn't filter. I got the same error( toLowerCase)
我该如何解决?
我的网格非常相似此示例
,这是 jsFiddle .我刚刚添加了过滤器.而且仍然出现先前的错误
and here is the jsFiddle . I've just added the filter. and I still get previous error
我想对类别进行过滤,有什么帮助吗?
I want to filter on the Category, any help ??
推荐答案
这是您过滤数据源的方式 Kendo dataSource,过滤器
This is how you filter a dataSource Kendo dataSource , filter
因此获取网格的数据源,
So get the dataSource of your grid,
var gridDatasource = $("#address-grid").data('kendoGrid').dataSource;
并按此示例进行过滤.
gridDatasource.filter({ ... });
如果您提供有效的jsFiddle,则可能会得到更具体的答案.
If you provide a working jsFiddle, you may get a more specific answer.
具体答案:
您添加了过滤器,因此对于Category来说它不起作用,因为正如我所说,它是可观察的,不是文件,您可以将其过滤为字符串.
You added the filter, so for Category it didn't work because as I said, it is an observable, not a filed you can filter as a string.
因此,您必须为此栏指定更好的过滤器,如下所示:
So you must specify better your filter for this column, like this:
field: "Category",
title: "Category",
width: "160px",
editor: categoryDropDownEditor,
template: "#=Category.CategoryName#",
filterable: {
extra: false,
field:"Category.CategoryName",
operators: {
string: {
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to"
}
}
}
请参阅此jsFiddle-> http://jsfiddle.net/blackjim/Sbb5Z/463/
see this jsFiddle -- > http://jsfiddle.net/blackjim/Sbb5Z/463/
这篇关于用字段类型对象过滤kendo ui网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!