开发者

Unable to set focus to textbox in dojo datagrid

开发者 https://www.devze.com 2022-12-08 11:34 出处:网络
I have a Dojo Datagrid with one of the columns being rendered as a textbox by a formatter function. When I click on the rendered textbox to enter some value, the cursor appears in the textbox and focu

I have a Dojo Datagrid with one of the columns being rendered as a textbox by a formatter function. When I click on the rendered textbox to enter some value, the cursor appears in the textbox and focus is immediately lost (i.e, the cursor disappears - typin开发者_如何转开发g does not produce anything). I have to click once more on the textbox for the focus to set - only then can I enter values.

Is there any way to set the focus on the first click itself?

Here is the code:

<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>

And here is the formatter function:

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


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


Try setting editable and alwaysEditing attributes to true:

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


While creating an instance of dojox.grid.EnhancedGrid, use the singleClickEdit attribute and set it as true.

This will set the focus on the textbox or any other widget on the first click.


In my case below code works perfectly for the text box focus issue:

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

where this.floorTable is a table object.

0

精彩评论

暂无评论...
验证码 换一张
取 消