【问题标题】:Unable to set focus to textbox in dojo datagrid无法将焦点设置到 dojo 数据网格中的文本框
【发布时间】:2010-12-05 21:44:53
【问题描述】:

我有一个 Dojo Datagrid,其中一列通过格式化程序函数呈现为文本框。当我单击呈现的文本框输入一些值时,光标出现在文本框中并且焦点立即丢失(即光标消失 - 键入不会产生任何内容)。我必须再次单击文本框才能设置焦点 - 只有这样我才能输入值。

有什么方法可以将焦点设置在第一次点击本身上?

代码如下:

<table dojoType="dojox.grid.DataGrid" store="selectedItemsStore" class="resultsGridClass" jsid="selecteditems">
<thead>
<tr>
<th field="field1" formatter="renderTextBox" width="20%">Field 1</th>
</tr>
</thead>
</table>

这里是格式化函数:

function renderTextBox(value, rowIndex) {
var htmlString = "<input type='text' name= 'exp' />";
return htmlString;
}

【问题讨论】:

  • 想知道这是否与 bugs.dojotoolkit.org/ticket/9827 相关——在该票证中有一个参考,以支持嵌入文本输入的方式
  • 这里有同样的问题。有人知道解决方案吗?

标签: datagrid dojo double-click


【解决方案1】:

在我的例子中,下面的代码非常适合文本框焦点问题:

dojo.connect(this.floorTable,"onRowClick",this,function(row){               
    row.target.focus();             
});

其中this.floorTable 是一个表对象。

【讨论】:

    【解决方案2】:

    在创建dojox.grid.EnhancedGrid 的实例时,使用singleClickEdit 属性并将其设置为true

    这将在第一次点击时将焦点设置在文本框或任何其他小部件上。

    【讨论】:

      【解决方案3】:
      window.setTimeout(function() {
          dijit.byId("profileGrid").scrollToRow(rowIndex);
          dijit.byId("profileGrid").focus.setFocusIndex( rowIndex, 0 );
          dijit.byId("profileGrid").edit.setEditCell( dijit.byId("profileGrid").getCell(0), rowIndex );
      },10);
      

      【讨论】:

        【解决方案4】:

        尝试将 editable 和 alwaysEditing 属性设置为 true:

        <th alwaysEditing="true" editable="true" field="field1" formatter="renderTextBox" width="20%" >Field 1</th>
        

        【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多