tags:

views:

1618

answers:

3

Hello all,

I've got a jqGrid running on my jsp page, and I love every features of this grid so far. Now I try to explore the event feature. I am trying to attach a function to onSelectRow event of the grid, but nothing works when i click on any row of the grid. Can you tell me why?

I am using jqGrid 3.6. Do I need to reference any other javascript library to make it works?

+2  A: 

You have an extra comma after shrinkToFit that needs to be removed. But before you fix that, why are you adding the onSelectRow handler later instead of as part of the grid definition? You can just add it during grid creation:

shrinkToFit:'false',
onSelectRow: function(id){
    alert('Selected row ID ' + id);
}
});
Justin Ethier
A: 

My grid shows up with data loading in, but when i click any row, nothing happens.

Below is my script:



           
    
      
         
     

jQuery(document).ready(function(){ 
            jQuery("#list").jqGrid({
            url:'admin.htm',
            datatype: 'xml',
            mtype: 'GET',
            colNames:['ID', 'data 1','data 2'],
            colModel :[ 
              {name:'ID', index:'ID', hidden:true}, 
              {name:'data 1', index:'data 1', width:90}, 
              {name:'data 2', index:'data 2', width:80, align:'right'}            
            ],
            rowNum:10,
            rowList:[10,20,30],
            sortname: 'ID',
            sortorder: 'desc',
            viewrecords: 'true',
            caption: 'Administration', width:"920",
            shrinkToFit:'false',
          });

            jQuery("#list").jqGrid({
                onSelectRow: function(id){
                    alert('Selected row ID ' + id);
                }
            });

dara
A: 

You are probably missing some jqGrid dependencies (it is modular and default configuration doesn't include many of its features). Try doing the same on a full package of jqGrid. Also, make sure to check the JS error console for signs of breakage.

mst