0

我正在使用 KendoUI,我想研究一下它是如何进行过滤的。我遇到了下面的代码片段:

http://demos.telerik.com/aspnet-mvc/grid/filter-row

我编写了如下代码:

<div id="clientsDb">
        @(Html.Kendo().Grid<Prometheus.Core.Domain.Employee>()
              .Name("employeeGrid")
              .Columns(columns =>
              {
                  columns.Bound(c => c.Id).Width(140).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
                  columns.Bound(c => c.FirstName).Width(190).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
                  columns.Bound(c => c.LastName);
              })
              .HtmlAttributes(new {style = "height: 380px;"})
              .Scrollable()
              .Groupable()
              .Sortable()
              .Pageable(pageable => pageable
                  .Refresh(true)
                  .PageSizes(true)
                  .ButtonCount(5))
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .Read(read => read.Action("ReadEmployee", "EmployeeGrid"))))

我没有看到任何错误,但在网格中的任何位置都没有看到启用任何搜索过滤器。

但是,以下代码对我来说工作正常,它在网格级别添加过滤器而不是在列级别添加它:

<div id="clientsDb">
        @(Html.Kendo().Grid<Prometheus.Core.Domain.Employee>()
              .Name("employeeGrid")
              .Columns(columns =>
              {
                  columns.Bound(c => c.Id).Width(140).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
                  columns.Bound(c => c.FirstName).Width(500).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
                  columns.Bound(c => c.LastName);
              })
              .HtmlAttributes(new { style = "height: 380px;" })
              .Scrollable()
              .Groupable()
              .Sortable()
              .Selectable()
              .Pageable(pageable => pageable
                  .Refresh(true)
                  .PageSizes(true)
                  .ButtonCount(5))
                  .Filterable(filterable => filterable
                .Extra(true)
                .Operators(operators => operators
                    .ForString(str => str.Clear()
                        .Contains("Contains")
                        .IsEqualTo("Exactly matches")
                        .StartsWith("Starts with")
                        .DoesNotContain("Does not contain")
                        .EndsWith("Ends with")
                        .IsNotEqualTo("Is not equal to")
                    ))).DataSource(dataSource => dataSource
                  .Ajax()
                  .Read(read => read.Action("ReadEmployee", "EmployeeGrid"))))
        </div>

我不确定这里有什么大区别,因为两者都使用几乎相同的可过滤属性。有任何想法吗?

4

2 回答 2

0

我认为您需要在第一个代码中应用 Filterable() 。

于 2015-03-10T07:28:34.350 回答
0

我知道这是一个非常晚的回复,但您需要.Filterable(filter => filter.Mode(GridFilterMode.Row))在第一个示例中添加网格级别。值得注意的是,为了.Cell(etc...)在列中使用样式,它需要处于行过滤器模式,因为菜单模式不支持每列选项。

这是一个很好的问题,为什么会这样,但确实如此。

于 2016-01-13T17:59:00.930 回答