JSFiddle - React, Tailwind, and code Playground
Configuring the report
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="setReport()">Set Report</button>
<div id="pivot-container">The component will appear here</div>
JavaScript
let pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
data: getData(),
},
slice: {
rows: [
{
uniqueName: "Color",
},
],
columns: [
{
uniqueName: "Country",
},
{
uniqueName: "[Measures]",
},
],
measures: [
{
uniqueName: "Price",
aggregation: "sum",
},
{
uniqueName: "Quantity",
aggregation: "sum",
},
],
},
formats: [
{
name: "",
thousandsSeparator: ",",
decimalSeparator: ".",
decimalPlaces: 2,
nullValue: "-",
currencySymbol: "$",
},
],
},
})
function setReport() {
let report = pivot.getReport()
report.dataSource = {
data: getData(),
}
pivot.setReport(report)
}
function getData() {
return [
{
Color: "green",
Country: "Canada",
State: "Ontario",
City: "Toronto",
Price: Math.floor(Math.random() * 100) + 1,
Quantity: Math.floor(Math.random() * 100) + 1,
},
{
Color: "red",
Country: "USA",
State: "California",
City: "Los Angeles",
Price: Math.floor(Math.random() * 100) + 1,
Quantity: Math.floor(Math.random() * 100) + 1,
},
{
Color: "blue",
Country: "USA",
State: "Florida",
City: "Tallahassee",
Price: Math.floor(Math.random() * 100) + 1,
Quantity: Math.floor(Math.random() * 100) + 1,
},
{
Color: "black",
Country: "Canada",
State: "Quebec",
City: "Montreal",
Price: Math.floor(Math.random() * 100) + 1,
Quantity: Math.floor(Math.random() * 100) + 1,
},
]
}