Revindex Storefront

How to export data from custom report

Last updated on 2017-11-22 2 mins. to read

For many reasons, you may occasionally want to export the data out from the custom reports into a tabular or spreadsheet format for manipulation. 

Custom reports are built using HTML and XSL tokens. You can render the data separately into a Javascript string that is hidden from the normal view. Simply include a button to retrieve the data to CSV and send to the window object using Javascript. For example, the following Javascript code can be used to trigger the download of the CSV file.

function downloadFile(fileName, data) {

    var a = document.createElement("a");
    if (navigator.msSaveBlob) {
        navigator.msSaveBlob(new Blob([data], {
            type: "text/csv"
        }), fileName);
    } else if ('download' in a) {
        a.href = 'data:text/csv;charset=UTF-8,' + encodeURIComponent(data); = fileName;
        setTimeout(function() {
        }, 100);
    } else if (document.execCommand) {
        var oWin ="about:blank", "_blank");
        oWin.document.execCommand('SaveAs', true, fileName);

function exportCsv() {
var data = '"Order","Status"\r\n';
{xsl:for-each select=&quot;/in/dataSet/dataTable/dataRow&quot; }
data += '"{xsl:value-of select="SalesOrderNumber" /}","{xsl:value-of select="Status" /}"\r\n';

downloadFile('Orders.csv', data);
<p><button class="btn btn-link" type="button" onclick="exportCsv()" style="float: right">Export</button></p>


You can find many examples online on how to use Javascript to export CSV. Some examples are shown here:


Powered by Revindex Wiki