title: jqgrid - Set the custom_value of edittype: 'custom'
body: <p>The custom_value of place_id is set to whichever row I click first. Subsequent clicked rows will all use that same value, regardless of their actual value. Why?</p>
  
  <p><strong>example:</strong></p>
  
  <pre><code>place_id foo_name bar_value
     10      blah       abc
     11      blah2      fgr
  </code></pre>
  
  <p>click the row with the place_id of 10 and click "edit" and the form that appears will have <code>10</code> for the place_id value. Make a change and save it then click the next row down. The form will still have the place_id of <code>10</code> though all other values will be correct. </p>
  
  <p><strong>My code:</strong></p>
  
  <p>The column place_id looks like this:</p>
  
  <pre><code>{name:'place_id', index:'place_id', editable: true, edittype:'custom',
   editoptions: { custom_element:myelem,custom_value:myval }}
  </code></pre>
  
  <p>The <code>myval</code> function is:</p>
  
  <pre><code>function myval(elem){
      return elem.val();
  }
  </code></pre>
  
  <p>What I need is for the myval to be set to the correct place_id for the row being edited. I looked at the <code>elem</code> object in Firebug and I see that it always has the value of whichever row was first clicked but I don't understand why nor do I see where I can grab the correct value from. Any suggestions are appreciated (I tried asking on the jqgrid forums but nothing came of it so I'm turning to stackoverflow).</p>
  
  <p>*Edit: If I use <code>edittype:'text'</code> rather than <code>edittype:'custom'</code> I get the correct values displayed and passed but then the column is editable and it should only be visible but not editable.</p>
  
  <p>Full code:</p>
  
  <pre><code>jQuery(document).ready(function(){ 
      jQuery("#list").jqGrid({
          url:'/foo/bar/results',
          datatype: 'json',
          mtype: 'POST',
          colNames:['Place ID', 'Site ID', 'Site Name', 'API ID', 'M Type'],
          colModel :[ 
              {name:'place_id', index:'place_id', key: true, sorttype:'integer',
               width:70, editable: true, edittype:'custom',
               editoptions: {custom_element:myelem,custom_value:myval }},
              {name:'site_id', index:'site_id', sorttype:'integer', width:70,
               editable: true, edittype: 'select', editrule: {required: true},
               editoptions:{value:getSites(), size:30}},
              {name:'site_name', index:'site_name', width:150, editable: false,
               editrule: {required: true}, editoptions: {size:30}},
              {name:'api_id', index:'api_id', sorttype:'integer', width:75,
               editable: true, edittype: 'text', editrules: {required: true},
               editoptions:{size:30}},
              {name:'m_type', index:'m_type', width:150, editable: true,
               edittype: 'select', editrules: {required: true},
               editoptions:{value:{'one':'one','two':'two','three':'three',
                                   'four':'four'},size:30}} 
          ],
          editurl:'/foo/bar/editinfo',    
          height: 'auto',
          width: 'auto',
          pager: '#pager',
          viewrecords: true,
          loadonce: true,
          rowNum:20,
          rowList:[20,40,60,80,100],
          caption: 'Meter Listing'
      }); 
  
      // Edit functionality
      $("#editfields").click(function(){
          var gr = jQuery("#list").jqGrid('getGridParam','selrow');
          if( gr != null ) { 
              jQuery('#list').setGridParam({datatype:'json'});
              jQuery("#list").jqGrid('editGridRow',gr,
                             {editCaption: 'Edit Place Details',height:550,
                              closeAfterEdit:true,width:600,reloadAfterSubmit:true});
          } else {
              alert("Please select a row");
          }
      });
  });
  
  function myelem(value,options){
      return $('&lt;input type="text" value="'+value+'" disabled="disabled"/&gt;');
  }
  
  function myval(elem){
      return elem.val();
  }
  </code></pre>
  
  <p><strong>edit2:</strong></p>
  
  <p>getSites:</p>
  
  <pre><code>function getSites(){
      &lt;?php
      $sites = "0:Select";
      foreach ($this-&gt;sites as $k =&gt; $v){
          $sites = $sites . ";" . $v['site_id'] . ":" . $v['site_name'];
      }
      ?&gt;
      return "&lt;?= $sites ?&gt;";
  }
  </code></pre>