Denzil Soans
Denzil Soans

Reputation: 667

Set focus to the first row in a gridview using knockoutjs or jquery

I have a dynamic grid in ASP.NET for which the data is being fetched Using Knockout.js, whenever a Search button is clicked. Once the grid is loaded the user can click on the any row to check the details related to that row in a popup.

What I want to implement here is, Once the Search button is clicked and the data in the grid is loaded the focus should be set to the first row and Enter Key should fire the click event (As when clicked by mouse which displays a pop up).

Thanks in advance!!

Note : Using Knockout js and jquery to fetch and bind data in asp.net

Upvotes: 1

Views: 2224

Answers (3)

aditya
aditya

Reputation: 26

 Try this:
$(document).ready(function(){   
 var column = $("#<%=GridView1.ClientID %>").find("tr:eq(1)");   
 column.focus();   
});                 
 If it fails 
 try
 ClientIDMode="Static"

Upvotes: 1

fuzzybear
fuzzybear

Reputation: 2405

You can use Knockouts hasFocus Binding

The hasFocus binding links a DOM element’s focus state with a viewmodel property. It is a two-way binding, so:

If you set the viewmodel property to true or false, the associated element will become focused or unfocused.

Link to Docs

Upvotes: 0

Charly
Charly

Reputation: 125

$("#search").click(function(){
     $("#first-row").focus();
})

//active your row   
if( $("#first-row").is(":focus")){
   $("#first-row").addClass("active") //maybe a style for this active row
}

$(document).keypress(function(e) {
     if(e.which == 13 && $("#first-row").hasClass("active")) {
         //redirect or show a div..
     }
});

Something like that ?

P.S : I don't know if it's possible to focus a div or tr ^^

Upvotes: 0

Related Questions