问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/33134809/can-i-have-the-cursor-start-on-a-particular-column-by-default-in-jqgrids-edit-m