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
var pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
report: {
dataSource: {
dataSourceType: "json",
data: getData()
},
"slice": {
"rows": [{
"uniqueName": "Resource Name"
}, {
"uniqueName": "TaskType"
}],
"columns": [{
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "WorkHours",
"aggregation": "sum"
}, {
"uniqueName": "On-Project Hours",
"formula": "If(Or( max(\"TaskType\") = 0, max(\"TaskType\") = 1), sum(\"WorkHours\"),0)",
"caption": "On-Project Hours",
"individual": true
}]
}
},
customizeCell: function(cell, data) {
if (data && data.hierarchy && data.hierarchy.uniqueName === "TaskType") {
if (data.label === "0") {
cell.text = "Work"
} else if (data.label === "1") {
cell.text = "Monitor"
} else if (data.label === "2") {
cell.text = "Meeting"
} else if (data.label === "3") {
cell.text = "Time-Off"
}
}
},
toolbar: true,
width: "100%",
height: 600
});
// Work - 0, Monitor - 1, Meeting - 2, TIme-Off - 3
function getData() {
return [{
"Resource Name": "Resource 1",
"TaskType": 0,
"WorkHours": 8
},
{
"Resource Name": "Resource 2",
"TaskType": 1,
"WorkHours": 3
},
{
"Resource Name": "Resource 3",
"TaskType": 3,
"WorkHours": 2
},
{
"Resource Name": "Resource 4",
"TaskType": 2,
"WorkHours": 3
},
{
"Resource Name": "Resource 5",
"TaskType": 0,
"WorkHours": 3
},
{
"Resource Name": "Resource 6",
"TaskType": 3,
"WorkHours": 2
},
{
"Resource Name": "Resource 7",
"TaskType": 1,
"WorkHours": 8
},
{
"Resource Name": "Resource 8",
"TaskType": 2,
"WorkHours": 6
},
{
...