在jqGrid生成的表格最后一列追加操作列:
//在colModel中添加(記得在colNames中加入'操作')
{name:'id',index:'id',align:'center',edittype:'button',formatter:function(cellValue,options,rowData){
//console.log(cellValue);
//console.log(options);
//console.log(rowData);
btnstr="<button class='btn btn-danger' onclick='delRow("+rowData.id+")' >刪除</button>";
return btnstr
}}
或者
{name:'id',index:'id',align:'center',edittype:'button',formatter:btn_del}
function btn_del(cellValue,options,rowData){
console.log(cellValue,options,rowData);
btnstr="<button class='btn btn-danger' onclick='delRow("+rowData.id+")' >刪除</button>";
return btnstr;
}
輸出:
cellValue輸出的是單元格值(例子中為id的值)
options輸出的是表格配置相關(guān)的json對(duì)象
rowObject輸出的是當(dāng)前行的數(shù)據(jù)json對(duì)象
那么就通過(guò)rowObject就可得到當(dāng)前行數(shù)據(jù)的id(不是序列號(hào)),從而實(shí)現(xiàn)操作
注意事項(xiàng):
name屬性最好選擇當(dāng)前行數(shù)據(jù)的id
除了cellValue,option,rowData還有第四個(gè)參數(shù)輸出為"add"(暫不知什么作用,吊大的請(qǐng)回復(fù),學(xué)學(xué)習(xí))
具體api請(qǐng)看官方文檔http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter
本文中用是jqGrid 4.6.0 新手學(xué)習(xí),有錯(cuò)請(qǐng)回復(fù)指出,不甚言謝