感谢Sandman为我提供了指向他的问题的链接,该链接与我的问题非常相似,并且他能够找到解决方案。我已经稍微改变了他的解决方案,以便它对我有用。原始解决方案。
function applyClientFilters() {
var listView = $("#ProductsList").data("kendoListView");
var listViewDataSource = listView.dataSource;
// clear existing datasource
listViewDataSource.filter([]);
// extract selected items from each of the dropdown controls and the search box
var productType = $("#ProductTypeDropDown").data("kendoDropDownList").value();
var therapeuticClass = $("#TherapeuticClassDropDown").data("kendoDropDownList").value();
var searchString = $(".search-filter").val();
// setup filter object (using and logic)
var filter = {
logic: "and",
filters: [] // ready for filter from each of the dropdowns and search bar
};
// push new filter into array of filters with or logic on each filter
if (productType.length > 0) {
var productTypeFilter = {
logic: "or",
filters: [
{ field: "ProductTypeId", operator: "equals", value: productType }
]
};
filter.filters.push(productTypeFilter);
}
if (therapeuticClass.length > 0) {
var therapeuticClassFilter = {
logic: "or",
filters: [
{
field: "TherapeuticClasses",
operator: function (itemValue, value) {
return itemValue &&
itemValue.find(function (item) {
if (item.Name.toLowerCase().indexOf(value.toLowerCase()) !== -1) {
return true;
} else {
return false;
}
});
},
value: therapeuticClass
}
]
};
filter.filters.push(therapeuticClassFilter);
}
if (searchString.length > 0) {
var searchFilter = {
logic: "or",
filters: [
{ field: "Name", operator: "startswith", value: searchString },
{ field: "ProductTypeDisplay", operator: "startswith", value: searchString },
{ field: "NdcCode", operator: "startswith", value: searchString },
{
field: "TherapeuticClasses",
operator: function(itemValue, value) {
return itemValue &&
itemValue.find(function(item) {
// If a therapeutic class name matches search then return true
if (item.Name.toLowerCase().indexOf(value.toLowerCase()) !== -1) {
return true;
} else {
return false;
}
});
},
value: searchString
}
]
};
filter.filters.push(searchFilter);
}
// apply filter query to datasource
listViewDataSource.query({
filter: filter
});
}
然后我只是applyClientFilters()
在每个下拉和搜索框的更改事件中调用该函数,并且过滤效果很好。