I use the following script function for get the row id from the grid. It was working properly. I get the ID within the click function. But if I try to get the outside of the function it will display Empty. I need the click function value for selr outside? How to do this?
var selr='';
$(document).ready(function(){
$("#datagrid").click(function(e) {
row = jQuery(e.target).closest('tr');
getId= row.attr("id");//for getting row number
selr = $("#datagrid").getCell(getId,'companyid');//getting Row ID
alert('alert in'+selr);
});
alert('alert out'+selr);
});
The thing is, the value of
selrgets declared only when you initiate theclickfunction. So check after clicking thejqGrid.The script inside the
$(document).ready();will not work, and will show as empty because, after the document is ready, theselrwouldn’t have set.Instead of having a simple variable, assign
selras a global variable. Just replaceselrwithwindow.selr.