views:

40

answers:

1

I'm doing some inline editing on the jqgrid. The client wants a confirmation dialog to appear that the user really wanted to save the changes made (similar to how delete works). In looking at http://github.com/tonytomov/jqGrid/blob/master/js/grid.inlinedit.js I've noticed that the editRow command takes these parameters.

table.jqGrid('editRow', id, true/keys/, function(){alert('1');}/oneditfunc/, function(){alert('1.5'); return false;}/successfunc/, null/url/, null/extraparam/, function(){alert('2');}/aftersave/, function(){alert('3');}/error/, function(){alert('4');}/afterrestore/);

when i start editing the oneditfunc gets called. after the post to the server successfunc get's called and then afterrestore gets called. It seems that there should be a beforeSave or something like that?

These parameters get used and sent to the saveRow function. It doesn't look like there is anywhere where I can inject a method to abort the sending of the data or popup a the modal window to confirm the changes being made.

Is this oversight on my part or is this some functionality that I'll have to bake into the jqgrid?

+1  A: 

One way to solve your problem is to use custom validation editrules. Before the data will be send to the server it will be validated. The only disadvantage of the approach is that if the user decide not to send the data, the error message with the text which you mostly produce will be displayed.

Another way will be the usage of serializeRowData together with the errorfunc (the parameter of the editRow). Typically serializeRowData parameter of jqGrid will be used to modify or encode the data which will be send to the server. So if you display inside of the function a conformation dialog and send no data or a dummy wrong data to the server in the case, the server can answer with the known error. Then inside of your errorfunc you can ignore this special error. So you can solve the problem with the error message. After all because of error jqGrid call "restoreRow" and the original data will be restored.

Oleg
right now i'm exploring cellediting since it has a beforeSubmitCell event. I'm still trying to figure out how to access the default modal popup but I'm starting to think I'm going to have to just create a new one for my purpose. So much for code re-usability.
Steve
but that's not looking too helpful since beforeSubmitCell can't cancel the post. FRUSTRATING.
Steve
and I want to be able to cancel the post not bother the server with dummy requests.
Steve
@Steve: You can overwrite any parameter on the `ajax` request with respect of `ajaxRowOptions` (see http://github.com/tonytomov/jqGrid/blob/master/js/grid.inlinedit.js#L217), for example `url`. So you can not send the data to the server in the case if you don't want to do this.
Oleg
@Oleg, I had a terrible time trying to find out the props for ajaxRowOptions and ajaxOptions ... is this documented anywhere?
Steve
@Steve: see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#saverow scroll till the table with the Properties. See also http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods#common_functions_and_settings
Oleg
@Oleg, this doesn't really tell me the complete objects events, "This option allow to set global ajax settings for the row editiing when we save the data to the server. Note that with this option is possible to overwrite all current ajax setting in the save request including the complete event."
Steve
@Steve: the text of documentation is not very clear. But all works very easy. For example if you use `ajaxRowOptions: { contentType: "application/json", type: "PUT", url: "myUrl" }` you add a new option in the `$.ajax` call or replace an existing. So you can not skip the `$.ajax` call but you can **replace all** parameters inclusive callback functions like `complete` or `error`. It is what the function `$.extend` do.
Oleg
@Oleg, am I missing something? how does that help me stop the ajax request going out?
Steve
@Steve: You can for example set url to any other server to produce http://en.wikipedia.org/wiki/Cross-site_scripting (see http://en.wikipedia.org/wiki/Same_origin_policy).
Oleg
but if i want to stop the post from happening that doesn't really help me.
Steve