This is a migrated thread and some comments may be shown as answers.

Tabbing into a datagrid cell

3 Answers 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dhuss
Top achievements
Rank 1
dhuss asked on 28 Mar 2012, 10:00 PM
I have a web page that has a series of dropdown controls (12 total). As the user enters/selects a value, they can tab to the next dropdown. When they tab out a dropdown that doesn't have a value (any of the 12), I want the focus to go to a data grid - first row - third cell. The following code, when looking via quick watch, confirms I have the correct row and cell based on the rendered ID when viewing the source. What ends up happing is the focus goes to the second row - first cell. What am I doing wrong?

var masterTable = $find("<%= dgServices.ClientID %>").get_masterTableView();
if (masterTable != '') {
    masterTable.get_dataItems()[0].get_element().cells[2].focus();

The attached jpg shows the flow I want to accomplish.

3 Answers, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 02 Apr 2012, 09:36 AM
Hi Dennis,

You could achieve your scenario by wrapping your code in a setTimeout as it is shown in the example below.
var masterTable = $find("<%= dgServices.ClientID %>").get_masterTableView();
if (masterTable != '')
{
    setTimeout(function()
    {
        masterTable.get_dataItems()[0].get_element().cells[2].focus();
    }, 5);
}

Greetings,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
dhuss
Top achievements
Rank 1
answered on 02 Apr 2012, 03:15 PM
If I hard code the "mangled" name (example: ParentControl_ctl00_ct04_lblID) then tabbing into the grid works fine. I don't want to rely on the generated name because I have found they can change. Why does this work and referring to the actual column/cell not work?
0
Antonio Stoilkov
Telerik team
answered on 05 Apr 2012, 11:21 AM
Hello Dennis,

I have assembled a sample project demonstrating the desired functionality. Note that in order to focus the text box you should focus the html input element in the cell not directly the cell.
function focusGrid()
{
        var masterTable = $find("<%= dgServices.ClientID %>").get_masterTableView();
                 
    if (masterTable != '')
    {
        setTimeout(function()
        {
            //$get("dgServices_ctl00_ctl04_TextBox1").focus();
            masterTable.get_dataItems()[0].get_element().cells[2].getElementsByTagName("input")[0].focus();
        }, 10);
    }
}


Regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
dhuss
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
dhuss
Top achievements
Rank 1
Share this question
or