telerik - Kendo UI Grid 的过滤器未对指定列执行

标签 telerik filtering kendo-grid kendo-dropdown

这是我的 MVC View 代码:-

<div id="reportsDb">
  <div id="grid"></div>
  <script type="text/x-kendo-template" id="template">
    <div class="toolbar" id="template" >
      <label class="Status-label" for="Status">Show reports by status:</label>
      <input type="search" id="Status" style="width: 150px"/>
    </div>
  </script>
  <script>
    $(document).ready(function () {
      var path = ""
      dataSource = new kendo.data.DataSource({

        transport: {
          read: {
            url: "@Url.Action("Report_Read", "Report")",
            dataType: "json",
            type: "Get",
            contentType: "application/json"
          }

        },

        serverPaging: true,
        serverSorting: true,
        serverFiltering: true,

        pageSize: 10,
        schema: {
          model: {
            id: "RequestId",
            fields: {
              IPAddress: { type: "string" },
              RequestQuetime: { type: "date" },
              RequestPicktime: { type: "date" },
              RequestRespondTime: { type: "date" },
              StatusType: { type: "string" },
              RequestTimeDifference: { type: "datetime", format: "{0:hh:mm:ss}" },
              RequestPickDifference: { type: "datetime", format: "{0:hh:mm:ss}" }
            }
          }
        }
      });

      var grid =  $("#grid").kendoGrid({
        dataSource: dataSource,
        sortable: true,
        pageable: true,
        filterable: {
          extra: false,
          operators: {
            string: {
              startswith: "Starts with",
              eq: "Is equal to",
              neq: "Is not equal to"
            }
          }
        },
        toolbar: kendo.template($("#template").html()),
        height: 430,

        columns: [
          { field: "IPAddress", title: "IP address", width: 100, filterable: true },
          { field: "RequestQuetime", title: "Que time", width: 100, filterable: false },
          { field: "RequestPicktime", title: "Pick time", width: 110, filterable: false },
          { field: "RequestRespondTime", title: "Respond time", width: 100, filterable: false },
          { field: "StatusType", title: "status", width: 110, filterable: { ui: statusFilter } },
          { field: "RequestTimeDifference", title: "Time difference", width: 110, filterable: false },
          { field: "RequestPickDifference", title: "Pick difference", width: 110, filterable: false }
        ]
      });

      function statusFilter(element) {
        element.kendoDropDownList({
          dataSource: {
            transport: {
              read: {
                url: "@Url.Action("RequestStatus_Read", "Report")",
                dataType: "json",
                type: "Get",
                contentType: "application/json"
              }
            }
          },
          dataTextField: "Text",
          dataValueField: "Value",
          optionLabel: "--Select Value--"
        });
      }
    });
  </script>
</div>

下面是 Controller 的操作方法:-

public ActionResult Report_Read()
{
  return Json(_oRepository.GetReports().ToList(), JsonRequestBehavior.AllowGet);
}

I want to apply filtering on StatusType filed and for that I have bound this filed with dropdownlist.

我的问题是,当我尝试通过从下载中选择一种状态来进行过滤时,它什么也不做。

我正在按照这个例子工作:

http://demos.telerik.com/kendo-ui/grid/filter-menu-customization

最佳答案

从您的代码来看,除了 Controller 读取操作之外,一切似乎都很好。现在,如果当您从 GridView 应用过滤器时调用 Controller ,那么您这边唯一需要的更改如下:

 public JsonResult Report_Read([DataSourceRequest] DataSourceRequest request)
 {          
    return Json(_oRepository.GetReports().ToList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
 }

编辑:

如果您不使用 Kendo.MVC,那么您有两种过滤选项:

选项 1:客户端过滤
-> 您需要在读取时获取所有数据,以便在应用过滤时您拥有所有数据,如果数据源不大,这是最好的选择,因为它可以保存不需要的 Controller 过滤请求。
-> 首先认为您需要做的是订阅网格的 filterMenuInit() 并添加以下脚本进行客户端过滤。 代码:

    filterMenuInit: function(e) {
     if (e.field == "name") {
          alert("apply Filter");
          var filter = []
          ... // Generate filters
          grid.dataSource.filter(filters);
      }
    }

For detailed example: Extact from Kendo Examples

选项 2:服务器端过滤
-> 我对此不太了解,但是当我搜索过滤选项时,我遇到了以下问题,该问题很好,但对于我的应用程序来说有点复杂。但我认为你可以使用它。

JS Fiddle Sample

详细说明请引用下面的链接。

Reference: JS Kendo UI Grid Options

关于telerik - Kendo UI Grid 的过滤器未对指定列执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24797216/

相关文章:

javascript - 如何纯粹使用 AJAX 实现动态过滤并仍然保留可用的历史记录?

c# - 检测 ASP.NET 中的内存泄漏

telerik - 如何在 radgrid 中查找选定行的列值

javascript - VB.NET 中的虚假(但严重) "[WebElementId] is not declared"错误

excel - 在 VBA 中过滤范围

javascript - 带下拉菜单的 Angular 过滤

angularjs - 动态绑定(bind)剑道网格数据源绑定(bind)到指令

Angular2 typescript - kendo ui 网格列模板(单击)不起作用

javascript - Kendo UI 网格复选框列字段未定义

c# - 如何以编程方式在 DataTable 上使用 Telerik RadGrid FilterExpression