How do I download data as csv?

I have read data from SQL and want to download it as csv.

Quoting response from Hetu:

{{
function() {
    const csvRows = AllDataQuery.data;
    const objArr = [];
    const headers = csvRows[0].split(',');
        for(let i = 1; i < csvRows.length; i++) {
            const rowObj = {};
            objArr.push(rowObj);
            const rowArr = csvRows[i].split(',');
            rowArr.forEach((val, index) => {
                rowObj[headers[index]] = val;
            });
        }
    download(objArr, "AllData.csv", "data:text/csv")
}()
}}
1 Like

There is also a download button available with table widget which can be used to download data as a csv or excel sheet.