在jqgrid中向行添加按钮

17 jqgrid

我想在网格中的每一行添加一个按钮,这将打开一个新窗口.在这个非常丰富的控件中看不到这个功能.必须遗漏一些东西

Cra*_*ntz 16

这是一个例子,来自jqGrid演示页面:

jQuery("#rowed2").jqGrid({ 
    url:'server.php?q=3', 
    datatype: "json", 
    colNames:['Actions','Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'], 
    colModel:[ 
        {name:'act', index:'act', width:75,sortable:false}, 
        {name:'id',index:'id', width:55}, 
        {name:'invdate',index:'invdate', width:90, editable:true}, 
        {name:'name',index:'name', width:100,editable:true}, 
        {name:'amount',index:'amount', width:80, align:"right",editable:true}, 
        {name:'tax',index:'tax', width:80, align:"right",editable:true}, 
        {name:'total',index:'total', width:80,align:"right",editable:true}, 
        {name:'note',index:'note', width:150, sortable:false,editable:true} 
    ], 
    rowNum:10, 
    rowList:[10,20,30], 
    imgpath: gridimgpath, 
    pager: jQuery('#prowed2'), 
    sortname: 'id', 
    viewrecords: true, 
    sortorder: "desc", 
    gridComplete: function(){ 
        var ids = jQuery("#rowed2").getDataIDs(); 
        for(var i=0;i<ids.length;i++){ 
            var cl = ids[i]; 
            be = "<input style='height:22px;width:20px;' type='button' value='E' onclick=jQuery('#rowed2').editRow("+cl+"); ></ids>"; 
            se = "<input style='height:22px;width:20px;' type='button' value='S' onclick=jQuery('#rowed2').saveRow("+cl+"); />"; 
            ce = "<input style='height:22px;width:20px;' type='button' value='C' onclick=jQuery('#rowed2').restoreRow("+cl+"); />"; 
            jQuery("#rowed2").setRowData(ids[i],{act:be+se+ce}) 
        } 
    }, 
    editurl: "server.php", 
    caption:"Custom edit " }
).navGrid("#prowed2",{edit:false,add:false,del:false}); 
Run Code Online (Sandbox Code Playgroud)

您也可以使用自定义格式化程序执行此操作.

  • 您以完全相同的方式添加按钮,但是在onclick中添加了不同的JavaScript方法.不,您不会覆盖saveRow或editRow.这会打破编辑! (2认同)

use*_*905 8

当前最高答案将自定义按钮代码放在loadComplete中.它应该是gridComplete.自问题得到解答以来,API可能已经发生了变化.


Kis*_*mar 6

在colModel中,您可以通过以下代码使用formatter进行格式化

formatter:function (cellvalue, options, rowObject) {    
    return "<input type='button' value='somevalue' onclick='some_function'\>";
}
Run Code Online (Sandbox Code Playgroud)