如何在 Kendo 网格加载后关闭对特定列的过滤?

How to switch off filtering for a certain column in Kendo grid after it's loaded?

我有一个 kendo 使用通常的 MVC Razor 语法创建的网格。

例如,

    @(Html.Kendo().Grid<exampleViewModel>()
    .Name("ExampleGridName")
    .DataSource(ds => ds
        .Ajax()
        .Read(read => read.Action("ExampleMethod", "ExampleClass"))
    .Columns(c =>
    {
        c.Bound(m => m.Id);
        c.Bound(m => m.FirstName);
        c.Bound(m => m.LastName);
    });
    .Filterable())

我的问题:在使用 jquery 加载网格后,有没有办法关闭像 "LastName" 这样的列的过滤?

我成功地遍历了各列并确定了我需要关闭过滤的列。我尝试将 filterable 属性 设置为 false 但它不起作用。也许是因为它看起来像一个对象类型。

我在尝试重用网格时遇到了这个问题,但在页面加载期间必须应用不同的过滤器。过滤器工作但当过滤器被清除时,网格被完全重置。当我在 运行 时间关闭过滤器时,重置将重置但在加载期间保持应用过滤器。

查看我根据 Telerik 自己的过滤器网格演示创建的这个 dojo,让我知道这是否适合您 filter demo

我添加到演示中的代码。

  $(document).ready(function () {
  var preventFilter = 'City'

  console.log($('th[role="columnheader"]').length);
  $('th[role="columnheader"]').filter('[data-role="filtermenu"]').each(function (item) {


      if ($(this).attr("data-field") == preventFilter) {
          console.log('matched')
          $(this).attr("data-role", "");
          $(this).find("a").remove();
          $(this).removeClass('k-filterable');
      }

  });

}); 需要明确的是,它会从“城市”列中删除过滤器 link。这是在初始化网格时添加的。

这基于 header 中的过滤器项目起作用,如果您启用了菜单或行功能,那么您将需要适当地更改代码。

很高兴这对您有所帮助。