简体   繁体   English

jqGrid-内联编辑时选择选定单元格的文本

[英]jqGrid - Select selected cell's text while inline editing

Part 1) In my grid, I have some editable columns which I would like to do inline editing to. 第1部分)在网格中,我有一些可编辑的列,我想对其进行内联编辑。 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. 但是,当我选择任何特定的单元格并且如果该单元格上有内联编辑功能时( editable: true ),它应该选择要编辑的文本。

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. 当我们单击一个单元格以在jqGrid中编辑该行时,当前实现不会像这样突出显示所选的文本。 Is there any way to achieve this? 有什么办法可以做到这一点?

Part 2) Migrated to this question as per Oleg's suggestion 第2部分)根据Oleg的建议移至此问题

GRID CODE: jsFiddle 网格代码: jsFiddle

Note: My real application datatype is JSON 注意:我真正的应用程序数据类型是JSON

I'm not sure about all versions of old web browsers, but you can modify the code of onSelectRow to the following 我不确定所有版本的旧网络浏览器,但是您可以将onSelectRow的代码修改为以下内容

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/ . 参见http://jsfiddle.net/OlegKi/HJema/163/ It uses focusField: 'Quantity' option to set the focus on the 'Quantity' column. 它使用focusField: 'Quantity'选项将焦点设置在'Quantity'列上。 It uses select() method to select the text of <input> field. 它使用select()方法选择<input>字段的文本。

The second part of your question (about bindKeys ) seems to me a separate question. 在我看来,您问题的第二部分(关于bindKeys )是一个单独的问题。 The method bindKeys allows to implement custom callbacks onLeftKey , onRightKey . bindKeys方法允许实现自定义回调onLeftKeyonRightKey Which one you would like better to use is not full clear for me. 对于我来说,您还想使用哪一种更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM