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="validate();">
Validate
</button>
<div class="output-container" id="validation-container">Validation result will appear here</div>
<div id="pivot-container"></div>
CSS
.output-container {
border: 2px solid #df3800;
background: #fdfd96;
color: #df3800;
text-transform: uppercase;
cursor: pointer;
margin: 10px 20px 10px 0px;
display: inline-block;
transition: all 0.3s;
font-weight: normal;
padding: 10px 10px;
font-size: 14px;
min-width: 50px;
}
JavaScript
var pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 430,
toolbar: true,
report: {
dataSource: {
filename: "data/sales.csv"
},
slice: {
columns: [{
uniqueName: "Month"
}, {
uniqueName: "[Measures]"
}],
rows: [{
uniqueName: "Category",
filter: {
members: [
"category.[condiments].[bbq sauce]",
"category.[breakfast cereals].[corn flakes]",
"category.[confectionery]",
"category.[bakery].[chocolate biscuits]",
"category.[fruit preserves].[apple jam]",
"category.[bakery].[apple cake]",
"category.[soups].[tomato soup]"
]
}
}],
measures: [{
"uniqueName": "Revenue",
"aggregation": "sum",
"format": "2sfou03a"
}]
},
conditions: [{
formula: "#value < 2500",
measure: "Revenue",
format: {
backgroundColor: "#df3800",
color: "#FFFFFF"
},
isTotal: false
}, {
formula: "#value > 20000",
measure: "Revenue",
format: {
backgroundColor: "#00A45A",
color: "#FFFFFF"
},
isTotal: false
}],
formats: [{
name: "2sfou03a",
thousandsSeparator: ",",
decimalSeparator: ".",
decimalPlaces: 2,
currencySymbol: "$",
currencySymbolAlign: "left",
nullValue: "",
textAlign: "right",
isPercent: false
}]
}
});
function isAReport(jsonObject){
if(!(jsonObject.hasOwnProperty("dataSource"))){
return false;
}
return true;
}
function validate(){
//A valid report object:
var someReportObject = pivot.getReport();
//Not a report object:
var someJSONObject = {"product": "apple", "price": 456};
//Checking and showing result:
if(isAReport(someReportObject)){
...