Shivasubramanian A
Shivasubramanian A

Reputation: 4456

Unable to set focus to textbox in dojo datagrid

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 - typing 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;
}

Upvotes: 1

Views: 4133

Answers (4)

Sonti Nagarjuna
Sonti Nagarjuna

Reputation: 61

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.

Upvotes: 0

Ravi82
Ravi82

Reputation: 1

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.

Upvotes: 0

Indira
Indira

Reputation: 11

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

Upvotes: 1

ivalkeen
ivalkeen

Reputation: 1411

Try setting editable and alwaysEditing attributes to true:

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

Upvotes: 0

Related Questions