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="pivotContainer"></div>
CSS
.green {
background: #90ee90;
}
JavaScript
let pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
dataSourceType: "csv",
data: getData()
},
"slice": {
"rows": [{
"uniqueName": "Item"
}],
"measures": [{
"uniqueName": "Discount",
"format": "percentage"
}]
},
formats: [{
name: "percentage",
decimalPlaces: 2,
currencySymbol: "%",
isPercent: true
}],
options: {
grid: {
type: "flat",
showGrandTotals: "off"
}
}
}
});
flexmonster.customizeCell((cell, data) => {
if (
data &&
data.hierarchy &&
data.hierarchy.uniqueName == "Discount" &&
data.type == "value"
) {
cell.text = `
<div class="green" style="width:${
data.value && data.value > 100 ? "100%" : cell.text
}">${data.label}</div>
`;
}
});
function getData() {
return [{
Item: "Item 1",
Discount: 32
}, {
Item: "Item 2",
Discount: 60
}, {
Item: "Item 3",
Discount: 15
}, {
Item: "Item 4",
Discount: 45
}]
}