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>
<button onclick="applyFormatting()">Apply Negative Number formatting</button>
<button onclick="disableFormatting()">Disable Negative Number formatting</button>
<div id="pivot-container"></div>
JavaScript
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 430,
toolbar: true,
report: {
dataSource: {
dataSourceType: "json",
data: getData()
},
slice: {
rows: [{
uniqueName: "date"
}],
columns: [{
uniqueName: "[Measures]"
}],
measures: [{
uniqueName: "n"
}],
}
}
});
function applyFormatting(){
pivot.customizeCell(customizeNegativeNumbers);
}
function customizeNegativeNumbers(cell, data) {
if (data && data.type == "value" && data.measure && data.measure.uniqueName == "value") {
var number = parseInt(cell.text);
cell.text = (number<0)?"("+number*(-1)+")":cell.text;
}
}
function disableFormatting(){
pivot.customizeCell(null);
}
function getData() {
return [
{
"value": 10,
"field": "field1"
},
{
"value": -20,
"field": "field2"
},
{
"value": 1,
"field": "field3"
}
];
}