jqGrid saveRow with an error function
This might be a 2 part question. First one is "what am I doing wrong" and 2nd is 开发者_JAVA百科"is this the right way?". Anyway...
I'm attempting to save an edited row with jqgrid and for some reason I've yet to identify, I can't get the error event to fire using inline editing.
table.saveRow(rowId,
false,
false,
optionalParams,
false,
function () { common.ShowMeSomething("error fired"); },
false);
All ShowMeSomething does is an alert right now, no big deal, but will not fire. I've went as far as opening up the source, and it's an $.extend with complete: function(res,stat) -- I've attempted to mimic those with a return Json(new { res = "hi", stat = false }) with no luck on it walking down the javascript to fire off the error event. No luck.
Also, is there a better way to do this? I need the errors back for validation reasons.
The problem was unclear documentation. In some of the grids functionality, error == false and success == true which is not the case. The first parameter is the rowId, the second is a successful call to the server (basically, does it exist and did I get an http response) where what I expected is reserved for utter failures that I wasn't able to create.
Moving the function to this second parameter and doing the error handling from the result allows for what I wanted -- simple return Json(whateverObject) and do what needs to be done from there such as reset, show errors, etc.
You don't include the code of your jqGrid and the code of MVC controller action which produce the error. So I could only guess what is the reason of your problem.
One reason in the server part could be that you try to return the error as a Json(...)
and not change the HTTP response status code to an error code. In case of an error you can either set the response code with the code like HttpContext.Response.StatusCode = 500
or use HttpException.
Another possible reason on the client side is that you try to save a row which is not currently edited with respect of editRow. The method editRow set additional attribute "editable"="1" for the editing row and saveRow save only the row having this attribute.
It you would be include more client and server code in the body of your question one could better help you.
精彩评论