Kendo MultiSelect:搜索多个字段
Kendo MultiSelect: Search on multiple fields
我正在使用 kendo Multiselect,我想找到一种方法来搜索我的数据源的多个字段。
这是我的实际代码。但它只适用于一个领域:
`
$scope.dataList = new kendo.data.DataSource({
data:[{id: "1",name: "Doe, John",email: "John.Doe@example.com"}],
});
$scope.customOption = {
dataSource: $scope.dataList,
dataTextField: "name",
dataValueField: "id",
filter: "contains",
itemTemplate: '<span>#=id#</span>#=name#<i> #=email#</i>',
}
`
如您所见,我也在使用 AngularJS,我尝试搜索姓名和电子邮件。
$("#id").kendoMultiSelect({
placeholder: "Select products...",
dataTextField: "name",
dataValueField: "id",
autoBind: false,
filtering: function (e) {
if (e.filter) {
var value = e.filter.value
var newFilter = {
filters: [
{ field: "id", operator: "contains", value: value },
{ field: "name", operator: "contains", value: value },
{ field: "email", operator: "contains", value: value }
],
logic: "or"
}
e.sender.dataSource.filter(newFilter)
e.preventDefault()
}
e.preventDefault()
},
dataSource: {
data:[
{id: "1",name: "Doe, John",email: "John.Doe@example.com"},
{id: "2",name: "sss, John",email: "sss.Doe@example.com"},
{id: "3",name: "fff, John",email: "fff.Doe@example.com"},
{id: "4",name: "ccc, John",email: "ccc.Doe@example.com"}
],
},
value: [
{id: "1",name: "Doe, John"},
]
});
参考 API Kendo DataSource and MultiSelect 的文档。希望对你有帮助。
我正在使用 kendo Multiselect,我想找到一种方法来搜索我的数据源的多个字段。 这是我的实际代码。但它只适用于一个领域:
`
$scope.dataList = new kendo.data.DataSource({
data:[{id: "1",name: "Doe, John",email: "John.Doe@example.com"}],
});
$scope.customOption = {
dataSource: $scope.dataList,
dataTextField: "name",
dataValueField: "id",
filter: "contains",
itemTemplate: '<span>#=id#</span>#=name#<i> #=email#</i>',
}
`
如您所见,我也在使用 AngularJS,我尝试搜索姓名和电子邮件。
$("#id").kendoMultiSelect({
placeholder: "Select products...",
dataTextField: "name",
dataValueField: "id",
autoBind: false,
filtering: function (e) {
if (e.filter) {
var value = e.filter.value
var newFilter = {
filters: [
{ field: "id", operator: "contains", value: value },
{ field: "name", operator: "contains", value: value },
{ field: "email", operator: "contains", value: value }
],
logic: "or"
}
e.sender.dataSource.filter(newFilter)
e.preventDefault()
}
e.preventDefault()
},
dataSource: {
data:[
{id: "1",name: "Doe, John",email: "John.Doe@example.com"},
{id: "2",name: "sss, John",email: "sss.Doe@example.com"},
{id: "3",name: "fff, John",email: "fff.Doe@example.com"},
{id: "4",name: "ccc, John",email: "ccc.Doe@example.com"}
],
},
value: [
{id: "1",name: "Doe, John"},
]
});
参考 API Kendo DataSource and MultiSelect 的文档。希望对你有帮助。