如何将数据从JQGrid发送到我的查询以删除行?

Lou*_*Lou 1 coldfusion jquery jqgrid

我无法从我的JQGrid中删除一行,因为我无法弄清楚如何将我需要的数据发送到包含MySQL的文件.我正在使用ColdFusion.

在我的JQGrid文件中,我的editurl参数设置如下:

editurl: url+"process_delete.cfc?method=process_delete&region="+region,
Run Code Online (Sandbox Code Playgroud)

在我的process_delete.cfc文件中,我保存了我的MySQL查询,我有:

DELETE FROM awesome_table
WHERE region = '#region#' AND Field1 = '??????' AND Field2 = '???????'
Run Code Online (Sandbox Code Playgroud)

我知道MySQL正在到达 - 没有问题.此外,该区域从URL填充得很好.没有问题.问题是我无法弄清楚如何从我想要删除的行中访问数据以填充Field1和Field2,从而有效地完成查询.有人可以帮忙吗?谢谢.

对于删除,我有以下代码:

jQuery.jgrid.del = {
            caption: "Delete Item",
            msg: "Delete record?",
            bSubmit: "Delete",
            bCancel: "Cancel",
            beforeSubmit: function(postdata, formid) { 
                var rowid = $("#mygrid").getGridParam('selrow');
                $("#mygrid").jqGrid('saveRow',rowid,false,'clientArray');
                var rowvalues = $("#mygrid").getRowData(rowid);
                return [true, ""]
            }
Run Code Online (Sandbox Code Playgroud)

当我rowid在警告消息框中显示时,我得到"null",所以也许这就是我的问题所在.

Ole*_*leg 6

您可以使用delData属性field1field2定义为函数,也可以使用onclickSubmitbeforeSubmit在其中动态修改URLDELETE操作中使用的属性或使用serializeDelData回调.最好的方法可能取决于您使用的其他选项(例如,取决于mtype用于删除操作).在答案中,我包括了对其他答案的引用,这些答案详细说明了所有方法.

例如,您可以使用

onclickSubmit: function (options, rowid) {
    // we suppose that use don't use multiselect: true option
    // in the case rowid parameter if the string with the id of the
    // deleted row

    // we can get the data about the deleted row with respect of
    // getCell, getLocalRow or getRowData methods
    var rowData = $(this).jqGrid("getRowData", rowid);

    // now we can modify the URL used in the Delete operation
    options.url += "?" + $.param({
        field1: rowData.field1,
        field2: rowData.field2
    });

    return {}; // you can return additional data which will be sent to the server
}
Run Code Online (Sandbox Code Playgroud)