Kendo Grid过滤器无法使用外键列模型

时间:2018-05-15 09:54:24

标签: asp.net-mvc model-view-controller filter kendo-ui kendo-grid

我的网格列:

@(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的过滤函数被命中,而模型的内容则用于填充过滤器。

如何让过滤器只查看网格内容?

0 个答案:

没有答案