<!-- 
/*
Copyright 2017 apHarmony

This file is part of jsHarmony.

jsHarmony is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

jsHarmony is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this package.  If not, see <http://www.gnu.org/licenses/>.
*/
-->
<script type="text/x-tutorial-info">
{
  "Title": "Exporting CSV",
  "Menu": ["Models","Grids"],
  "Code": ["/models/GridExport_Cust_Listing.json"],
  "Demo": "jsHarmonyTutorials/GridExport_Cust_Listing"
}
</script>
Export any grid to a CSV by pressing the "Export" button in the top right.
<%-getScreenshot('jsHarmonyTutorials/GridExport_Cust_Listing?popup=1','Grid Export')%>

The grid will export the data with column headers to a CSV:<br/>
&nbsp;
<div class="GridExport_Cust_Listing_Data"></div>
<script type="text/javascript">
(function(jsh){
  var jobj = jsh.$root('.GridExport_Cust_Listing_Data');
  var _ = jsh._;
  var XExt = jsh.XExt;
  jobj.empty();
  jsh.XForm.prototype.XExecute('jsHarmonyTutorials/GridExport_Cust_Listing',{},function(rslt){
    if(rslt && rslt.GridExport_Cust_Listing){
      var html = '<table border="1" cellpadding="5">';
      html += '<tr><th>ID</th><th>Customer</th></tr>';
      _.each(rslt.GridExport_Cust_Listing, function(item){
        html += '<tr><td>'+XExt.escapeHTML(item.cust_id)+'</td><td>'+XExt.escapeHTML(item.cust_name)+'</td></tr>';
      });
      html += '</table>';
      jobj.html(html);
    }
  });
})(<%=instance%>)
</script>

<h4>Search / Sort</h4>
If the data is searched and sorted, the search and sort will be applied to the CSV.

<h4>Row Limit</h4>
The jsHarmony config setting "export_rowlimit" in app.config.js defines the maximum number of rows returned in an export:
<pre>
jsh.Config.export_rowlimit = 5000;
</pre>

<h4>Export URL</h4>
CSV exports can be linked using URLs.  For example, the CSV URL for the model GridExport_Cust_Listing would be:<br/>
<a href="/_csv/GridExport_Cust_Listing">/_csv/GridExport_Cust_Listing</a>