2

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.

Matt Zukowski
  • 4,469
  • 4
  • 37
  • 38

2 Answers2

7

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.
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi @Oleg , From the answer above I need the second option, along with the save button and cancel button and the end of each row. Can you please point to me an existing project with asp.net web forms. I tried to go through what is existing but am unable to understand it correctly. It would be much help and appreciated if I could get a small sample with guidelines for the following scenario:- **1. Inline edit on onclick, 2. Save or or cancel button at the end of every row which have accessible events. So that I can make a ajaxcall on lick of save.** –  Nov 17 '15 at 10:30
  • @Ganesh: Sorry, but you ask too common questions. I have no Web Forms projects. Probably [the old answer](http://stackoverflow.com/a/10871428/315935) is what one can use. Web Forms is very old and practically dead, so it's difficult to speak about *existing* ASP.NET WebForms projects. To add editing buttons in every row one can use `formatter: "actions"` for example. In case of usage [free jqGrid](https://github.com/free-jqgrid/jqGrid) you can just add the last column with some `name` property and `template: "actions"`. To save modifications to the server you need still wrote some server code. – Oleg Nov 17 '15 at 10:52
0

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).

OfirD
  • 9,442
  • 5
  • 47
  • 90