Data Download

Introduction #

SmartChart provides ds_download() function to download dataset data as CSV or Excel files. Combined with button click events, enables flexible on-demand download of current query results (including filter conditions).

Usage #

ds_download(name, dataset, xls=0)
// name: file name
// dataset: 2D array or string
// xls: 0=CSV (default), 1=Excel

Example #

  1. Create a download button in template with a drag container:
<div class="smtdrag" id="id_down1">
    <button>Download Data</button>
</div>
  1. Add click handler in any chart JS:
$('#id_down1').click(() => {
    ds_download('report_data.csv', dataset);
});

Function Parameters #

Parameter Description
name Download file name, e.g., 'data.csv' or 'data.xlsx'
dataset 2D array data or string content
xls 0=CSV (default), 1=Excel (.xlsx)

Complete Example #

$('#id_down1').click(() => {
    ds_download('sales_data_' + new Date().format('yyyyMMdd') + '.xlsx', dataset, 1);
});