Matt Zukowski
Matt Zukowski

Reputation: 4541

In jqGrid do I have to manually call saveRow to trigger an ajax save request?

The documentation here is not very clear:

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing&s[]=editurl#saverow

Do I have to manually make a saveRow call after the user finishes editing a table cell/row, or will jqGrid automatically trigger saveRow when the row (cell?) loses focus?

I'm giving jqGrid a editurl value in the initial setup, but I don't see any ajax requests going out when I finish editing a row.

Upvotes: 2

Views: 11866

Answers (2)

OfirD
OfirD

Reputation: 10490

Although that's an old question, I'd like to add an example of explicitly calling editRow and then saveRow, which is a pretty frequent case.

The following code allows the user to just move freely between selected rows, and save the previous selected, edited row:

var grid = $('#gridName').jqGrid({
   // ... some grid properties ...
   editurl: 'clientArray',
   cellEdit: false, // that's the default, but just to make clear that wer'e in inline edit mode
   onSelectRow: utils.onSelectRow
   // ... some more grid properties ...
});
var utils = {
   prevRowId: null, // we have to keep the previous row id
   onSelectRow: function (rowId, selectionStatus, event) {
      if (rowId && rowId !== utils.prevRowId) {
         var $grid = $(event.target).closest('table');
         $grid.jqGrid('saveRow', utils.prevRowId);
         $grid.jqGrid('editRow', rowId, { keys: true });
         utils.prevRowId = rowId;
      }
   },
};

I couldn't find one of Oleg's official examples doing exactly this (they're all using buttons, as this one, or calling retrieveRow instead of saveRow, as this one).

Upvotes: 0

Oleg
Oleg

Reputation: 222007

You have two options:

  1. You use editRow with the parameter keys: true. In the case the method saveRow will be called if the user press Enter and the method restoreRow will be called if the user press Esc. In the case you don't need to call saveRow explicitly. Inside of onSelectRow one calls typically restoreRow see here an example.
  2. You can call saveRow instead of restoreRow in the onSelectRow callback. Additionally (or alternatively) you can gives the user an interface to save current editing row. It can be some kind of "Save" button.

Upvotes: 7

Related Questions