title: jqGrid - How to set custom editoptions based on *initial* column values?
body: <p>I am using the open source jqGrid plugin with EF4 and ASP.NET Web Forms. I need to set an input element in an inline-editable grid row based on a column value from the DB. For example, the first row could contain a DDL, the second row could contain a checkbox, etc. </p>
  
  <p>I'm trying to achieve this using the <code>custom_element</code> and <code>custom_values</code>, like so:</p>
  
  <pre><code>$("#grid1").jqGrid({
      url: 'Default.aspx/getGridData',
      datatype: 'json',
      ...
      colModel: [
      ...
      //contains the input type ('select', etc.)
      { name: 'InputType', hidden:true }, 
      ...
      //may contain a string of select options ('&lt;option&gt;Option1&lt;/option&gt;'...)
      { 
        name: 'Input', 
        editable:true, 
        edittype:'custom', 
        editoptions:{
           custom_element: /* want cell value from InputType column here */ , 
           custom_value:   /* want cell value from Input column here */ 
        } 
       }, 
      ...
      ]
  });
  </code></pre>
  
  <p>The jqGrid <a href="http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#editoptions" rel="nofollow noreferrer">docs</a> say that I can call custom functions to set <code>custom_element</code> and <code>custom_values</code>, but I don't see how I can capture column values and pass them into my custom functions. </p>
  
  <p>For setting <code>custom_values</code>, I did notice <a href="https://stackoverflow.com/questions/4987123/in-jqgrid-is-there-anyway-to-use-ajax-to-get-data-for-your-custom-element">Oleg's nice solution</a> using the <code>list:</code> parameter, but that appeared to involve an extra Ajax call. I want to avoid this, as I already have the all data I need from the initial Ajax call for the grid.</p>
  
  <p>In summary, I need to do the following while in inline-edit mode:</p>
  
  <ol>
  <li>dynamically assign an input type from a DB value </li>
  <li>dynamically assign input values (for DDL or checkboxes) from a DB string</li>
  </ol>
  
  <p>I am also open to skipping the use of <code>custom_element</code> and <code>custom_values</code>, but then I still face the same problem of dynamically setting the <code>edittype</code> and <code>editoptions:{value:}</code> parameters.</p>
  
  <p>Any ideas on how to do this? Is there a different approach that I should be taking?</p>
  
  <p><strong>UPDATE</strong>: Thanks for your efforts to help me out. Per request, here is an abbreviated example of my JSON response:</p>
  
  <pre><code>{"d":[
  {"Input":null,"InputType":"select"},
  {"Input":"From downtown, proceed west on Interstate 70.", "InputType":"text"}
  ]}
  </code></pre>
  
  <p>With this data, I would want to show an empty select in one row, and a populated text field in the next row. Both would be editable inline. </p>
  
  <p><strong>SOLUTION</strong>: I have returned to this problem in order to find a solution that does <strong>not</strong> involve using <code>custom_element</code> and <code>custom_values</code>. Here is my solution (based on the <a href="https://stackoverflow.com/a/7538323/920506">accepted answer</a> below) to changing <code>edittype</code> and <code>editoptions</code> :</p>
  
  <pre><code>loadComplete: function () {
      var rowIds = $("#grid1").jqGrid('getDataIDs');
  
      $.each(rowIds, function (i, row) {
         var rowData = $("#grid1").getRowData(row);
  
         if (rowData.InputType == 'select') {
            $("#grid1").jqGrid('restoreRow', row);
                  var cm = $("#grid1").jqGrid('getColProp', 'Input');
                  cm.edittype = 'select';
                  cm.editoptions = { value: "1:A; 2:B; 3:C" };
                  $("#grid1").jqGrid('editRow', row);
                  cm.edittype = 'text';
                  cm.editoptions = null;
         }
     });
  }
  </code></pre>
  
  <p><strong>Nota Bene</strong>: One important thing for me was remembering to set the <code>editoptions</code> back to <code>null</code>, after calling <code>editrow</code>. Also, as Oleg mentioned in the comments, avoiding the use of custom elements allows me to implement datepicker inputs without extra trouble. This was important for my app, so I ended up accepting Oleg's answer, but I still upvoted Walter's answer, as well. If this is bad form, I sincerely apologize. I simply wanted to reward the solution that worked best for me.</p>