【问题标题】:adding button on column template of kendo grid在剑道网格的列模板上添加按钮
【发布时间】:2014-04-23 12:06:33
【问题描述】:

我正在使用 MVC 构建一个应用程序,使用 Jquery(KendoGrid) 来显示数据,一切都按要求正常工作,后来我们计划在网格的每一行上添加带有按钮的额外列,听起来很简单,但尝试了数字添加到应用程序中的方法,收到错误消息“未定义的'节点'.....”,所以我没有其他选择,只能在这里发布,如果有人能帮助我,我将不胜感激,我在 jquery kendo 网格上使用了列模板谢谢

场景

onclick 指定行中的该按钮应带有“ID(如下所示)”并重定向到“ActionResult”控制器,我可以在其中进一步编码我的要求

代码(部分代码)

columns: [
                { field: "ID", Title: "ID", filterable: false, sortable: false, hidden: true },

                { field: "RowID", Title: "RowID", filterable: false, sortable: false, hidden: true },

                { field: "BillNumber", Title: "BillNumber", filterable: false, sortable: false,hidden:true },

                { field: "ServiceName", Title: "ServiceName",width:600 },

                { field: "ServiceStatus", Title: "ServiceStatus", width: 150 }
// Creating template column

               , {
                   field: "Action", title: "Is Action", template: "<input type=\"checkbox\"    #= Action ? checked='checked' : '' #  class=\"check_row\"/> ", editable: false,

                  // field: "Action",title: "Preview ", template: '<input type="button" class="info" name="info" value="Info" style="height: 26px; margin: 0px 2px; min-width: 64px;" />',                       

    headerTemplate: '<label>  <input type="checkbox" id="checkAll"/>Print All</label>', filterable: false, sortable: false, width: 100,                     
               }

目前我能够在列中生成复选框,我需要的是多一列带有按钮(与每一行中的复选框相同)

Manjuboyz

【问题讨论】:

  • 查看我对以下帖子的回答,我在每一列中都显示了一个下拉列表,您应该能够操作代码来添加一个按钮。 stackoverflow.com/questions/23217890/…
  • 嗨 C Sharper 感谢您的回复,但我没有使用“columns.bound”或“客户端模板”,我不想编辑我的任何代码(因为它按照我的要求),请建议我可以编辑的代码

标签: asp.net-mvc-4 kendo-ui


【解决方案1】:

在单元格中定义一个按钮非常简单......基本上你做对了。

示例:将列定义为:

columns: [
    ...
    {
        title: "Preview ", 
        template: '<input type="button" class="k-button info" name="info" value="Info" />',                       
        headerTemplate: '<label>  <input type="checkbox" id="checkAll"/>Print All</label>', 
        filterable: false, 
        sortable: false, 
        width: 100                     
    }
]

template 定义为input 类型的button。如果你想让它看起来像一个 Kendo UI 按钮,请将 k-button 类添加到它。

然后,您可以绑定 click 处理程序:

$(".info").on("click", function() {
    var row = $(this).closest("tr");
    var item = grid.dataItem(row);
    ...
});

其中item 包含与您单击按钮的行对应的所有数据。

在这里运行示例:http://jsfiddle.net/m8fsv/1/

编辑:如果您需要控制/决定显示其中一个,您应该将模板更改为:

<script id="template" type="text/kendo-template">
    # if (showButton) { #
    <input type="checkbox" #= data.Action ? checked="checked" : "" #  class=\"check_row\"/>
    # } else { #
    <input type="button" class="k-button info" name="info" value="Info" />
    # } #
</script>

您可以在这里查看:http://jsfiddle.net/OnaBai/m8fsv/12/

【讨论】:

  • 您好 OnaBai,谢谢您的回复,我相信我什至尝试过这一步,但它没有再生成一列(我需要复选框和按钮),我尝试了您的方式并弹出此错误在 IE 中“0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性 'nodeName' 如果有针对此异常的处理程序,则可以安全地继续程序。”
  • 或者对大家来说,我心中有一个要求,我不知道能不能做到,如果能做到,那我就准备好了。除了获得复选框和按钮的不同列之外,我是否可以像在同一个网格上一样拥有带有按钮和复选框的单列(基于条件的任何一个),在选择“ printall"(headertemplate) 它应该只获取复选框而不是按钮的值,如果可能,请告诉我,谢谢
  • 如果我评论复选框代码然后启用您提供的按钮代码,那么没有错误,它会生成一个按钮列!!!但是当复选框和按钮都未注释时,它会产生上述错误(基本上就像只允许任何一列而不是两者一样),我做错了吗???如果需要愿意分享更多关于此的代码,谢谢
  • 两者都没有问题 (jsfiddle.net/OnaBai/m8fsv/12) 唯一的问题是,如果没有收到 Action,您应该检查 data.Action 而不仅仅是 Action (&lt;input type=\"checkbox\" #= data.Action ? checked="checked" : "" # class=\"check_row\"/&gt;)跨度>
  • ,如果我将我的复选框模板代码替换为您的小提琴,它只显示复选框行,而不是按钮??关于我的要求,它应该连续具有复选框或按钮(不是两者),例如仅第一行按钮,仅第二和第三复选框等等,基于任何条件?谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 2013-01-12
  • 1970-01-01
  • 2014-10-10
  • 1970-01-01
  • 1970-01-01
  • 2013-09-15
相关资源
最近更新 更多