JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
HTML
<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<button onclick="exportClassicForm()">
Export
</button>
<div id="pivotContainer"></div>
JavaScript
var pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: false,
report: {
dataSource: {
filename: "data/data.csv"
},
"slice": {
"rows": [{
"uniqueName": "Category"
},
{
"uniqueName": "Country"
},
{
"uniqueName": "Color"
},
{
"uniqueName": "Business Type"
}
],
"columns": [{
"uniqueName": "Destination"
},
{
"uniqueName": "[Measures]"
}
],
"measures": [{
"uniqueName": "Quantity",
"aggregation": "sum"
}
],
"expands": {
"expandAll": true
}
}
}
});
function exportClassicForm() {
let container = document.querySelector("#pivotContainer");
let initialWidth = container.getBoundingClientRect().width;
container.style.width = ((pivot.gridColumnCount() - 1) * 110 + pivot.getRows().length * 110) + "px";
pivot.setOptions({
grid: {
type: "classic"
}
});
pivot.refresh();
pivot.on("exportcomplete", () => {
pivot.off("exportcomplete");
pivot.setOptions({
grid: {
type: "compact"
}
});
pivot.refresh();
container.style.width = initialWidth + "px";
});
setTimeout(() => {
pivot.exportTo("pdf");
}, 0);
}