JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivot-container"></div>
JavaScript
var data = [
{
"franja_eda": "De 16 a 18 anys",
"sexe": "Dona",
"value": 30
},
{
"franja_eda": "De 19 a 24 anys",
"sexe": "Home",
"value": 30
}
];
var dictionary = {
"Dona": "% Dones",
"Home": "% Homes",
"Totals": "% Totals"
}
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
data: data
},
"slice": {
"rows": [
{
"uniqueName": "franja_eda"
}
],
"columns": [
{
"uniqueName": "sexe"
},
{
"uniqueName": "[Measures]"
}
],
"measures": [
{
"uniqueName": "value",
"aggregation": "sum"
},
{
"uniqueName": "value",
"aggregation": "percentofrow"
}
]
}
},
customizeCell: function(cell, data) {
if (data != null) {
if (data.rowIndex == 1 && data.columnIndex > 0 && data.lable != "") {
cell.text = dictionary[data.label];
}
if (data.rowIndex == 2 && data.columnIndex > 0) {
cell.text = "";
}
}
}
});