title: jqGrid - how to get caption of the current grid?
body: <p>I have more than one <code>jqGrids</code> on my page. These were created dynamically. I want to get the caption of the grid from row click. I see <code>setCaption</code> method but no getCaption. So was wondering if there is a good way to get this value?</p>
  
  <p>I didn't find any helpful link here in SO or outside. Appreciate any help.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>@Oleg's solution helped me to fix the issue, his comment on how to find the grid id made me re-think about my problem and got the solution:</p>
  
  <p><code>zLoadLabResult()</code> generates grid dynamically. And when user clicks on the checkbox, I wanted to know the caption of the grid for some other logic that i am building.</p>
  
  <pre><code>function zLoadLabResults(fulldata) {
      fulldata = $.parseJSON(fulldata);
      $.each(fulldata, function (i, item) {
          var data = item.resultData;
          var colNames = item.colNames;
  
          var colModelsArray = [];
          for (var i = 0; i &lt; colNames.length; i++) {
              var str;
              if (i === 0) {
                  str = {
                      name: 'id',
                      width: 25,
                      editoptions: { value: "True:False" },
                      editrules: { required: true },
                      edittype: 'checkbox',
                      formatter: zCheckboxFormatter,
                      formatoptions: { disabled: false },
                      editable: true,
                      sortable: false
                  };
              } else {
                  str = {
                      name: colNames[i],
                      index: colNames[i],
                      width: '100px'
                  };
              }
              colModelsArray.push(str);
          }
  
          var gridName = "grid-" + item.testName;
          $("#gridcontainer").append("&lt;table id='grid-" + item.testName + "' class='grid'&gt;&lt;/table&gt;");
  
          $("#" + gridName).jqGrid({
              //url: "user.json",
              //datatype: "json",
              datatype: "local",
              colNames: colNames,
              colModel: colModelsArray,
              height: "auto",
              width: "auto",
              caption: item.testName
          });
  
          var names = colNames;
          var mydata = [];
  
          for (var i = 0; i &lt; data.length; i++) {
              mydata[i] = {};
              for (var j = 0; j &lt; data[i].length; j++) {
                  mydata[i][names[j]] = data[i][j];
              }
          }
  
          for (var i = 0; i &lt;= mydata.length; i++) {
              $("#" + gridName).jqGrid('addRowData', i + 1, mydata[i]);
          }
          for (var i = 0; i &lt;= colNames.length; i++) {
              $("#" + gridName).jqGrid("setLabel", colNames[i], "", { "text-align": "left" });
          }
      });
  };
  
  function zCheckboxFormatter(cellvalue, options, rowObject) {
      return '&lt;input type="checkbox" class="selectedId" name="Id-' + cellvalue + '"&gt;';
  };
  </code></pre>
  
  <p>I have the following event hooked to checkbox that does the trick by adding Oleg's solution:</p>
  
  <pre><code>$('table[id^="grid-"]').on("click", "td &gt; input", function (e) {
      var grid = "#" + $(e.target).closest("table").attr("id");
      var caption = $(grid).jqGrid("getGridParam", "caption");
  
      var checked = $(e.target).is(":checked")
  
      var rowId = $(e.target).closest("tr").attr("id")
      rowData = $(grid).getRowData(rowId);        
  });
  </code></pre>