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="pivot-container"></div>
JavaScript
const pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
reportcomplete: () => {
pivot.customizeCell(customizeCellFunction);
},
report: {
"options": {
"grid": {
"showGrandTotals": "off"
}
},
"dataSource": {
"type": "json",
"filename": "https://cdn.flexmonster.com/data/retail-data.json"
},
"slice": {
"rows": [{
"uniqueName": "Country",
"filter": {
"members": ["Australia"]
}
}],
"columns": [{
"uniqueName": "Status"
},
{
"uniqueName": "[Measures]"
}
],
"measures": [{
"uniqueName": "Price",
"aggregation": "sum",
}],
},
}
});
function customizeCellFunction(cell, data) {
let measure = pivot.getReport().slice.measures[0].uniqueName;
let measuresTotal = pivot.getReport().slice.measures.length;
/*
Check if only one measure is present and the cell is a non-empty column measure label
*/
if (measuresTotal === 1 && data.columns.length > 0 && data.type === "header" && data.label != "" && !data.measure){
cell.text += " - " + measure;
}
}