【问题标题】:Remove options from Kendo Grid filter从 Kendo Grid 过滤器中删除选项
【发布时间】:2016-03-29 13:41:25
【问题描述】:

我尝试从 Kendo 网格过滤器的下拉列表中删除一个项目。但它仍然被渲染。我怎样才能达到这种行为?

$("#grid").kendoGrid({
  columns: [
    { field: "someDate", type: "date" }
  ],
  dataSource: [
    { someDate: "2016-3-29"},
    { someDate: "2016-3-30"}
  ],
  filterable: {
    extra: true,
    operators: {
      date: {
        gte: "Is after or equal to",
        lte: "Is before or equal to"
      }
    }
  },
  filterMenuInit: function(e) {
    e.container.find("select:eq(0)>option")[1].remove();
    e.container.find("select:eq(1)>option")[1].remove();
    e.container.find("select:eq(2)>option")[0].remove();
  }
});

dojo 上的链接。 请帮忙。

已编辑: 我需要两个复杂的日期过滤器。在第一个过滤器中,我只需要“在或等于之后”,然后是“AND”,在第二个过滤器中,我只需要“在或等于之前”。我尝试通过从第一个下拉列表中删除“之前或等于”并从第二个下拉列表中删除“之后或等于”来做到这一点。

【问题讨论】:

    标签: javascript kendo-ui telerik kendo-grid


    【解决方案1】:

    你可以只添加你想要的而不是删除

      filterable: {
                     extra: false,
                     operators: {
                     string: {
                      startswith: "Starts with",
                      eq: "Is equal to",
                      neq: "Is not equal to"
                              }
                            }
                  },
    

    【讨论】:

    • 这对我没有帮助。我需要两个复杂的日期过滤器。在第一个过滤器中,我只需要“在或等于之后”,然后是“AND”,在第二个过滤器中,我只需要“在或等于之前”。我不能这样做。
    • 为了更清晰,我添加了一些细节。
    【解决方案2】:

    您需要获取 kendoDropDownList 对象,然后从 dataSource 中移除该项;我已经更新了你的dojo

    <script>
        $("#grid").kendoGrid({
            columns: [
                { field: "name" }
            ],
            dataSource: [
                { name: "Jane Doe"},
                { name: "John Doe"}
            ],
            filterable: true,
            filterMenuInit: function(e) {
            if (e.field == "name") {
                var filter1 = e.container.find("select:eq(0)").data("kendoDropDownList");
                var filter2 = e.container.find("select:eq(2)").data("kendoDropDownList");
                filter1.dataSource.remove(filter1.dataSource.at(0));
                filter1.select(0);
                filter2.dataSource.remove(filter2.dataSource.at(0));
                filter2.select(0);
              }
           }
        });
    </script>
    

    【讨论】:

    • 第一次加载网格时有效。但是,如果您按下清除按钮,第一个下拉菜单将被重置为空值。我猜它设置了被删除的默认值。
    • 这在技术上是一个 hack,因为它设置了一个打算私有的成员的值......但它有效...... filter1._initial = 'lte'; dojo.telerik.com/EPegi/11
    【解决方案3】:

    请参阅下面的示例,在字段部分使用 filterable: false 从列中删除过滤器。

    <div id="grid"></div>
    <script>
    $("#grid").kendoGrid({
      columns: [
        { field: "name", filterable: false },
        { field: "age" }
      ],
      filterable: true,
      dataSource: [ { name: "Jane", age: 30 }, { name: "John", age: 33 }]
    });
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多