JQGrid 确认框 post 保存编辑的数据

JQGrid confirmation box post saving edited data

我想在用户在 JqGrid 中编辑数据后单击“保存”时显示一个确认框。请在下面找到我的代码。

function FetchAccountMapping() {
    try {
        if (ValidateForm()) {
            var selectedsearchoption = $('#ddlSearchOption').val();

            $("#jqGrid").show();
            $("#jqGrid").jqGrid("clearGridData");

            if (!firstclick) {
                var url = '/utility/utilityhandler.aspx';
                $("#jqGrid").jqGrid('setGridParam', {
                    url: url,
                    postData: {
                        command: 'fetchmobileaccountmapping',
                        username: function () { return (selectedsearchoption == "username") ? $('#txtUsername').val() : ''; },
                        useremail: function () { return (selectedsearchoption == "useremail") ? $('#txtUseremail').val() : ''; },
                        useremailhash: function () { return (selectedsearchoption == "useremail") ? $('#txtUseremail').val().hashCode() : ''; }
                    },
                    onSelectRow: editRow
                });
                $("#jqGrid").trigger("reloadGrid");
            }
            else {
                $("#jqGrid").jqGrid({
                    url: '/utility/utilityhandler.aspx',
                    postData: {
                        command: 'fetchmobileaccountmapping',
                        username: function () { return (selectedsearchoption == "username") ? $('#txtUsername').val() : ''; },
                        useremail: function () { return (selectedsearchoption == "useremail") ? $('#txtUseremail').val() : ''; },
                        useremailhash: function () { return (selectedsearchoption == "useremail") ? $('#txtUseremail').val().hashCode() : ''; }
                    },
                    datatype: "json",
                    styleUI: "Bootstrap",
                    colNames: ["MobileAccountMappingID", "Username", "Email", "App Name", "Active"],
                    colModel: [
                        {
                            label: 'nMobileAppAccountUserMappingID',name: 'nMobileAppAccountUserMappingID',key: true,hidden: true,editable: true
                        },
                        {
                            label: 'Username',name: 'Username',width: 250,search: true,editable: true, editoptions: { readonly: "readonly" }
                        },
                        {
                            label: 'Email',name: 'Email',width: 500,search: true, editable: true, editoptions: { readonly: "readonly" }
                        },
                        {
                            label: 'nvcMobileAppName',name: 'nvcMobileAppName',width: 150,search: true, editable: true, editoptions: { readonly: "readonly" }
                        },
                        {
                            label: 'bDeactivated',name: 'bDeactivated',width: 150,editable: true,edittype: 'checkbox', editoptions: { value: "Yes:No" },
                        }
                    ],
                    viewrecords: true,
                    width: "auto",
                    height: "auto",
                    rowNum: 20,
                    loadonce: false,
                    pager: "#jqGridPager",
                    jsonReader: {
                        root: "Table",
                        repeatitems: false
                    },
                    gridview: true,
                    caption: "Mobile Account Mapping List",
                    //onSelectRow: editRow,
                    inlineEditing: {
                        keys: true
                    }
                });
                $("#jqGrid").jqGrid('inlineNav', '#jqGridPager',
                {
                    edit: true,add: false,del: false,search: false
                },
                {
                    zIndex: 100,
                    navkeys: false,
                    url: '/utility/utilityhandler.aspx?command=editnewsletter',
                    checkOnSubmit: true,
                    closeOnEscape: true,
                    reloadAfterSubmit: true,
                    afterComplete: function (response) {
                        var jsonResponse = $.parseJSON(response.responseText);
                        alert(jsonResponse.ResponseMessage);
                    }
                });
                firstclick = false;
            }
        }
    } catch (e) {
        alert(e);
    }
}

我试过checkOnSubmitbeforeSubmit。两者都不适合我。我尝试在 beforeSubmit 上调用一个函数并尝试在其中呈现一个对话框。即使这样也无济于事。

也许您应该 post 您的代码如何尝试使用 beforeSubmit 事件。 基本上这个事件应该 return array ( see Guriddo jqGrid documentation events )

您可以采用的简单方法是:

...
beforeSubmit : function( postdata, form , oper) {
    if( confirm('Are you sure you want to update this row?') ) {
        // do something
        return [true,''];
    } else {
        return [false, 'You can not submit!'];
    }
}

亲切的问候