JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
April 15, 2021
HTML
<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<h3>
Try exporting using the "Export" tab on the Toolbar
</h3>
<div id="pivot-container"></div>
CSS
.highlight {
background-color: yellow !important;
}
JavaScript
let pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
"dataSource": {
"filename": "data/data.json"
},
"slice": {
"rows": [{
"uniqueName": "Country"
}, {
"uniqueName": "Business Type"
}],
"columns": [{
"uniqueName": "Color"
}, {
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "Price"
}, {
"uniqueName": "Quantity"
}],
"expands": {
"rows": [{
"tuple": [
"country.[australia]"
]
},
{
"tuple": [
"country.[canada]"
]
}
]
}
}
}
});
pivot.on("exportcomplete", revealSubtotals);
pivot.on("printcomplete", revealSubtotals);
function revealSubtotals() {
pivot.setOptions({
grid: {
showTotals: "on"
}
});
pivot.refresh();
}
function hideSubotals() {
pivot.setOptions({
grid: {
showTotals: "off"
}
});
pivot.refresh();
}
pivot.on("beforetoolbarcreated", (toolbar) => {
let tabs = toolbar.getTabs();
toolbar.getTabs = () => {
let exports = tabs.find(tab => tab.id == "fm-tab-export").menu;
if (!exports) return;
exports.forEach(tab => {
let hanlder =
tab.args ? () => {
pivot.exportTo(tab.args);
} : () => {
pivot.print();
};
tab.handler = () => {
pivot.on("aftergriddraw", () => {
pivot.off("aftergriddraw");
hanlder();
});
hideSubotals();
}
});
return tabs;
};
});