title: Unable to retireve the ids of the Selected rows in Jqgrid
body: <p>I am unable to retireve the ids of the Selected rows in Jgrid....</p>
  
  <p>I have a jgrid</p>
  
  <pre><code>jQuery("#grid").jqGrid({
      ....................
  });
  </code></pre>
  
  <p>I have a button in the same jsp page</p>
  
  <pre><code>&lt;input type ="button" name="button" id="button" value="OK"&gt;
  </code></pre>
  
  <p>Once I click on the button, I should be able to retrieve all the selected rows from the above grid. 
  Here is my function,</p>
  
  <pre><code>jQuery("#button").click(function ()
  var select = jQuery("#grid").jqGrid("getGridParam", "selarrrow");
  for (var i = 0; i &lt; select.length; i++) //iterate through array of selected rows
  {
      alert("inside the loop");
  
      var id = jQuery("#grid").jqGrid('getRowData', select[i]);
  
      var selectedID = id.Emp_ID;
  });
  </code></pre>
  
  <p>I am not able to retieve the ids.
  Please help     </p>
  
  <p>Please find the full code here</p>
  
  <pre><code>         function load()
          {
  
              jQuery("#grid").jqGrid({
                  url:'Emp?action=getData',
                  datatype: "xml",
                  height: 250,
                  width:900,
  
                  colNames:
                      ['srNo','Emp_ID','NAME','ADDRESS'],   
  
                  colModel:[
                           {name:'srNo',index:'srNo', width:35,sortable:true},
  
                           {name:'Emp_ID',index:'Emp_ID', width:20,sortable:true,editable:true},
                           {name:'NAME',index:'NAME', width:35,sortable:false,editable:true},
                           {name:'ADDRESS',index:'ADDRESS', width:100,sortable:false,editable:true},
  
                            ],
  
                  paging: true,
                  rowNum:10,
                  rowList:[10,20,30],
                  pager: $("#page"),
                  sortname: 'srNo',
                  loadonce:true,
                  multiselect:true,
               gridComplete: function() {
                  var actualrows = $("#grid").getGridParam("reccount");
                  document.getElementById("rows").value = actualrows;
              }
  
              }).navGrid
             ('#page',{edit:true,add:true,del:true,view:true,search: true},
      {closeOnEscape:true, recreateForm: true,width:500,editurl: '', closeOnSubmit: true},
      {closeOnEscape:true, recreateForm: true,width:500,url: '', closeOnSubmit: true},
      {closeOnEscape:true, recreateForm: true,width:500,url: '',                      closeOnSubmit: true},
                  {multipleSearch:true,overlay:false}
  
        );
  
          }
  
      jQuery("#button").click(function ()
      {
  var select = jQuery("#grid").jqGrid("getGridParam", "selarrrow");
  for (var i = 0; i &lt; select.length; i++) //iterate through array of selected rows
  {
   alert("inside the loop");
  
   var id = jQuery("#grid").jqGrid('getRowData', select[i]);
  
   var selectedID = id.Emp_ID;
       }
  });
  
   &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="load();"&gt;
  
    &lt;table id="grid" border="1"&gt;&lt;/table&gt;
          &lt;div id="page"&gt;&lt;/div&gt;
  
           &lt;input type ="hidden" name = "hidden" id ="hidden"&gt;
  
          &lt;input type="hidden" id = "rows" name="actualrows" /&gt;
  
              &lt;table align ="center"&gt;
              &lt;tr&gt;
          &lt;td&gt;Date&lt;/td&gt;
          &lt;td&gt;&lt;input type ="text" name="regdate" id ="regdate"&gt;&lt;/td&gt;&lt;/tr&gt;
          &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input type ="button" class ="button" name="button" id="button" value="OK"&gt;&lt;/td&gt;&lt;/tr&gt;
  
          &lt;/table&gt;
     &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p>Following is the test data that i have included in my grid</p>
  
  <h2>srNo    Emp_ID    NAME    ADDRESS</h2>
  
  <p>1        Emp1     Andrew    addr</p>
  
  <p>2        Emp2     Cyrus     addr</p>
  
  <p>3        Emp3     Tom       addr</p>
  
  <p>This is the Servlet which fills the grid</p>
  
  <pre><code>    if (request.getParameter("action").equals("getData")) 
     {
     try
       {
         String query="Select * from Employee";
  
        /* Connection code goes here*/
  
       pstmt = con.prepareStatement(query);
  
  
      /* pagination code goes here*/
  
      out.print("&lt;?xml version='1.0' encoding='utf-8'?&gt;\n");
      out.print("&lt;rows&gt;");
      out.print("&lt;page&gt;" + page + "&lt;/page&gt;");
      out.print("&lt;total&gt;" + totalPages + "&lt;/total&gt;");
      out.print("&lt;records&gt;" + count + "&lt;/records&gt;");
  
  
     while(rs.next())
     {
      out.print("&lt;row id='" + srNo + "'&gt;");
      out.print("&lt;cell&gt;" + srNo + "&lt;/cell&gt;");
      out.print("&lt;cell&gt;" +rs.getString(1) + "&lt;/cell&gt;");
      out.print("&lt;cell&gt;"+rs.getString(2) +"&lt;/cell&gt;");
      out.print("&lt;cell&gt;"+rs.getString(3) +"&lt;/cell&gt;");
      out.print("&lt;/row&gt;");
      srNo++;
  
  }     
                      out.print("&lt;/rows&gt;");
    }
   catch(Exception e)
             {
  
             }
    }
  </code></pre>
  
  <p>Please find the XML response...below..</p>
  
  <pre><code> &lt;body onload="fillGrid();"&gt;
  
   &lt;div class="ui-jqgrid ui-widget ui-widget-content ui-corner-all" id="gbox_grid" style="width: 900px;"&gt;&lt;div class="ui-widget-overlay jqgrid-overlay" id="lui_grid"&gt;&lt;/div&gt;&lt;div class="loading ui-state-default ui-state-active" id="load_grid" style="display: none;"&gt;Loading...&lt;/div&gt;&lt;div class="ui-jqgrid-view" id="gview_grid" style="width: 900px;"&gt;&lt;div class="ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix" style="display: none;"&gt;&lt;a role="link" href="javascript:void(0)" class="ui-jqgrid-titlebar-close HeaderButton"&gt;&lt;span class="ui-icon ui-icon-circle-triangle-n"&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class="ui-jqgrid-title"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="width: 900px;" class="ui-state-default ui-jqgrid-hdiv"&gt;&lt;div class="ui-jqgrid-hbox"&gt;&lt;table class="ui-jqgrid-htable" style="width:882px" role="grid" aria-labelledby="gbox_grid" cellspacing="0" cellpadding="0" border="0"&gt;&lt;thead&gt;&lt;tr class="ui-jqgrid-labels" role="rowheader"&gt;&lt;th role="columnheader" class="ui-state-default ui-th-column" style="width: 25px;"&gt;&lt;div id="jqgh_cb"&gt;&lt;input id="cb_jqg" class="cbox" type="checkbox"&gt;&lt;span class="s-ico" style="display:none"&gt;&lt;span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n"&gt;&lt;/span&gt;&lt;span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/th&gt;&lt;th role="columnheader" class="ui-state-default ui-th-column" style="width: 157px;"&gt;&lt;span class="ui-jqgrid-resize"&gt;&amp;nbsp;&lt;/span&gt;&lt;div id="jqgh_srNo" class="ui-jqgrid-sortable"&gt;srNo&lt;span class="s-ico" style=""&gt;&lt;span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-icon ui-icon-triangle-1-n"&gt;&lt;/span&gt;&lt;span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/th&gt;&lt;th role="columnheader" class="ui-state-default ui-th-column" style="width: 90px;"&gt;&lt;span class="ui-jqgrid-resize"&gt;&amp;nbsp;&lt;/span&gt;&lt;div id="jqgh_Emp_ID" class="ui-jqgrid-sortable"&gt;Emp_ID&lt;span class="s-ico" style="display:none"&gt;&lt;span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n"&gt;&lt;/span&gt;&lt;span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/th&gt;&lt;th role="columnheader" class="ui-state-default ui-th-column" style="width: 157px;"&gt;&lt;span class="ui-jqgrid-resize"&gt;&amp;nbsp;&lt;/span&gt;&lt;div id="jqgh_NAME" class="ui-jqgrid-sortable"&gt;NAME&lt;span class="s-ico" style="display:none"&gt;&lt;span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n"&gt;&lt;/span&gt;&lt;span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/th&gt;&lt;th role="columnheader" class="ui-state-default ui-th-column" style="width: 453px;"&gt;&lt;span class="ui-jqgrid-resize"&gt;&amp;nbsp;&lt;/span&gt;&lt;div id="jqgh_ADDRESS" class="ui-jqgrid-sortable"&gt;ADDRESS&lt;span class="s-ico" style="display:none"&gt;&lt;span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n"&gt;&lt;/span&gt;&lt;span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="ui-jqgrid-bdiv" style="height: 250px; width: 900px;"&gt;&lt;table id="grid" border="0" cellspacing="0" cellpadding="0" role="grid" aria-multiselectable="true" aria-labelledby="gbox_grid" class="ui-jqgrid-btable" style="width: 882px;"&gt;&lt;tbody&gt;&lt;tr id="1" role="row" class="ui-widget-content jqgrow  ui-state-highlight" aria-selected="true"&gt;&lt;td role="gridcell" style="text-align:center;width: 25px;"&gt;&lt;input type="checkbox" id="jqg_1" class="cbox" name="jqg_1" checked="checked"&gt;&lt;/td&gt;&lt;td role="gridcell" style="width: 157px;" title="1"&gt;1&lt;/td&gt;&lt;td role="gridcell" style="width: 90px;" title="Emp1"&gt;Emp1&lt;/td&gt;&lt;td role="gridcell" style="width: 157px;" title="Andrew"&gt;Andrew&lt;/td&gt;&lt;td role="gridcell" style="width: 453px;" title="addr"&gt;addr&lt;/td&gt;&lt;/tr&gt;&lt;tr id="2" role="row" class="ui-widget-content jqgrow ui-state-highlight" aria-selected="true"&gt;&lt;td role="gridcell" style="text-align:center;"&gt;&lt;input type="checkbox" id="jqg_2" class="cbox" name="jqg_2" checked="checked"&gt;&lt;/td&gt;&lt;td role="gridcell" style="" title="2"&gt;2&lt;/td&gt;&lt;td role="gridcell" style="" title="Emp2"&gt;Emp2&lt;/td&gt;&lt;td role="gridcell" style="" title="Cyrus"&gt;Cyrus&lt;/td&gt;&lt;td role="gridcell" style="" title="addr"&gt;addr&lt;/td&gt;&lt;/tr&gt;&lt;tr id="3" role="row" class="ui-widget-content jqgrow"&gt;&lt;td role="gridcell" style="text-align:center;"&gt;&lt;input type="checkbox" id="jqg_3" class="cbox" name="jqg_3"&gt;&lt;/td&gt;&lt;td role="gridcell" style="" title="3"&gt;3&lt;/td&gt;&lt;td role="gridcell" style="" title="Emp3"&gt;Emp3&lt;/td&gt;&lt;td role="gridcell" style="" title="Tom"&gt;Tom&lt;/td&gt;&lt;td role="gridcell" style="" title="addr"&gt;addr&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="ui-jqgrid-resize-mark" id="rs_mgrid"&gt;&amp;nbsp;&lt;/div&gt;&lt;div id="page" style="width: 900px;" class="ui-state-default ui-jqgrid-pager corner-bottom"&gt;&lt;div id="pg_page" class="ui-pager-control" role="group"&gt;&lt;table cellspacing="0" cellpadding="0" border="0" class="ui-pg-table" style="width:100%;table-layout:fixed;" role="row"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td id="page_left" align="left"&gt;&lt;table cellspacing="0" cellpadding="0" border="0" class="ui-pg-table navtable" style="float:left;table-layout:auto;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="ui-pg-button ui-corner-all" title="Add new row" id="add_grid"&gt;&lt;div class="ui-pg-div"&gt;&lt;span class="ui-icon ui-icon-plus"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="ui-pg-button ui-corner-all" title="Edit selected row" id="edit_grid"&gt;&lt;div class="ui-pg-div"&gt;&lt;span class="ui-icon ui-icon-pencil"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="ui-pg-button ui-corner-all" title="View selected row" id="view_grid"&gt;&lt;div class="ui-pg-div"&gt;&lt;span class="ui-icon ui-icon-document"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="ui-pg-button ui-corner-all" title="Delete selected row" id="del_grid"&gt;&lt;div class="ui-pg-div"&gt;&lt;span class="ui-icon ui-icon-trash"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="ui-pg-button ui-state-disabled" style="width:4px;"&gt;&lt;span class="ui-separator"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class="ui-pg-button ui-corner-all" title="Find records" id="search_grid"&gt;&lt;div class="ui-pg-div"&gt;&lt;span class="ui-icon ui-icon-search"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="ui-pg-button ui-corner-all" title="Reload Grid" id="refresh_grid"&gt;&lt;div class="ui-pg-div"&gt;&lt;span class="ui-icon ui-icon-refresh"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;td id="page_center" align="center" style="white-space: nowrap; width: 278px;"&gt;&lt;table cellspacing="0" cellpadding="0" border="0" style="table-layout:auto;" class="ui-pg-table"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td id="first" class="ui-pg-button ui-corner-all ui-state-disabled"&gt;&lt;span class="ui-icon ui-icon-seek-first"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td id="prev" class="ui-pg-button ui-corner-all ui-state-disabled"&gt;&lt;span class="ui-icon ui-icon-seek-prev"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class="ui-pg-button ui-state-disabled" style="width:4px;"&gt;&lt;span class="ui-separator"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;Page &lt;input class="ui-pg-input" type="text" size="2" maxlength="7" value="0" role="textbox"&gt; of &lt;span id="sp_1"&gt;1&lt;/span&gt;&lt;/td&gt;&lt;td class="ui-pg-button ui-state-disabled" style="width:4px;"&gt;&lt;span class="ui-separator"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td id="next" class="ui-pg-button ui-corner-all ui-state-disabled" style="cursor: default;"&gt;&lt;span class="ui-icon ui-icon-seek-next"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td id="last" class="ui-pg-button ui-corner-all ui-state-disabled"&gt;&lt;span class="ui-icon ui-icon-seek-end"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;select class="ui-pg-selbox" role="listbox"&gt;&lt;option role="option" value="10" selected=""&gt;10&lt;/option&gt;&lt;option role="option" value="20"&gt;20&lt;/option&gt;&lt;option role="option" value="30"&gt;30&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;td id="page_right" align="right"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
  
  
       &lt;input type="hidden" name="hidden" id="hidden"&gt;
  
      &lt;input type="hidden" id="rows" name="actualrows" value="3"&gt;
  
          &lt;table align="center"&gt;
          &lt;tbody&gt;&lt;tr&gt;
      &lt;td&gt;Date&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="regdate" id="regdate"&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="button" class="button" name="button" id="button" value="OK"&gt;&lt;/td&gt;&lt;/tr&gt;
  
      &lt;/tbody&gt;&lt;/table&gt;
  </code></pre>
  
  <p>WarningPlease, select row</p>