tags:

views:

37

answers:

1

Hi,

I have a jqGrid in inline editing mode. When the user hits Enter, the record is sent to the server to save. The server returns a success:true or false which I handle in successFunc as follows:

function successFunc(data) {
  d = jQuery.parseJSON(data.responseText);
  if (!d.success) { alert(d.message); }
  return d.success;
}

What I would like is that when d.success is false, the jqGrid should remain in edit mode and not restore. I tried adding a throw "exit" call after the alert. It works, but the Esc and Enter keys do not work any longer.

Is there any way to prevent jqGrid from restoring the row after save?

Thanks

A: 

The call to saveRow supports an afterrestorefunc callback:

afterrestorefunc if defined, this function is called in restoreRow (in case the row is not saved with success) method after restoring the row. To this function we pass the rowid

So you could let the grid call restoreRow and then in your callback you can call editRow to force the grid back in to edit mode. Not an ideal solution, but the transition will happen so fast the user probably will not notice.

Justin Ethier
Thanks. But afterrestorefunc will also be called when user hits Esc. So with Esc it won't go out of edit mode.
4manan
Yes, but you could use a `mode` variable to detect where it is called from. Initialize `mode` to false and only set it to true in `successFunc`. Then inside `afterrestorefunc`, only call `editRow` if `mode` is true - then immediately set it back to false. What do you think?
Justin Ethier
Issue now is that changes are lost as soon as I put it back in edit mode. I need to rethink my interface. Thanks for the help.
4manan