JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
July 17, 2024
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="toggleGridFormat(true)">
FORMAT ALL
</button>
<button onclick="toggleGridFormat(false)">
FORMAT GRAND TOTALS ONLY
</button>
<div id="pivot-container"></div>
JavaScript
let pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
height: 550,
toolbar: true,
report: {
dataSource: {
type: "json",
filename: "data/retail-data.json",
},
options: {
grid: {
type: "classic"
}
},
slice: {
rows: [{
uniqueName: "Country",
}, {
uniqueName: "City"
}],
columns: [{
uniqueName: "Status",
},
{
uniqueName: "[Measures]",
},
],
measures: [{
uniqueName: "Price",
aggregation: "sum",
format: "currency",
}, ],
},
conditions: [{
formula: "#value > 15000",
measure: "Price",
aggregation: "sum",
format: {
backgroundColor: "#00A45A",
color: "#FFFFFF"
},
}],
formats: [
{
name: "currency",
currencySymbol: "$"
}
]
},
customizeCell: customizeCell,
});
function toggleGridFormat(formatAll) {
if (formatAll) {
pivot.customizeCell(() => {})
} else {
pivot.customizeCell(customizeCell)
}
}
function customizeCell(cell, data) {
if (!data.isGrandTotal) {
cell.style["background-color"] = "#fff"
cell.style["color"] = "#000"
}
}