Dipen Shah
Dipen Shah

Reputation: 1919

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. 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: enter image description here then upon selecting any cell in Quantity, the result should be something like this: enter image description here

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

Upvotes: 2

Views: 3375

Answers (1)

Oleg
Oleg

Reputation: 221997

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.

Upvotes: 3

Related Questions