title: How to Edit or Add a New Row in jqGrid
body: <p>My jqGrid that does a great job of pulling data from my database, but I'm having trouble understanding how the Add New Row functionality works.</p>
  
  <p>Right now, I'm able to edit inline data, but I'm not able to create a new row using the Modal Box.  I'm missing that extra logic that says, "If this is a new row, post this to the server side URL" instead of modifying existing data.  (Right now, hitting Submit only clears the form and reloads the grid data.)</p>
  
  <p>The documentation states that Add New Row is:</p>
  
  <pre><code>jQuery("#editgrid").jqGrid('editGridRow',"new",{height:280,reloadAfterSubmit:false}); 
  </code></pre>
  
  <p>but I'm not sure how to use that correctly.  I've spent alot of time studying the Demos, but they seem to all use an external button to fire the new row command, rather than using the Modal Form, which I want to do.</p>
  
  <p>My complete code is here:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;jqGrid&lt;/title&gt;  
  
  &lt;link rel="stylesheet" type="text/css" media="screen" href="../css/ui-lightness/jquery-ui-1.7.2.custom.css" /&gt;
  &lt;link rel="stylesheet" type="text/css" media="screen" href="../css/ui.jqgrid.css" /&gt;
  
  &lt;script src="jquery-1.3.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="../js/i18n/grid.locale-en.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="jquery.jqGrid.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h2&gt;My Grid Data&lt;/h2&gt;
  &lt;table id="list" class="scroll"&gt;&lt;/table&gt;
  &lt;div id="pager" class="scroll c1"&gt;&lt;/div&gt; 
  
  &lt;script type="text/javascript"&gt;
  var lastSelectedId;
  
  jQuery('#list').jqGrid({
  url:'grid.php',
  datatype: 'json',
  mtype: 'POST',
  colNames:['ID','Name', 'Price', 'Promotion'],
  colModel:[    
     {name:'product_id',index:'product_id', width:25,editable:false},     
     {name:'name',index:'name', width:50,editable:true, edittype:'text',editoptions:{size:30,maxlength:50}},
     {name:'price',index:'price', width:50, align:'right',formatter:'currency', editable:true},
     {name:'on_promotion',index:'on_promotion', width:50, formatter:'checkbox',editable:true, edittype:'checkbox'}],
  rowNum:10,
  rowList:[5,10,20,30],
  pager: $('#pager'),
  sortname: 'product_id',
  viewrecords: true,
  sortorder: "desc",
  caption:"Database",
  width:500,
  height:150,  
  onSelectRow: function(id){
  if(id &amp;&amp; id!==lastSelectedId){
    $('#list').restoreRow(lastSelectedId);
    $('#list').editRow(id,true,null,onSaveSuccess);
    lastSelectedId=id; }},
  editurl:'grid.php?action=save'}) 
  
  .jqGrid('navGrid','#pager', 
      {refreshicon: 'ui-icon-refresh',view:true},
      {height:280,reloadAfterSubmit:true}, 
      {height:280,reloadAfterSubmit:true}, 
      {reloadAfterSubmit:true})
  
  .jqGrid('editGridRow',"new",{height:280,reloadAfterSubmit:false}); 
  
  function onSaveSuccess(xhr) 
  {response = xhr.responseText; if(response == 1) return true; return false;}
  
  &lt;/script&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>If it makes it easier, I'd be willing to scrap the inline editing functionality and do editing and posting via modal boxes.</p>
  
  <p>Any help would be greatly appreciated.</p>