jqGrid - Select selected cell's text while inline editing

岁酱吖の 提交于 2020-01-11 06:44:31

问题


Part 1) In my grid, I have some editable columns which I would like to do inline editing to. However when I select any particular cell and if the inline editing is available on that cell (editable: true), it should select the text to be edited.

For example if this is the default grid: then upon selecting any cell in Quantity, the result should be something like this:

When we click on a cell to edit that row in jqGrid, current implementation does not highlight the selected text like this. Is there any way to achieve this?

Part 2) Migrated to this question as per Oleg's suggestion

GRID CODE: jsFiddle

Note: My real application datatype is JSON


回答1:


I'm not sure about all versions of old web browsers, but you can modify the code of onSelectRow to the following

onSelectRow: function (id) {
    var $self = $(this);
    if (id && id !== lastsel2) {
        $self.jqGrid('restoreRow', lastsel2);
        $self.jqGrid('editRow', id, {
            keys: true,
            focusField: 'Quantity',
            oneditfunc: function (rowid, options) {
                $control = $("#" + rowid + "_Quantity");
                if ($control.length > 0) {
                    $control[0].select();
                }
            },
            aftersavefunc: reload
        });
        lastsel2 = id;
    }
}

see http://jsfiddle.net/OlegKi/HJema/163/. It uses focusField: 'Quantity' option to set the focus on the 'Quantity' column. It uses select() method to select the text of <input> field.

The second part of your question (about bindKeys) seems to me a separate question. The method bindKeys allows to implement custom callbacks onLeftKey, onRightKey. Which one you would like better to use is not full clear for me.



来源:https://stackoverflow.com/questions/32701708/jqgrid-select-selected-cells-text-while-inline-editing

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