0

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 ...

shyam shankar
  • 25
  • 1
  • 8

1 Answers1

0

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.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • you mean this way:if (msgType == "S") { alert(msg); $(CityMaster.idGrid).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid'); } else { alert(msg); return [false, msg]; } – shyam shankar Oct 23 '15 at 09:14
  • @shyamshankar: Almost so, but you need make some changes in the above code. First of all you should understand that `.trigger('reloadGrid')` works **synchronously**, So your above code will start and probably process the reloading of grid first and then returns from `.trigger('reloadGrid')` and will continue the current executing. I recommend you never use `.trigger('reloadGrid')` directly in your code and wrap it inside of `setTimeout` instead. It will allows to process the current callback till the end end only after that to start processing of `.trigger('reloadGrid')`. – Oleg Oct 23 '15 at 09:22
  • @shyamshankar: the corresponding code could be something like: `if (msgType == "S") { alert(msg); setTimeout(function () {$(CityMaster.idGrid).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');}, 0); return [true]; } else { alert(msg); return [false, msg]; }` You can replace the second parameter of `setTimeout` from `0` to `50` for example, but 0 should already work. Such code returns either `[true]` or `[false, msg]`, process `successfunc` till the end and only then start `setTimeout` which would trigger reloadGrid. – Oleg Oct 23 '15 at 09:25
  • i want to set my JQGrid Row In INLINE editable mode ,when msgType return other than "S" from SERVER. – shyam shankar Oct 23 '15 at 09:42
  • @shyamshankar: I see you made small error in your code. You use `restoreAfterError: true` instead of `restoreAfterError: false`. It's exactly the setting which informs jqGrid to restore the old values from the line (the state before starting inline editing) or to hold inline editing after displaying the error message. You have to combine correct implementation of `successfunc` (return `[false, msg]` in case of error) with the option `restoreAfterError: false`. – Oleg Oct 23 '15 at 10:00