2009-10-12 158 views
1

我有一個Dojo Datagrid,其中一列通過格式化函數呈現爲文本框。當我點擊渲染文本框輸入某個值時,光標會出現在文本框中,焦點會立即丟失(即光標消失 - 輸入不會產生任何內容)。我必須再次點擊文本框才能設置焦點 - 只有這樣才能輸入值。無法將焦點設置爲dojo數據網格中的文本框

有什麼辦法可以將重點放在第一次點擊本身上嗎?

下面是代碼:

<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; 
} 
+0

不知道這是否與http://bugs.dojotoolkit.org/ticket/9827有關 - 在該工單中有一個支持嵌入文本輸入方式的參考 – peller 2009-10-12 16:13:01

+0

這裏也有同樣的問題。有人知道解決方案嗎? – 2013-11-19 12:44:35

回答

0

嘗試設置可編輯和alwaysEditing屬性爲true:

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

沒有。不起作用。 – 2009-10-19 09:54:35

+0

您可以嘗試從此測試頁面重複行爲(按下切換dSingleClickEdit時):http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_edit.html – ivalkeen 2009-10-21 20:25:29

0

在創建一個實例dojox.grid.EnhancedGrid,使用singleClickEdit屬性並將其設置爲true

這會在第一次點擊時將焦點置於文本框或任何其他小部件上。

1
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); 
0

在我的情況下面的代碼完全適用於文本框的焦點問題:

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

其中this.floorTable是一個表對象。