title: How do I add more rows in jqGrid?
body: <p>I have the following grid:</p>
  
  <pre><code> var gridMyTasks = $('#gridMyTasks').jqGrid({
      jsonReader: { root: 'rows', repeatitems: false, id: 'ID' },
      datatype: 'json',
      colNames: ['Task ID', 'Task Name', 'Project Name', 'Task Stage', 'Doc Type', 'Due Date'],
      colModel: [
            { name: 'ShortCode', width: 70, jsonmap: 'ShortCode', sortable: false },
            { name: 'TaskName', width: 200, jsonmap: 'TaskName', formatter: 'fmtTaskName', sortable: false },
            { name: 'ProjName', width: 200, jsonmap: 'ProjName', formatter: 'fmtName', sortable: false },
            { name: 'TaskStage', width: 100, jsonmap: 'TaskStage', sortable: false },
            { name: 'DocType', width: 130, jsonmap: 'DocType', sortable: false },
            { name: 'DueDate', width: 70, jsonmap: 'DueDate', sortable: false }
    ],
      rowNum: 0,
      height: 'auto',
      autowidth: true,
      forceFit: true,
      multiselect: false,
      caption: '',
      altclass: 'zebra',
      altRows: true,
      hoverrows: false,
      gridview: true,
      sortable: false,
      grouping: true,
      groupingView: { groupField: ['ProjName'], groupDataSorted: true }
   });
  </code></pre>
  
  <p>When my page loads, I call a web service to get the first 15 rows and add it to a grid:</p>
  
  <pre><code> TPM.GetHomepageData(function (results) // AJAX web service to load data
   {
      gridMyTasks[0].addJSONData({ rows: results.Tasks });
      if (results.Tasks.length &gt;= 15) $('#divTaskFooter').show(); // Enable "Show All" link
  
      gridMyTasks.show();
   }, null);
  </code></pre>
  
  <p>This works great.  However, for users who have <em>more than</em> 15 rows of data, I have a "Show all..." link.  This calls a web service again, but passes in a parameter to indicate I want all rows.  This is hooked up as follows:</p>
  
  <pre><code>var loadGrid = function (limit)
  {
     TPM.GetMyTasks(limit, curSort, curDir, function (results)
     {
        grid.clearGridData(true); // should clear the existing rows first?
        grid[0].addJSONData({ rows: results }); // *all* rows, not sure new ones
        link.html(expanded ? 'Show less...' : 'Show all...');
     }, null);
  };
  
  moreLink.click(function (event) // When user clicks "Show All", load all the data
  {
     expanded = !expanded;
     loadGrid(expanded ? null : 15);
     event.preventDefault();
  });
  </code></pre>
  
  <p>In this case, <code>results</code> is an array of 18 rows, and this data is correct.  However, what happens is the original 15 rows stick around, the 18 rows are added on, then I have 33 rows in total.  In other words, the grid isn't being cleared first.</p>
  
  <p>If I comment out the <code>addJSONData</code> line:</p>
  
  <pre><code>grid.clearGridData(true);
  //grid[0].addJSONData({ rows: results });
  </code></pre>
  
  <p>Then, the grid will clear and I'll see zero rows.  So, it's as if the grid is cleared, then the old data is resurrected like a bunch of undead zombie rows, and the duplicate rows are tacked on.  I must be doing something wrong.</p>
  
  <p><strong>Update: Adding HTTP Traffic capture for Oleg</strong></p>
  
  <p><em>Initial Load:</em></p>
  
  <pre><code>POST http://oursite.com/TPM.svc/GetHomepageData HTTP/1.1
  Accept: */*
  Accept-Language: en-us
  Referer: oursite.com
  x-requested-with: XMLHttpRequest
  Content-Type: application/json; charset=utf-8
  Accept-Encoding: gzip, deflate
  User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)
  Host: oursite.com
  Content-Length: 0
  Connection: Keep-Alive
  Pragma: no-cache
  Cookie: SMSESSION=Unimportant
  </code></pre>
  
  <p><em>Response:</em></p>
  
  <pre><code>HTTP/1.1 200 OK
  Cache-Control: private
  Content-Length: 893
  Content-Type: application/json; charset=utf-8
  Server: Microsoft-IIS/7.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Date: Thu, 25 Jul 2013 16:57:43 GMT
  
  {"d":{ ... A bunch of JSON here ...}}
  </code></pre>
  
  <p><em>Show All Click:</em></p>
  
  <pre><code>POST http://oursite.com/TPM.svc/GetMyTasks HTTP/1.1
  Accept: */*
  Accept-Language: en-us
  Referer: oursite.com
  x-requested-with: XMLHttpRequest
  Content-Type: application/json; charset=utf-8
  Accept-Encoding: gzip, deflate
  User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)
  Host: oursite.com
  Content-Length: 42
  Connection: Keep-Alive
  Pragma: no-cache
  Cookie: SMSESSION=Unimportant
  
  {"limit":null,"orderBy":null,"desc":false}
  </code></pre>
  
  <p><em>Response:</em></p>
  
  <pre><code>HTTP/1.1 200 OK
  Cache-Control: private
  Content-Length: 1762
  Content-Type: application/json; charset=utf-8
  Server: Microsoft-IIS/7.5
  set-cookie: SMSESSION=...
  Set-Cookie: SMSESSION=...
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Date: Thu, 25 Jul 2013 17:01:55 GMT
  
  {"d":{ ... A bunch of JSON here ...}}
  </code></pre>