向jqgrid中的行添加按钮

向jqgrid中的行添加按钮,jqgrid,Jqgrid,我想在网格中的每一行添加一个按钮,以打开一个新窗口。在这个非常丰富的控件中看不到此功能。一定是遗漏了什么以下是jqGrid演示页面中的一个示例: jQuery("#rowed2").jqGrid({ url:'server.php?q=3', datatype: "json", colNames:['Actions','Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'], colModel:[

我想在网格中的每一行添加一个按钮,以打开一个新窗口。在这个非常丰富的控件中看不到此功能。一定是遗漏了什么

以下是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}); 
jQuery(#rowed2”).jqGrid({
url:'server.php?q=3',
数据类型:“json”,
colNames:['Actions','Inv No','Date','Client','Amount','Tax','Total','Notes'],
colModel:[
{name:'act',index:'act',width:75,sortable:false},
{名称:'id',索引:'id',宽度:55},
{名称:'invdate',索引:'invdate',宽度:90,可编辑:true},
{name:'name',index:'name',宽度:100,可编辑:true},
{名称:'amount',索引:'amount',宽度:80,对齐:“right”,可编辑:true},
{名称:'tax',索引:'tax',宽度:80,对齐:“right”,可编辑:true},
{名称:'total',索引:'total',宽度:80,对齐:“right”,可编辑:true},
{名称:'note',索引:'note',宽度:150,可排序:false,可编辑:true}
], 
rowNum:10,
行列表:[10,20,30],
imgpath:gridimgpath,
寻呼机:jQuery(“#prowed2”),
sortname:'id',
viewrecords:是的,
巫师:“描述”,
gridComplete:函数(){
var id=jQuery(“#rowed2”).getDataId();

对于(var i=0;i当前最高答案将自定义按钮代码放在loadComplete中。它应该是gridComplete。自回答问题以来,API可能已更改。

这可能会有所帮助。请参阅此页和Oleg。

我正在使用jqgrid显示联系人列表。我有一个名为“角色”的列带有“定义”按钮,您可以单击该按钮并将该联系人的角色重新定义为主要、次要、销售或其他

最初,button元素通过XML发送到网格单元格,其中$rowid是行的id(PHP):


换句话说,setRowData方法在autoencode设置为true时不起作用,但是可以在gridcomplete事件中根据需要操纵DOM。

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

formatter:function (cellvalue, options, rowObject) {    
    return "<input type='button' value='somevalue' onclick='some_function'\>";
}
格式化程序:函数(cellvalue、options、rowObject){
返回“”;
}

这将只启用保存和编辑按钮,我想要的是启动一个打开新窗口的函数。我想我只是覆盖了.saveRow或.editRow。您以完全相同的方式添加按钮,但在onclick中添加了不同的JavaScript方法。不,您不会覆盖saveRow或editRow。这将中断编辑!不要忘记添加在jqgrid config autoencode:false中,您的示例都与导航栏相关。查询者要求在数据行中输入一个按钮。
gridcomplete: function() {
    var ids = $grid.getDataIDs();

    for (var i=0;i<ids.length;i++){
        var cl = ids[i],
        button = '<button data-idx="'+cl+'" class="contact_role_button btn" title="Define Role...">Define</button>';
        if (cl.substr(0,2) !== "jq") {
            $('#'+cl).find('td[aria-describedby="list_role"]').html(button);
        }
    }
}
formatter:function (cellvalue, options, rowObject) {    
    return "<input type='button' value='somevalue' onclick='some_function'\>";
}