javascript - KendoUI Grid - Select text on cell focus - Stack Overflow

The cell content selection works successfully for a numeric text box (internally handled as a Kendo Num

The cell content selection works successfully for a numeric text box (internally handled as a Kendo NumericTextBox control) but for some reason, it doesn't work with a plain textbox column. Attached is the jsfiddle demo'ing the issue:

This is the code in the grid setup that's of importance:

edit: function (e) {
        var input = e.container.find("input");
        input.focus(function (e) {
            console.log('focus');
            setTimeout(function () {
                input.select();
            });
        });
    }

The cell content selection works successfully for a numeric text box (internally handled as a Kendo NumericTextBox control) but for some reason, it doesn't work with a plain textbox column. Attached is the jsfiddle demo'ing the issue:

http://jsfiddle/latenightcoder/TrJVK/86

This is the code in the grid setup that's of importance:

edit: function (e) {
        var input = e.container.find("input");
        input.focus(function (e) {
            console.log('focus');
            setTimeout(function () {
                input.select();
            });
        });
    }
Share Improve this question asked Jul 29, 2013 at 21:14 Joel D'SouzaJoel D'Souza 9766 silver badges15 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

It turns out that the focus event was getting fired before I could even wire up the focus event handler. So this was the optimal solution to support all types of fields within the grid row:

        var input = e.container.find("input");
        setTimeout(function () {
            input.select();
        }, 25);

The modified jsfiddle can be viewed here: http://jsfiddle/latenightcoder/TrJVK/90

You're only attaching the focus event handler to it, but you're not actually telling it to focus. The question should be, why does the kendo number box do it? :-) Also, setTimeout's 2nd argument isn't optional (according to spec).

Try the following (http://jsfiddle/TrJVK/87/)

    edit: function (e) {
        var input = e.container.find("input");
        input.focus(function (e) {
            // var input = $(this);
            console.log('focus');
            input.select();
        });
        input.focus();
    },

One more note:

For future jQuery patibility, it might be best to do the following even:

    edit: function (e) {
        var input = e.container.find("input");
        input.on('focus', function (e) {
            // var input = $(this);
            console.log('focus');
            input.select();
        });
        input.trigger('focus');
    },

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744752085a4591659.html

相关推荐

  • javascript - KendoUI Grid - Select text on cell focus - Stack Overflow

    The cell content selection works successfully for a numeric text box (internally handled as a Kendo Num

    20小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信