jqGrid - Adding edit buttons to each row
I'm trying to add a column to the grid with an Edit button on eac开发者_如何学编程h row. The code I found on the Demo site works great for adding the button but I can't figure out how to add the item id (primary key) to the link. You'll notice in my example I have it hard coded in as "10" for testing the link. It works, but ss there a way to grab that ID in the loop to add to my link?
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});
}
}
I suppose what you need is the formatter:'actions'. See the answer where I explain how it works and included the demo which produced many alerts for demo purpose only. See also and the demo if you need only local editing of grid.
Isn't that ID stored in your 'cl' variable?
be = "<input style='height:22px;' type='button' value='Edit' onclick=\"window.location.href='editItem.asp?ID="+cl+"'\" />";
精彩评论