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>

<div id="pivotContainer"></div>

<div class="output" id="output">Output will appear here</div>

CSS

#pivotContainer .fm-drillthrough-view {
  display: none !important;
}

.output {
  width: 80%;
  height: 300px;
  margin-left: auto;
  margin-right: auto;
  padding: 20px;
  background: rgba(242, 242, 242, 1);
  font-family: Menlo, Monaco, "Courier New", Courier, monospace;
  white-space: pre;
  font-size: 16px;
  font-weight: 400;
  overflow-y: scroll;
  margin-top: 20px;
}

JavaScript

let endpointUrl = "https://olap.flexmonster.com:9500/";
let index = "fm-product-sales";
let cache = {};

function pivotEndpoint(requestStringified, done) {
  let request = JSON.parse(requestStringified);
  const start = new Date();
  $.ajax({
    type: "POST",
    url: endpointUrl + request.type,
    data: requestStringified,
    success: response => {
    	const time = new Date() - start;
      showOutput(`${time}ms\n` + JSON.stringify(response, null, 4));
      done(response);
    },
    dataType: "json",
    contentType: "application/json"
  });
}

let pivot = new Flexmonster({
  container: "pivotContainer",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    "dataSource": {
      "type": "api",
      "url": pivotEndpoint,
      "index": index
    },
    "slice": {
      "rows": [{
        "uniqueName": "Country"
      }],
      "columns": [{
        "uniqueName": "[Measures]"
      }],
      "measures": [{
        "uniqueName": "Price",
        "aggregation": "sum"
      }]
    }
  }
});

function showOutput(content) {
  document.getElementById("output").innerText = content;
}