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="exportToExcel()">Export to Excel</button>
<div id="pivot-container"></div>
CSS
/* Make Flexmonster's overlay non-transparent */
#fm-pivot-view div.fm-ui-modal-overlay {
opacity: 1 !important;
}
/* Style your custom overlay */
.custom-overlay {
opacity: 1 !important;
background: white;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 16;
}
JavaScript
// Create your custom overlay element:
const overlay = document.createElement("div")
overlay.classList.add("custom-overlay")
overlay.style.display = "none"
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: "Color"
},
{
uniqueName: "Category"
}
],
columns: [{
uniqueName: "[Measures]"
}],
measures: [{
uniqueName: "Price"
},
{
uniqueName: "Quantity"
}
]
},
options: {
grid: {
type: "classic",
showTotals: "off"
}
}
},
ready: function() {
// Add your overlay element:
document.querySelector("#fm-pivot-view").append(overlay)
}
});
function customizeCellFunction(cell, data) {
if (data && data.type == "header" &&
data.member &&
data.member.caption != 'All' &&
data.label == "") {
cell.text = " " + data.member.caption;
}
}
function clearCustomizing() {
pivot.customizeCell(null);
}
function startCustomizing() {
pivot.customizeCell(customizeCellFunction);
}
function exportToExcel() {
// Before the export starts, show your custom overlay:
overlay.style.display = "block"
// Save the report settings:
const reportCopy = pivot.getReport();
pivot.on("aftergriddraw", () => {
pivot.off("aftergriddraw");
pivot.exportTo('excel', null, () => {
// Export is complete
// Now we can restore the previous report settings (with the filters):
pivot.setReport(reportCopy);
clearCustomizing()
setTimeout(() => {
overlay.style.display = "none"
}, 100);
});
});
// Expand the data to include all data in the export:
pivot.expandAllData();
// Display all labels in...