【问题标题】:add a custom button along with action formatter in jqgrid在 jqgrid 中添加自定义按钮以及动作格式化程序
【发布时间】:2012-07-06 12:15:31
【问题描述】:

我有一个这样的 jqgrid

colNames: ['Name','Actions'],

 colModel: [

        { name: 'name', index: 'name', align: 'right', editable: true},
{ name: 'act', index: 'act', width: 75, align: 'center', sortable: false, formatter: 'actions',formatoptions: {keys: true,delbutton:false}}
],

现在我想添加一个自定义按钮以及动作格式化程序的编辑按钮。

我试过了,好像没有用,有什么原因吗?

gridComplete: function(){
    var ids = $("#grid").jqGrid('getDataIDs');
    for(var i=0;i < ids.length;i++){
        var cl = ids[i];
        alert(cl);
        be = "<input style='height:22px;' type='button' value='Edit' onclick=\"window.location.href='editItem.asp?ID="+cl+"'\"  />";

        $("#grid").jqGrid('setRowData',ids[i],{act:be});
    }   
},

【问题讨论】:

  • 我认为您应该编写自己的格式化程序,因为您不使用删除操作,并且您想自定义编辑按钮。
  • 不,我想保持我的编辑按钮不变,而且我想在编辑的同时再添加一个按钮。那你能给我举个例子吗?

标签: jquery asp.net-mvc jqgrid


【解决方案1】:

如果我理解正确您的要求,您将在 thisthis 旧答案中找到您问题的答案。

【讨论】:

  • 谢谢先生,乌拉救生员……这正是我在寻找的……信不信由你,我在等你的答案……谢谢你……:)
【解决方案2】:

这是一个自定义格式化程序的示例(假设您使用您的项目 ID 设置“Actions”列的值):

<script>
    var myCustomFormatter = function(cellVal,options,rowObject) {
        return "<input style='height:22px;' type='button' value='Edit' onclick=\"window.location.href='editItem.asp?ID="+cellVal+"'\"  />";  
    };

    $("#yourTableID").jqGrid({
        ....
        colNames: [....,'Actions'],
        colModel: [
            ....
            { name: 'act', index: 'act', width: 75, align: 'center', sortable: false, formatter:myCustomFormatter}
        ],
        ....
    });

</script>

阅读jqGrid documentation 了解自定义格式化程序。

【讨论】:

  • 就是想问这个问题,action formatter 和 custom formatter 可以一起去吗??当我获得代码访问权限时,我会实现这个......
  • @PiyushSardana,我不认为,你可以在 jqGrid 源代码中扩展动作格式化程序。
  • 你确定吗?因为如果你是真的,那么我想我会实施这些改变,但你确定没有其他办法吗?
  • @PiyushSardana 在我看来,最简单的方法是编写自己的自定义格式化程序:)!在 jqGrid 论坛上提问,如果您需要更多信息,我不能再帮助您了,对不起。
猜你喜欢
  • 2014-02-10
  • 2012-04-10
  • 1970-01-01
  • 2012-05-29
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 1970-01-01
  • 2012-07-29
相关资源
最近更新 更多