When editing a row on jqgrid, the cursor automatically enters the left-most editable field. Is there a way to have it default to a particular column, or better yet, to whatever column I click on?
-
there are some additional options which one can/want to use additionally. I posted previously some answers with a little different implementations of the behavior. So it's important to know which version and which fork of jqGrid you use. Look at [the answer](http://stackoverflow.com/a/32704985/315935) for example which uses the last version of free jqGrid. The oldest answer about the subject is probably [this one](http://stackoverflow.com/a/6538102/315935). – Oleg Oct 14 '15 at 21:18
-
Ah, unfortunately we're using 4.8, not 5.0, which it looks like is when `focusField` was added :/ – ZAD-Man Oct 14 '15 at 21:40
-
5.0 is the version number of [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334). Free jqGrid is my alternatively fork of jqGrid. It exist in versions 4.8.0, 4.9.0, 4.9.1, 4.9.2 (see [here](https://github.com/free-jqgrid/jqGrid/releases)). **Which fork you use: free jqGrid or Guriddo jqGrid JS**? `focusField` option exist starting with jqGrid 4.7 (see [the line](https://github.com/free-jqgrid/jqGrid/blob/v4.7.0/js/grid.inlinedit.js#L46)). The approach from the oldest answer can be implemented without `focusField` at all. – Oleg Oct 14 '15 at 22:26
-
Do you read my answer? – Oleg Oct 22 '15 at 09:23
-
Yes, but I had another project that came up that has priority over this one, sorry. Not sure when I'll be back to it. – ZAD-Man Oct 22 '15 at 16:01
1 Answers
The implementation depend on the version of jqGrid and from the fork of jqGrid which you use.
If you use the latest version of free jqGrid then the code
onSelectRow: function (rowid, status, e) {
var $self = $(this), savedRow = $self.jqGrid("getGridParam", "savedRow");
if (savedRow.length > 0 && savedRow[0].id !== rowid) {
$self.jqGrid("restoreRow", savedRow[0].id);
}
$self.jqGrid("editRow", rowid, { focusField: e.target });
},
inlineEditing: { keys: true, defaultFocusField: "amount", focusField: "amount" }
see the demo. The above code uses e.target
as the value of focusField
property of jqGrid method editRow
. As the result the focus will be set on the clicked cell. If the user clicks on non-editable cell, like on "rownumber" column for example, then the option defaultFocusField
will be used and the focus will be set on the column "amount"
. I remind that free jqGrid uses inlineEditing
option to specify default parameters of inline editing (see the wiki article for more details).
The option focusField
of editRow
is supported starting with version 4.7, but old version support only boolean and number values.

- 220,925
- 34
- 403
- 798