Can I have the cursor start on a particular column by default in jqgrid's edit mode?

空扰寡人 提交于 2020-01-04 05:25:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!