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/",
toolbar: true,
report: {
dataSource: {
data: getData(),
dataSourceType: "json"
},
slice: {
rows: [{
uniqueName: "kpitype"
},
{
uniqueName: "segment"
}
],
columns: [{
uniqueName: "timePeriod"
},
{
uniqueName: "[Measures]"
}
],
measures: [{
uniqueName: "value",
aggregation: "sum"
}],
expands: {
rows: [{
tuple: [
"kpitype.[gwp]"
]
},
{
tuple: [
"kpitype.[policy]"
]
}
]
}
},
options: {
grid: {
showGrandTotals: "off"
}
}
}
});
function applyFormat(cell, data) {
console.log(data);
if (data && data.measure && data.measure.uniqueName == "value" && data.rows && data.rows.length > 0) {
if (data.rows[0].caption == "GWP") {
cell.text += (cell.text == "")?"":" €";
}
}
}
pivot.customizeCell(applyFormat);
function getData() {
return [{
"kpitype": "GWP",
"lineOfBusiness": "Life",
"segment": "Cancellation",
"startDate": "2018-12-31T23:00:00.000Z",
"endDate": "2019-03-30T23:00:00.000Z",
"timePeriod": "Acc. 1.1 to date 2019",
"value": 239974.59000000003
},
{
"kpitype": "GWP",
"lineOfBusiness": "Life",
"segment": "Cancellation",
"startDate": "2018-12-31T23:00:00.000Z",
"endDate": "2019-03-30T23:00:00.000Z",
"timePeriod": "Acc. 1.1 to date 2018",
"value": 2399.59000000003
},
{
"kpitype": "Policy",
"lineOfBusiness": "Health",
"segment": "Replacement",
"startDate": "2017-12-31T23:00:00.000Z",
"endDate": "2018-03-30T22:00:00.000Z",
"timePeriod": "Acc. 1.1 to date 2018",
"value":...