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
let pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
customizeCell: customizeCell,
report: {
dataSource: {
"type": "csv",
"filename": "https://cdn.flexmonster.com/data/happyness.csv",
mapping: {
"Score": {
type: "number"
},
"Overall rank": {
visible: false
},
"Social support": {
visible: false
},
"GDP per capita": {
visible: false
},
"Perceptions of corruption": {
visible: false
}
}
},
options: {
configuratorActive: true
},
"slice": {
"rows": [{
"uniqueName": "Region"
},
{
"uniqueName": "Country or region"
}
],
"columns": [{
"uniqueName": "[Measures]"
},
{
"uniqueName": "Year"
}
],
"measures": [{
"uniqueName": "Score",
"aggregation": "median",
"grandTotalCaption": "Average Happyness"
}]
},
"conditions": [{
"formula": "AND(#value > 7.3, #value < 10)",
"format": {
"backgroundColor": "#f0c63e",
"color": "#000000",
"fontFamily": "Arial",
"fontSize": "12px"
}
},
{
"formula": "AND(#value > 0, #value < 4.5)",
"format": {
"backgroundColor": "#f29c8d",
"color": "#000000",
"fontFamily": "Arial",
"fontSize": "12px"
}
}
],
"formats": [{
"name": "",
"decimalPlaces": 2
}],
}
});
function customizeCell(cell, data) {
if (data.isGrandTotalColumn) {
if (data.value < 5 && data.value >= 0) {
cell.text = data.value.toPrecision(3) + " ☹️";
} else if (data.value >= 5 && data.value < 7) {
cell.text = data.value.toPrecision(3) + " 🙂";
} else if (data.value >= 7 && data.value < 10)...