Mark P.
Mark P.

Reputation: 282

jqGrid - Adding edit buttons to each row

I'm trying to add a column to the grid with an Edit button on each 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});
    }   
}

Upvotes: 1

Views: 10137

Answers (2)

Oleg
Oleg

Reputation: 221997

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.

Upvotes: 5

Damb
Damb

Reputation: 14600

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+"'\"  />"; 

Upvotes: 1

Related Questions