Getting id as undefined when jqgrid row is clicked
Asked Answered
Q

1

0

I need to get the id of the selected row, to highlight it. But I get id as undefined. What could be the reason for it?

I have attached a click event with UserDetails jqgrid. The following function is invoked when the UserDetails grid is clicked.

var selectUserGrid = function(event) {
   var grid = $('#UserDetails');
      grid.jqGrid( {
         onSelectRow : function(id) {
            var i = id;
         }
      });
   grid.setSelection(i,true);
}

How do I get the ID of the row clicked?

Quadratics answered 9/10, 2015 at 8:4 Comment(3)
I believe you had the same question earlier?Paramagnet
@Pekka This one is different.Quadratics
why don't you put grid.setSelection(i,true); code inside onSelectRow : handler?Totemism
H
2

I suppose that you have the problem with the order of processing of click event.

The first problem is in registering of additional click event handler. Why you do this? jqGrid already registered one click event handler. jqGrid process it and it calls beforeSelectRow callback, trigger jqGridBeforeSelectRow event then it selects the row, it calls onSelectRow callback, trigger jqGridSelectRow event, calls onCellSelect callback, trigger trigger jqGridCellSelect. In other words jqGrid process click event and allows to use callbacks and events to do some additional actions, which synchronized with internal work of jqGrid.

If you register the second click handler then you could not quarantine that your click handler will be called after the row of the grid is selected.

I recommend you to use callback or events described above. Moreover you use setSelection in the code fragment which you posted. On the other side it's not clear how you fill the grid. You can call setSelection only after the corresponding row will be inserted in jqGrd. I suppose that your real code is another. Nevertheless the code which you posted can't work. Moreover the code defines i variable inside of onSelectRow callback, but you try to use it in outside of the callback. In the case i will be undefined forever.

Homegrown answered 9/10, 2015 at 8:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.