How to export wijmo flexgrid if flexgrid contains no rows?

Posted by: soumya.mangaraj on 17 February 2020, 10:36 am EST

    • Post Options:
    • Link

    Posted 17 February 2020, 10:36 am EST

    We want to export flexgrid header into CSV file even if flexgrid contains no rows but it should contain rowheaders.

    Please find the code.

    exportBatch(fileName) {

    console.log(this.flex.rows.length);

    let rng;

    if (this.flex.rows.length === 0) {

    rng = new wjcGrid.CellRange(0, 3, this.flex.rows.length, this.flex.columns.length - 1);

    } else {

    rng = new wjcGrid.CellRange(0, 3, this.flex.rows.length - 1, this.flex.columns.length - 1);

    }

    const csv = this.flex.getClipString(rng, true, true);

    fileName = fileName + ‘.csv’;

    const fileType = ‘txt/csv;charset=utf-8’;

    if (navigator.msSaveBlob) {

    // IE

    navigator.msSaveBlob(

    new Blob([csv], {

    type: fileType

    }),

    fileName

    );

    } else {

    const e = document.createElement(‘a’);

    e.setAttribute(‘href’, ‘data:’ + fileType + ‘,’ + encodeURIComponent(csv));

    e.setAttribute(‘download’, fileName);

    e.style.display = ‘none’;

    document.body.appendChild(e);

    e.click();

    document.body.removeChild(e);

    }

    }

  • Posted 17 February 2020, 10:42 am EST - Updated 3 October 2022, 5:22 pm EST

  • Posted 19 February 2020, 12:24 am EST

    Hi Soumya,

    You can add logic in your export method in which you can manually create a CSV text by iterating over each column and adding its header to CSV. Please refer to the sample below:

    https://stackblitz.com/edit/angular-dh9sh2

    Regards,

    Ashwin

  • Posted 20 February 2020, 7:28 am EST

    Thanks A lot Ashwin.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels