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>
<div id="pivotContainer"></div>
JavaScript
var pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
beforetoolbarcreated: customizeToolbar,
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 = (("3000px" - 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("excel");
}, 0);
}
function customizeToolbar(toolbar) {
// get all tabs
var tabs = toolbar.getTabs();
toolbar.getTabs = function () {
// add new handler to the export to excel
// from the Toolbar
tabs[3].menu[3].handler = exportClassicForm;
return tabs;
}
}