Reset again and persist the data of JqGrid Row in

2019-09-12 10:51发布

问题:

enter image description hereIn "successfunc" the else part should retain the row in editable mode ...

 var editparameters= {
                    "keys": true,
                    "oneditfunc": function () {
                        debugger;
                        $("select#" + arrprimarykey + "_StateName").val(rowData.StateCode);
                    },
                    "successfunc": function (data) {
                        debugger;
                        var msg = JSON.parse(data.responseText).Message;
                        var msgType = JSON.parse(data.responseText).MsgType;
                        if (msgType == "S") {
                            alert(msg);
                            $(CityMaster.idGrid).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
                        } else {
                            alert(msg)
                           HERE RESTORE TO INLINE EDITABLE MODE THE ROW ,AGAIN IF ERROR RETURN FROM SERVER
                        }
                    },

                    "url": CityMaster.EditUrl,
                    "extraparam": {},
                    "aftersavefunc": function (data) {
                        debugger;
                    },
                    "errorfunc": null,
                    "afterrestorefunc": function (data) {
                        debugger;
                        $(CityMaster.idGrid).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
                    },
                    "restoreAfterError": true,
                    "mtype": "POST"
                }
                jQuery(CityMaster.idGrid).jqGrid('editRow', arrprimarykey, editparameters);

In "successfunc" the else part should retain the row in editable mode ...

回答1:

The standard way of reporting the error in jqGrid is setting an error status code of HTTP response. If will force executing of errorfunc for example in case of usage inline editing. If the server code unable to set error status code of HTTP response then jqGrid provides an alternative. The callback successfunc can be used to examine the response of the server. The successfunc should inform jqGrid whether the response is successful of now. The callback successfunc should return array [true] in case of successful response and return array with two elements: [false, "error message to display the user"] in case of the error. The callback successfunc get typically the error message from the response from the server.

UPDATED: You should of case use restoreAfterError: false (see "restoreAfterError": true in your current code) to prevent restoring the state of the row before starting inline editing.