jqgrid使用delData通过内联删除传递额外参数

问题描述:

I have a jqgrid with an inline delete button. This button sends a post to a php file which would, in turn, go delete the record from the database. Unfortunately, I cannot seem to figure out how to send additional data with the post call. I don't want to rely on the row number. Rather, I wish to add the value from a column (childId) to the POST.

Here is my table:

jQuery("#team").jqGrid({
    url: 'TeamRetrieval.php?userId='+userId,
    datatype: "json",
    colNames: ['User Id', 'Email', 'Created', 'Delete'],
    colModel: [
        {name: 'childId', index: 'childId', align: 'center', sorttype: 'string'},
        {name: 'user_email', index: 'user_email', align: 'center', sorttype: 'string'},
        {name: 'user_registered', index: 'user_registered', align: 'center', sorttype: 'string'},
        { name: 'delete', formatter: 'actions', width: 40, align:'center', sortable: false,
            formatoptions:{
                keys: true,
                editbutton: false,
                editformbutton: false,
                delbutton: true,
                delOptions: { url: 'TeamRetrieval.php?userId='+userId}
             }
        }                
    ],
    mtype: "GET",
    sortorder: 'asc',
    sortname: 'childId',
    caption: "Existing Team Members",
});

This seems to me like it should be pretty straightforward. I did find an option delData in the documentation here:

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing&s[]=deldata

Another SO post showed Oleg suggesting delData can be used in the format options on an inline delete button, thus allowing one to pass additional parameters via the POST.

http://stackoverflow.com/questions/16798420/inline-delete-deloptions-how-to-add-additional-data-to-restful-post

However, there wasn't an example of how one would go about doing this. I'm pretty new to javascript (I come from java/c# land) and it isn't clear to me how to reference the column value from an array inside delData.

Could I please ask someone to explain how one would pass the value of the 'childId' column along in the POST which is made when the inline delete button is clicked?

Tony over at the jqgrid help forms was able to answer this. It is very easy to achieve what I describe, provided you know how to do it. =)

In order to pass parameters with jqgrid's default delete functionality, one must identify the fields they wish to pass as keys. For example, note the key:true below:

{name: 'childId', index: 'childId', align: 'center', sorttype: 'string', key:true}