donglei2022 2014-10-06 16:49
浏览 120
已采纳

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?

展开全部

  • 写回答

1条回答 默认 最新

  • duangao7133 2014-10-25 16:14
    关注

    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}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部