title: JQGrid load data on another grid with OnSelectRow
body: <p>I have been tearing my hair out over the last couple of days. Just as a quick outline of the problem. I am using JqGrid 4.2.0 (latest version at the time of writing). In a single page, I have two grids. One on the left, looking to act as the navigator. I want to load the data on the right-hand grid with data determined by the row ID of the item clicked on the left hand side.</p>
  
  <p>My problem is that the first selected row ID gets "stuck" and all ajax calls in future are the same identical rowid (for example: if first selected row was 514, every other selected row will output 514 on the ajax call to load the other grid, if first selected was 513, all others 513, etc)</p>
  
  <p>I suspect it might be some kind of variables crossing or somesuch as I placed alert calls for testing throughout the execution and they all alert the correct ID number until the point where the next grid is loaded, at which point the row ID becomes the erroneous one.</p>
  
  <p>Here is my code below:</p>
  
  <p>First segment is the initial list on the left with the OnSelectRow call, and the second section of code is for the data grid on the right hand side which actuall holds the data)</p>
  
  <pre><code>renderImportsList = function(url, data, firstrow) {
  var cnames = data.names;
  var cmodel = data.model;
  currentrow = firstrow;
  $("#imports_grid").jqGrid({
      url: url + "&amp;type=list",
      //caption: "Imports",
      datatype: "json",
      colNames: cnames,
      colModel: cmodel,
      recordtext: "&lt;b&gt;Imports: {1}&lt;/b&gt;",
      autowidth: true,
      rowNum: 10000,
      toolbar: [true,"top"],
      pager: "#imports_grid_pager",
      pgbuttons: false,
      pginput: false,
      viewrecords: true,
      multiselect: false,
      sortorder: "desc",
      sortable: true,
      onSelectRow: function(rowid) {
          if (rowid != firstrow) {
              if ($("#" + firstrow).hasClass("ui-state-highlight"))
                  $("#" + firstrow).removeClass("ui-state-highlight")
          }
          setTimeout(function() { 
              // Display import items
              var itype = "checkpoint";
                              alert(rowid); // This returns the right row ID so far
              renderImportItems(url, rowid, itype);
          }, 500);
      },
      loadComplete: function() {
          $("#imports_grid tr").css("border-color", "#666");
          $("tr.jqgroup").css("background", "#e9efff");
          $("tr.jqfoot").css("background", "#ced5e9");
          $("#imports_grid tr.jqfoot td").css("border-right", "none");
          $("#t_imports_grid").css("padding-bottom", "3px");
          $("#imports_grid").setSelection(firstrow, true);
          $("#imports_grid").trigger("reloadGrid"); // Call to fix client-side sorting
      }
  });     
  $("#imports_grid").jqGrid('navGrid','#imports_grid_pager',{edit:false,add:false,del:false,search:false});
  $("#imports_grid").trigger("reloadGrid"); // Call to fix client-side sorting
  sizeGrid("imports_grid");
  </code></pre>
  
  <p>}</p>
  
  <p>This part executes fine, the rowid at this stage is what I clicked on, according to the alert placed above. Below is the second function which is called from inside OnSelectRow in the function above.</p>
  
  <pre><code>renderImportItems = function(url, rowid, itype) {
  $.ajax({
      url: srvrname + "applications/PMS/views/view/imports/" + itype + ".php",
      success: function(data) {
          var cnames  = data.names;
          var cmodel  = data.model;
                      alert(rowid); // Here, the code still executes the right row ID
          $("#checkpoint_grid").jqGrid({
              url: url + "&amp;rid=" + rowid + "&amp;type=" + itype,
              // This is where it breaks. No matter what, I keep getting rowid to equal whichever row was selected the very first time the grid was clicked (or loaded programatically onload)
              datatype: "json",
              colNames: cnames,
              colModel: cmodel,
              recordtext: "&lt;b&gt;Total: {1}&lt;/b&gt;",
              autowidth: true,
              rowNum: 500,
              pager: "#" + itype + "_grid_pager",
              pgbuttons: false,
              pginput: false,
              viewrecords: true,
              multiselect: false,
              sortorder: "desc",
              sortable: true,
              loadComplete: function() {
                  $("#" + itype + "_grid tr").css("border-color", "#666");
                  $("tr.jqgroup").css("background", "#e9efff");
                  $("tr.jqfoot").css("background", "#ced5e9");
                  $("#" + itype + "_grid tr.jqfoot td").css("border-right", "none");
                  $("#" + itype + "_grid").trigger("reloadGrid"); // Call to fix client-side sorting
              }
          }); 
          $("#" + itype + "_grid").jqGrid('navGrid','#' + itype + 'grid_pager',{edit:false,add:false,del:false,search:false});
          $("#" + itype + "_grid").trigger("reloadGrid"); // Call to fix client-side sorting
          sizeGrid(itype + "_grid");
      }
  });
  </code></pre>
  
  <p>}</p>
  
  <p>As you can see above: at the point at which the first alert is called; it is still outputting the correct ID number, but as soon as the second grid is initialized; the ID returns to whatever it was inintially set on the very first call.</p>
  
  <p>Any help provided would be greatly appreciated. If it helps, here are some firebug outputs to demonstrate the issue...</p>
  
  <p>(Domain name removed for privacy)</p>
  
  <p>(First load: programmatic: firstrow selected = 514)
  Response: //mydomain.com/views/view/grid.php?rid=514&amp;type=checkpoint&amp;_search=false&amp;nd=1321336809180&amp;rows=500&amp;page=1&amp;sidx=&amp;sord=desc</p>
  
  <p>(Clicked row: selected row = 503)
  Response: //mydomain.com/views/view/grid.php?rid=514&amp;type=checkpoint&amp;_search=false&amp;nd=1321336863994&amp;rows=500&amp;page=1&amp;sidx=&amp;sord=desc</p>
  
  <p>(Clicked row: selected row = 510)
  Response: //mydomain.com/views/view/grid.php?rid=514&amp;type=checkpoint&amp;_search=false&amp;nd=1321336864848&amp;rows=500&amp;page=1&amp;sidx=&amp;sord=desc</p>