jqGrid not saving inline row edits
Asked Answered
P

2

6

I'm working with jqGrid 4.3.2 in an ASP.NET MVC 4 website, jQuery 1.7.2. There are several places in the application where jqGrid is used. My general setup right now is that all editing is done locally (loadonce: true and clientArray) with inline navigation and editing, and all grid data is posted to the server on form submit via AJAX calls. I've run into some difficulty with row edits and at what events they are committed. You can view the site (and source, total work in progress, be nice) here. If you add or edit a row and then click somewhere else on the page, the row edit is not saved. The user has to hit the enter key somewhere during the row edit in order to save the row.

I touched on this a little bit in this question, which Oleg was kind enough to answer. Is there a way to commit a row edit other than when the enter key is pressed, like when the row loses focus maybe?

Programmer answered 13/6, 2012 at 19:28 Comment(0)
B
8

What you can do is the following:

  1. First of all you have to set restoreAfterSelect: false option of inlineNav. I see that the option is not documented, but you can see it in the source code. Without the setting inlineNav uses beforeSelectRow to call restoreRow (see here).
  2. Implement saving of the previous editing row inside of onSelectRow (see the code from the answer) or inside of beforeSelectRow. Probably the usage of beforeSelectRow will be even easier because the last editing row, which need be saved, could be only the last selected row which you can get from selrow option because the value is not yet changed inside of beforeSelectRow.
Banded answered 13/6, 2012 at 20:7 Comment(2)
Perfect! Thanks, Oleg. That's been bugging me for a while.Programmer
Oleg though its been more than 2 years, your answer still helped me. putting "restoreAfterSelect: false" was the key. thanksRaybourne
S
1

For anyone reading this in 2016, this functionality has now been incorporated into jqGrid. See https://github.com/tonytomov/jqGrid/issues/785. At the time of writing jqGrid 5.1 was out, so I expect this functionality to be available from version 5.2 onwards. Alternatively just obtain the most recent code from GitHub.

To use it simply set the following properties on your jqGrid:

...
restoreAfterSelect: false,
saveAfterSelect: true,
...

There is no longer a need to implement your own solution.

Skeie answered 17/5, 2016 at 3:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.