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);
}
}