【问题标题】:How to add a checkbox column to a Kendo grid如何将复选框列添加到剑道网格
【发布时间】:2012-08-25 23:05:43
【问题描述】:

我正在尝试将复选框列添加到 KendoUI 网格。 这是fiddle

我已关注剑道论坛的this 帖子。
有人可以指出我在这里做错了什么。

这是相关代码:

data-columns = '[
    {"field":"Name", "filterable":true},
    {"field":"Price", "filterable":false},
    "UnitsInStock",
    {"field":"Recon"},
    "template": "<input type='checkbox' #= (Recon == true) ? checked ='checked' : '' # disabled />"
]'

【问题讨论】:

    标签: kendo-ui kendo-grid


    【解决方案1】:

    将您的列更改为:

    [{"field":"Name", "filterable":true}, {"field":"Price", "filterable":false}, "UnitsInStock", {"field":"Recon", "template": "<input type=\"checkbox\" />" }]'
    

    你的语法有一些错误,还有一些未转义的引号。

    希望这会有所帮助。

    【讨论】:

    • 确实有帮助。非常感谢。现在它显示复选框字段。但默认情况下所有复选框都未选中。有没有办法根据视图模型中的值来改变复选框的选中状态。
    • 添加这个输入元素: '# if(Recon){ # checked #} #' ,应该这样做!
    • 我能知道我应该在输入元素中为哪个属性分配这个值吗?
    • "Checked" 是属性,不需要值。模板中的输入元素应如下所示: ''
    • 我自己想出来的... {"field":"Recon", "template": ""} 我最初认为这两个单引号是答案的一部分。谢谢@Logard,你拯救了我的一天
    【解决方案2】:

    您可以简单地添加一列作为复选框列。

    data-columns = '[
    {"field":"Name", "filterable":true},
    {"field":"Price", "filterable":false},
    "UnitsInStock",
    {"field":"Recon"},
    { selectable: true, width: "50px" } //selectable means it's a checkbox column
    ]'
    

    【讨论】:

      【解决方案3】:

      在模板部分使用 CheckBox 参见下面的示例:

       {
          title: "Deck Options",
          field: "DeckOption",
          template: "<input type='checkbox' #= (DeckOption == true) ? checked ='checked' : '' # disabled/>",
          width: "7%",
          sortable: {
          mode: "single",
          allowUnsort: false
          }
      

      【讨论】:

      • 欢迎来到 SO。请添加解释如何解决 OP 的问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 2013-06-27
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多