onSelectRow: function(id){
if(id && id!==lastSel){
jQuery(this).restoreRow(lastSel);
lastSel=id;
}
jQuery(this).editRow(id,true,null,
function(response, postdata){
var data = eval('(' + response.responseText + ')');
data.result.success ? alert('success') : alert('error')
});
}
In this case I can handle errors, but after this row data restored.
The question is how to prevent restoring row if data.result.success == false
?
If I edit through modal box, then all is ok. But in inline mode doesn't.
I wanted to fix the same scenario and I could by doing:
And in grid model:
editRow function has the following parameters:
You current code use
succesfunc
only. It is important, that the server return some HTTP status code which are grater or equal to 400. Then the server response will be interpret as error by jQuery.ajax and jqGrid. To display any error message or for any other action in case of error you should use errorfunc parameter of the editRow function.One more small remark. You should use jQuery.parseJSON or
JSON.parse
instead of the usage ofeval
.UPDATED: I answer here on your questions from the comment. Why it is important to use
errorfunc
and not alwayssuccesfunc
? There are different reason. If you fill the box having the label sugar with the salt, it could has bitter consequences in your kitchen. Exactly the same is in case of wrong usage different callback functions of theeditRow
. I can give just some examples:What I wrote about the working with errors is the general rule. jqGrid defines many events in case of errors. For example loadError for the grid filling, errorTextFormat for all types of form editing, errorCell for the cell editing and errorfunc for inline editing. All the methods are based on the fact that in case of error the server response has the HTTP status code which corresponds the error (are grater or equal to 400).