kendo网格过滤器运算符

时间:2016-08-25 08:32:30

标签: javascript asp.net-mvc kendo-grid

我有一个用于网格的数据源。 网格有服务器过滤,工作正常。 问题是 - 过滤器仅根据包含运算符给出结果(不管我选择了什么) 如何从过滤器运算符选项中获取过滤器运算符。

请帮帮我

@(Html.Kendo()。网格(模型),请将.Name( “ViewDataGrid”)

    .Columns(columns =>
    {
        columns.Bound(c => c.Id).Title(" ID").Width(150);
        columns.Bound(c => c.Name).Title(" Name").Width(150);

        })
    .HtmlAttributes(new { style = "height: auto; width: 2200px" })
    .Filterable(i => i.Mode(GridFilterMode.Menu | GridFilterMode.Row))
    .Sortable(s => s.AllowUnsort(false).SortMode(GridSortMode.MultipleColumn))
    .Selectable(selecting => selecting.Enabled(true))                               
    .Pageable(r => r.PreviousNext(true).PageSizes(new int[] { 10, 20, 30, 40, 50, 100 }))
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .ServerOperation(false)
        .Events(e => e.Change("call"))
        ))
function call(e) {

    if (e.sender.filter.arguments[0].filters != null) {
        if (e.sender.filter.arguments[0].filters[0].value == "") {                     
            $('#ViewDataGrid').data('kendoGrid').dataSource.filter({});
        }
        else {
            var filterlength = e.sender.filter.arguments[0].filters.length;
            $filter = new Array();
            if (e.sender.filter.arguments[0].filters[0].field == "Id")
            $filter.push({ field: e.sender.filter.arguments[0].filters[0].field, operator: "eq", value: e.sender.filter.arguments[0].filters[0].value });
            else
            $filter.push({ field: e.sender.filter.arguments[0].filters[0].field, operator: "contains", value: e.sender.filter.arguments[0].filters[0].value });
            $("#ViewDataGrid").data("kendoGrid").dataSource.filter($filter);

        }
    }
}

Model.CS

public int Id { get; set; }
public string Name { get; set; }

控制器

public ActionResult Index()
{
    List<GridData> dataList = new List<GridData>(); 
    GridData data1 = new GridData();
    data1.Id = 9191919;
    data1.Name = "XYZ";           
    dataList.Add(data1);
    return View(dataList);           
}

1 个答案:

答案 0 :(得分:0)

您可能只启用ID字段的“等于”过滤器

@(Html.Kendo().Grid(Model).Name("ViewDataGrid")

    .Columns(columns =>
    {
            columns.Bound(c => c.Id).Title(" ID").Width(150).Filterable(f => f.Operators(op => op.ForNumber(opn => opn.Clear().IsEqualTo("Is equal to") )));
            columns.Bound(c => c.Name).Title(" Name").Width(150);
        })
    .HtmlAttributes(new { style = "height: auto; width: 300px" })
    .Filterable(i => i.Mode(GridFilterMode.Menu | GridFilterMode.Row))
    .Sortable(s => s.AllowUnsort(false).SortMode(GridSortMode.MultipleColumn))
    .Selectable(selecting => selecting.Enabled(true))
    .Pageable(r => r.PreviousNext(true).PageSizes(new int[] { 10, 20, 30, 40, 50, 100 }))
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .ServerOperation(false)
    ))