Search This Blog

Monday 8 February 2016

Set Focus on any table row in javascript

                     Set Focus on any table row in javascript


To set focus on any specific row we will require row id ,HTML : 


<div id="one"><table border='1' id='tableDiv1'><tr><td>row1</td><td>Test1</td></tr><tr><td>row1</td><td>Test1Test1</td></tr><tr><td>row1row1</td><td>Test1Test1</td></tr><tr><td>Selected Row</td>Selected Td<td></td></tr><tr><td>row1</td><td>Test1Test1trgTest1</td></tr><tr><td>row1row1</td><td>Test1Test1Test1Test1</td></tr><tr><td>row1row1</td><td>Test1Tertgrgrst1Test1Test1</td></tr><tr><td>fdetgregtt</td><td>Test1Test1Test1Test1</td></tr><tr><td>rtgrgr</td><td></td>Test1tyhegergr</tr><tr><td>grgrgr</td><td></td>TestTAble</tr><tr><td>gregerg</td><td>Test1Test1Test1Test1</td></tr>
</table></div>

If  you want to select 4th row then put index number 4 in table row row[] array
$(document).ready(function(){
var row = document.getElementById("tableDiv1").rows;
row[4].scrollIntoView(false);
});

Or from any other method  

function selectRow(){
       var row = document.getElementById("tableDiv1").rows;
            row[4].scrollIntoView(false);
}

No comments:

Post a Comment