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="changeReport()">Change report</button>

<div id="pivot-container"></div>

JavaScript

const pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.csv"
    }
  }
});

flexmonster.on("reportcomplete", function() {
  const formats = [{
      name: "dollar",
      currencySymbol: "$",
      positiveNumberFormat: "$1"
    },
    {
      name: "round2",
      decimalPlaces: 2
    }
  ]
  for (let i = 0; i < 2; i++)
    flexmonster.setFormat(formats[i])
})

function changeReport() {
  const slice = {
    rows: [{
      uniqueName: "Country"
    }],
    columns: [{
      uniqueName: "Color"
    }],
    measures: [{
        uniqueName: "Price",
        aggregation: "sum",
        format:"dollar"
      },
      {
        uniqueName: "Quantity",
        aggregation: "average",
        format:"round2"
      },
    ]
  };
  flexmonster.runQuery(slice);


 
}