我的网格列:
@(Html.Kendo().Grid<Kendo_UI_Bootstrap_Integration.Models.DTO.GridDto>()
.Name("GridName")
.Filterable(f => f.Mode(GridFilterMode.Menu).Extra(false))
.EnableCustomBinding(true)
.Columns(
columns =>
{
columns.ForeignKey(c => c.HouseId, Model.Homes, "HouseGuid", "HouseName")
.EditorTemplateName("HouseDropDown")
.Title("House Name")
.Filterable(f => f.UI("$.proxy(GridFilter, {field: 'Id'})").Operators(o => o.ForString(e => e.Clear().IsEqualTo("Is equal to").IsNotEqualTo("Is not equal to"))));
columns.ForeignKey(c => c.NameId, Model.Names, "NameGuid", "Name")
.EditorTemplateName("NameDropDown")
.Title("Name")
.Filterable(f => f.UI("$.proxy(GridFilter, {field: NameId})").Operators(o => o.ForString(e => e.Clear().IsEqualTo("Is equal to").IsNotEqualTo("Is not equal to"))));
网格过滤器:
function GridFilter(element) {
var grid = "GridName";
var fieldName = this.field;
var gridDataItems = $("#" + grid).data("kendoGrid").dataSource.data();
var listDataItems = [];
for (var i = 0; i < gridDataItems.length; i++) {
if (gridDataItems[i][fieldName] !== null && $.inArray(gridDataItems[i][fieldName], listDataItems) < 0) {
listDataItems.push(gridDataItems[i][fieldName]);
}
}
listDataItems.sort();
$(element).prop("id", fieldName + "DropDown");
element.kendoDropDownList({
dataSource: {
data: listDataItems
}
})
}
我在视图顶部传递我的ViewModel,模型包含Homes列表和数据库中的Name列表。
我想根据网格的内容过滤网格,但我指定的dosnt的过滤函数被命中,而模型的内容则用于填充过滤器。
如何让过滤器只查看网格内容?