【问题标题】:Kendo UI filter on boolean布尔值上的剑道 UI 过滤器
【发布时间】:2014-06-26 16:35:36
【问题描述】:

是否可以有一个过滤器菜单,其中包含是、否、其他等选项

我有一个网格,其中有一列只能包含 3 个值 Yes、No 或 Other。过滤器应该显示带有这些值的单选按钮和两个按钮过滤器和清除。这可能吗?

当我尝试使用字段类型:“布尔”时,我得到“是”和“否”,但如何添加第三个单选按钮“其他”。

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: kendo-ui


    【解决方案1】:

    剑道在这里有一个如何做到这一点的例子:
    http://demos.telerik.com/kendo-ui/grid/filter-menu-customization

    这是一个示例,说明您的过滤器可能会如何设置

    filterable: {
      //hide second filter option
      extra: false,
      operators: {
        string: {
          eq: "Is equal to"
        }
      }
    },
    filterMenuInit: function(e) {
      //when the filter menu opens find the first dropdown and hide it
      //as it has the Is equal to filter in it.
      e.container.find(".k-dropdown").eq(0).hide();
    }
    

    这里是展示如何使用其中一些功能的 JSbin: http://jsbin.com/qehugexo/2/edit


    更新
    虽然我可以让单选按钮显示在过滤器窗口中,但安装它是一件令人头疼的事情,并且使用默认的 Kendo 东西非常hacky。我建议使用演示中显示的 Kendo Dropdown,或者只是在网格本身的数据源上操作过滤器。

    可以用这样的代码来完成:

    $(".k-grid").data("kendoGrid").dataSource.filter({filters: [{field: "City", operator: "eq", value: "Boston"}], Logic: "and"})
    

    这是一个如何使用它的示例。

     filterMenuInit: function(e) {
       //when filter menu opens toss it cause its lame!
       e.container.html("
         <input name='radio' type='radio' checked='checked' value='Clear'>Clear</input>  
         <input name='radio' type='radio' value='London'>London</input>
         <input name='radio' type='radio' value='Seattle'>Seattle</input>
       "); 
    
    
    
      $("input[type=radio]").click(function(){
        if($(this).val() != "Clear") {
          $(".k-grid").data("kendoGrid").dataSource.filter({filters: [{field: "City", operator: "eq", value: $(this).val()}], Logic: "and"})
        }else {
          $(".k-grid").data("kendoGrid").dataSource.filter({})
        }
       });
      }
    

    还有一个更新的 JSbin:http://jsbin.com/qehugexo/3/edit

    【讨论】:

    • 感谢您的回复。我正在使用版本 v2012.2.710(不是最新的)。此代码显示了如何隐藏下拉列表,但是如何添加三个带有过滤器和清除按钮的单选按钮(是、否、其他)?
    • 我希望能回答你的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多