【问题标题】:Needing to highlight the contents of a jqxNumberInput on click需要在点击时突出显示 jqxNumberInput 的内容
【发布时间】:2015-03-03 19:44:02
【问题描述】:

我一直在努力使用 jqxGrid 和一个使用 jqxNumberInput 渲染的单元格来获得一个非常简单的功能

  editor.jqxNumberInput({ decimalDigits: 2, spinButtonsStep: 0.1, spinMode: "simple", decimalSeparator: decimalSeparator, groupSeparator: groupSeparator });

基本上,当用户单击单元格时,光标一直放在文本(数字)的右侧,我的老板希望突出显示单元格的内容(选择文本),这样用户就不必向左移动光标以开始输入

我已经研究 jqx 网格文档很长一段时间了,但我似乎找不到任何东西来实现这一点。 http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxgrid/jquery-grid-api.htm

我试图绑定到 cellbeginedit 事件并假设我可以使用该事件来获取目标元素并以这种方式选择它,但 event.target 值是整个网格,而不是单元格本身。

 $(element).on('cellbeginedit', function (event) { // event.target == grid  not cell });

我也尝试使用 getcell 方法获取单元格,但这会返回该单元格的数据而不是元素本身。

 var cell = $(element).jqxGrid("getcell", args.rowindex, args.datafield);
 //  cell then equals the data for the row not with no reference to the 

有问题的元素 重申一下,我需要修改,hack update 做一些事情,所以当用户点击 jqxNumberInput 并且单元格进入编辑模式时,单元格中的所有文本都被选中(突出显示)

对于这个问题的任何帮助将不胜感激

【问题讨论】:

    标签: javascript jquery jqxgrid


    【解决方案1】:

    您应该将编辑器自定义逻辑放在列的 initeditor 回调函数中。在那里您可以尝试使用 jqxNumberInput API,例如“焦点”或用于选择输入中所有文本的代码。

    var input = editor.find('input');
    var length = input.val().length;
                try {
                    if ('selectionStart' in input) {
                        input.focus();
                        input.setSelectionRange(0, length);
                    }
                    else {
                        var range = input.createTextRange();
                        range.collapse(true);
                        range.moveEnd('character', length);
                        range.moveStart('character', 0);
                        range.select();
                    }
                }
                catch (error) {
                }
    

    在上面的代码中,editor 是从 jqxGrid 传递给列的 initeditor 函数的参数。

    【讨论】:

    • 我最终使用了 '' if (!!input[0]) { input[0].focus(); input[0].select();'',但你是正确的,谢谢一大堆人
    猜你喜欢
    • 2015-02-17
    • 2017-07-06
    • 2012-09-09
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-28
    • 2010-10-23
    • 1970-01-01
    相关资源
    最近更新 更多