我正在尝试使用每行上的“编辑”按钮向网格添加列。我在Demo site上找到的代码非常适合添加按钮,但我无法弄清楚如何将项目ID(主键)添加到链接。您会注意到在我的示例中,我将其硬编码为“10”以测试链接。它有效,但有一种方法可以在循环中获取该ID以添加到我的链接中吗?
gridComplete: function(){
var ids = $("#list").jqGrid('getDataIDs');
for(var i=0;i < ids.length;i++){
var cl = ids[i];
be = "<input style='height:22px;' type='button' value='Edit' onclick=\"window.location.href='editItem.asp?ID=10'\" />";
$("#list").jqGrid('setRowData',ids[i],{act:be});
}
}
答案 0 :(得分:5)
我想你需要的是formatter:'actions'。请参阅the answer,其中我解释了它的工作原理,并包括the demo,它仅为演示目的生成了许多警报。如果您只需要本地编辑网格,请参阅和the demo。
答案 1 :(得分:1)
该ID是否存储在您的'cl'变量中?
be = "<input style='height:22px;' type='button' value='Edit' onclick=\"window.location.href='editItem.asp?ID="+cl+"'\" />";