Posted 7 July 2020, 9:07 am EST
- Updated 3 October 2022, 7:01 am EST
Hi Ashwin,
I tried to use the custom getClipString method and I’m able to get the formatted values. But i’m missing the rowFields and columnHeaders
May i know how can i get the rowFields and columnHeaders ?
Here is the code:
.
export(docType: string) {
if (docType === 'csv') {
let grid = this.pivotGrid,
rng = new CellRange(0, 0, grid.rows.length - 1, grid.columns.length - 1);
let csv = this.getClipString(grid, rng);
this.exportFile(csv, 'PivotGrid.csv');
}
}
getClipString(grid, sel) {
var text = "";
let etemp = document.createElement("div");
etemp.style.visibility = "hidden";
grid.cells.hostElement.appendChild(etemp);
// loop through selected rows/columns
for (var r = sel.topRow; r <= sel.bottomRow; r++) {
// var firstCell = true;
for (var c = sel.leftCol; c <= sel.rightCol; c++) {
// if (firstCell) {
// firstCell = false;
// } else {
text = text + ","; // comma after each cell
// }
// add cell text
grid.cellFactory.updateCell(grid.cells, r, c, etemp);
text += etemp.textContent.replace(/,/g,"");
}
text += "\n"; // new line after each row
}
// dispose of temporary cell
grid.cellFactory.disposeCell(etemp);
etemp.parentElement.removeChild(etemp);
return text;
}
Below are the screenshots: