JSFiddle - React, Tailwind, and code Playground

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div>
	<button onclick="refreshCustomData()">Refresh Custom DataSource</button>
</div>

<div id="pivotContainer"></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);
  let drillThrough =
    request.type == "select" && request.query.aggs === undefined;
  if (drillThrough)
    done({
      fields: [],
      hits: [],
    });
  $.ajax({
    type: "POST",
    url: endpointUrl + request.type,
    data: requestStringified,
    success: (response) => {
      if (!drillThrough) {
        done(response);
      } else {
        showOutput(JSON.stringify(response, null, 4));
        alert("Custom pop-up based on the received information");
      }
    },
    dataType: "json",
    contentType: "application/json",
  });
}

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

flexmonster.on("reportcomplete", () => {
  flexmonster.off("reportcomplete");
  console.log("first data refresh");
  pivot.updateData({
    type: "api",
    url: pivotEndpoint,
    index: index,
    concurrentRequests: true,
  });
});

function refreshCustomData() {
  console.log("pivot.updateData");

  pivot.updateData(
    {
      type: "api",
      url: pivotEndpoint,
      index: index,
      concurrentRequests: true,
    },
    {
      ignoreScroll: false,
    },
  );
}