JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
May 27, 2021
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="showTotal()">Show Grand Total For Product</button>
<button onclick="hideTotal()">Hide Grand Total For Product</button>
<div id="pivot-container"></div>
JavaScript
var pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 600,
toolbar: true,
customizeCell: customizeCellFunction,
report: {
"dataSource": {
"type": "json",
"data": getData()
},
"slice": {
"rows": [{
"uniqueName": "Category"
}],
"columns": [{
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "Price",
"aggregation": "sum"
},
{
"uniqueName": "Quantity",
"aggregation": "sum"
},
{
"uniqueName": "Product",
"formula": "sum(\"Price\") * sum(\"Quantity\")",
"caption": "Product"
}
]
}
}
});
function customizeCellFunction(cell, data) {
if (data && data.isGrandTotal && data.type == "value" && data.measure && data.measure.uniqueName == "Product") {
cell.text = "";
}
}
function showTotal() {
pivot.customizeCell(null);
}
function hideTotal() {
pivot.customizeCell(customizeCellFunction);
}
function getData() {
return [{
"Category": "Accessories",
"Size": "262 oz",
"Color": "red",
"Destination": "Australia",
"Business Type": "Specialty Bike Shop",
"Country": "Australia",
"Price": 174,
"Quantity": 225,
"Discount": 23
}, {
"Category": "Accessories",
"Size": "214 oz",
"Color": "yellow",
"Destination": "Canada",
"Business Type": "Specialty Bike Shop",
"Country": "Canada",
"Price": 502,
"Quantity": 90,
"Discount": 17
}, {
"Category": "Components",
"Size": "235 oz",
"Color": "green",
"Destination": "Australia",
"Business Type": "Warehouse",
"Country": "Australia",
"Price": 551,
"Quantity": 1950,
"Discount": 51
}, {
"Category": "Components",
"Size": "307 oz",
"Color": "white",
"Destination": "United Kingdom",
"Business Type": "Warehouse",
...