title: "Uncaught TypeError: Cannot call method 'indexOf' of undefined" when selected jqgrid row
body: <p>I have used jqgrid for a while.  I am getting an error when I select a row:</p>
  
  <pre><code>&gt; Uncaught TypeError: Cannot call method 'indexOf' of undefined
  &gt; jquery.jqGrid.src.js:2465 $.jgrid.extend.setSelection
  &gt; jquery.jqGrid.src.js:2465 jQuery.extend.each jquery-1.7.1.js:658
  &gt; jQuery.fn.jQuery.each jquery-1.7.1.js:271 $.jgrid.extend.setSelection
  &gt; jquery.jqGrid.src.js:2460 $.fn.jqGrid jquery.jqGrid.src.js:587
  &gt; $.fn.jqGrid.each.$.before.click.bind.ts.p.datatype
  &gt; jquery.jqGrid.src.js:2235 jQuery.event.dispatch jquery-1.7.1.js:3256
  &gt; jQuery.event.add.elemData.handle.eventHandle
  </code></pre>
  
  <p>my grid definition is here:</p>
  
  <pre><code>var sql4 = 'select id_num, est_number, customer, product, rev, w, l, fw, fl, expr1009, status, comments from schema.table where customer = "' + customer + '" and est_number = "' + est_num + '"';
  $("#the_table").jqGrid({
      url:'thescript.php?sql=' + sql4,
      height: 300,
      shrinkToFit: true,
      width: 650,
      datatype: 'xml',
      mtype: 'POST',
      colNames:["ID","Estimate","Customer","Product","Rev","W","L","FW","FL","Expr1009","Status","Comments"],
      colModel:[
          {name:"id_num",index:"id_num",width:"10"},
          {name:"est_number",index:"est_number",width:"10"},
          {name:"customer",index:"customer",width:"10"},
          {name:"product",index:"product",width:"10"},
          {name:"rev",index:"rev",width:"10"},
          {name:"w",index:"w",width:"10"},
          {name:"l",index:"l",width:"10"},
          {name:"fw",index:"fw",width:"10"},
          {name:"fl",index:"fl",width:"10"},
          {name:"expr1009",index:"expr1009",width:"10"},
          {name:"status",index:"status",width:"10"},
          {name:"comments",index:"comments",width:"10"}
      ],
      rowNum:10000,
      sortname: 'id_num',
      sortorder: 'asc',
      viewrecords: true,
      gridview: true,
      caption: '',
      ondblClickRow: function(id){
          //do some stuff here
      }
  })
  .jqGrid('filterToolbar')
  .trigger('reloadGrid');
  </code></pre>
  
  <p>}</p>
  
  <p>I cannot figure out what the problem is, as it seems the grid works fine otherwise.</p>
  
  <p>I have noticed that in the following jqgrid function, the id = 1 for ever row (this info is contained in the variable <strong><em>pt</em></strong>.</p>
  
  <pre><code>setSelection : function(selection,onsr) {
      return this.each(function(){
          var $t = this, stat,pt, ner, ia, tpsr;
          if(selection === undefined) { return; }
          onsr = onsr === false ? false : true;
          pt=$t.rows.namedItem(selection+"");
  </code></pre>
  
  <p>The next line is where the error occurs.  The variable <strong><em>pt</em></strong> has 4 nodes that all have id: 1.</p>
  
  <pre><code>if(!pt || pt.className.indexOf( 'ui-state-disabled' ) &gt; -1 ) { return; }
  </code></pre>
  
  <p>** Amswer **</p>
  
  <p>I added the <code>key:true</code> option the the <code>id_num</code> field in the <code>ColModel</code>.  Each row of the grid had the SAME ID, so it was causing a problem.  I think is error happens most often when you do not have unique IDs. in your grid.</p>