dara
dara

Reputation: 39

jqGrid event not activated or triggered on Row Select

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?

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

Below is my script:

<script src="javascript/jquery-1.3.2.js" type="text/javascript"></script>
<script src="javascript/ui.core.js" type="text/javascript" ></script>       
<script src="javascript/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="javascript/jquery.jqGrid.min.js" type="text/javascript"></script>    
<script src="javascript/ui.multiselect.js" type="text/javascript"></script>   
<script src="javascript/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script> 
<script type="text/javascript">
  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); }
  });
</script>

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

Upvotes: 2

Views: 19351

Answers (3)

fafnirbcrow
fafnirbcrow

Reputation: 270

I found this as an example of onSelectRow and found that I had problems unless I actually moved it up into the original declaration

Upvotes: -1

Justin Ethier
Justin Ethier

Reputation: 134167

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);
}
});

Upvotes: 7

mst
mst

Reputation: 247

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.

Upvotes: 0

Related Questions