title: Exporting Specific jqGrid columns to Excel Sheet
body: <p>I am exporting my grid data to an excel sheet and everything is working awesome. Only thing is I want to include only  certain columns. Only the following: id,name,assign date,check date,due date, notes. How to do this? 
  Here is what I have so far: </p>
  
  <p>jQgrid:</p>
  
  <pre><code>$(function(){ 
    $("#list").jqGrid({
      url:'request.php',
      editurl: "jqGridCrud.php",
      datatype: 'xml',
      mtype: 'GET',
      height: 530,
      width: 850,
          scrollOffset:0,
  
  
  
      colNames:['id','Project', 'Assigned To','Assign Date','Check Date','Due Date','Attached','Notes',''],
      colModel :[ 
  
        {name:'id', index:'id', width:25}, 
        {name:'name', index:'name', width:235, align:'left',editable:true, editoptions:{
              size:60} }, 
        {name:'Assigned to', index:'id_continent', width:55, align:'right',editable:true,edittype:'select', 
        editoptions:{value: "Henry:Henry; Ramon:Ramon; Paul:Paul" },mtype:'POST'  }, 
  
        {name:'assign date', index:'lastvisit', width:70, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'm/dd/yy',editable:true, edittype: 'text',mtype:'POST' ,editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'m/dd/yy'});}}} ,
  
  
        {name:'check date', index:'cdate', width:70, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'm/dd/yy', edittype: 'text',editable:true ,mtype:'POST' ,editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'m/dd/yy'});}}} ,
  
        {name:'due date', index:'ddate', width:70, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'm/dd/yy',editable:true, edittype: 'text',editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'m/dd/yy'});}}} ,
  
  
        {name:'files', index:'email', width:40,align:'center',sortable:false,mtype:'POST', formatter:function(cellvalue, options, rowObject){
              return '&lt;a href="' + cellvalue + '" target="_blank"&gt;FILES &lt;/a&gt; '
          } },
          {name:'notes', index:'notes', width:100, align:'left',editable:true,edittype:'textarea', editoptions:{
              rows:5,cols:60,maxlength:200} },
          {name:'act',index:'act',width:25 ,align:'left', sortable:false,formatter: "actions",cellattr: function () { return ' title="Delete Project"'; },
  formatoptions: {
      keys: true,
      delbutton: true,
      editbutton:false,
  
  
      delOptions: {
          url: 'jqGridCrud.php',
          afterShowForm: function ($form) {
      $("#dData", $form.parent()).click();
  },
          beforeShowForm: function ($form) {
      $("td.delmsg", $form[0]).html("Do you really want delete the row with &lt;b&gt;id=" +
           $("#list").jqGrid('getGridParam','selrow') + "&lt;/b&gt;?");
  },
          msg: "Remove Selected Project?",
          bSubmit: "Remove",
          bCancel: "Cancel"
      } 
  }}, 
  
  
      ],
      pager: '#pager',
  
  
      rowNum:20,
      rowList:[20,40,80],
      sortname: 'id',
      sortorder: 'desc',
      viewrecords: true,
      gridview: true,
      caption: 'Pending Assignments',
  
  
  
      ondblClickRow: function(rowid) {
  
      $(this).jqGrid('viewGridRow', rowid,
                          {width:550,Height:550,recreateForm:true,
                           closeOnEscape:true,reloadAfterSubmit:true, modal:true,mtype:'post',top:350,left: 30});}
  
  
              });
  
  $.extend($.jgrid.nav, {delicon: "ui-icon-circle-check", deltext: "Project Complete", 
  });
  
   $("#list").jqGrid("navGrid", "#pager", { add: false, search: false, edit:false, refresh:false }) .navButtonAdd('#pager',{
  
  
                                  caption:"Export to Excel", 
                                  buttonicon:"ui-icon-save", 
                                  onClickButton: function(){ 
                                    exportExcel();
                                  }, 
                                  position:"last"
                              });
    // setup grid print capability. 
      setPrintGrid('list','pager','Print');
      });
  </code></pre>
  
  <p>Excel Export Function:      </p>
  
  <pre><code>  function exportExcel()
      {
          var mya=new Array();
          mya=$("#list").getDataIDs();  // Get All IDs
          var data=$("#list").getRowData(mya[0]);     // Get First row to get the labels
          var colNames=new Array(); 
          var ii=0;
          for (var i in data){colNames[ii++]=i;}    // capture col names
          var html="";
          var filtered = [ 6, 8];
              for(k=0;k&lt;colNames.length;k++)
              { 
              if (filtered.indexOf(k) &gt;= 0)
              {
              html=html+colNames[k]+"\t";     // output each Column as tab delimited
              }
              html=html+"\n"; 
              }                   // Output header with end of line
          for(i=0;i&lt;mya.length;i++)
              {
              data=$("#list").getRowData(mya[i]); // get each row
              for(j=0;j&lt;colNames.length;j++)
                  { 
                  if (filtered.indexOf(j) &gt;= 0){
               html=html+data[colNames[j]]+"\t"; // output each Row as tab delimited
                  }
              html=html+"\n";  // output each row with end of line
  
              }}
          html=html+"\n";  // end of line at the end
          document.forms[0].csvBuffer.value=html;
          document.forms[0].method='POST';
          document.forms[0].action='csvExport.php';  // send it to server which will open this contents in excel file
          document.forms[0].target='_blank';
          document.forms[0].submit();
      }
  </code></pre>
  
  <p>PHP on server:</p>
  
  <pre><code>&lt;?php 
  
  header('Content-type: application/vnd.ms-excel');
  header("Content-Disposition: attachment; filename=current-projects.xls");
  header("Pragma: no-cache");
  
  $buffer = $_POST['csvBuffer'];
  
  try{
      echo $buffer;
  }catch(Exception $e){
  
  }
  
  ?&gt;
  </code></pre>