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="switchToFlat()">Switch to flat</button>
<button onclick="switchToCompact()">Switch to compact</button>
<div id="pivot-container"></div>

JavaScript

var pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  width: "100%",
  toolbar: true,
  height: 430,
  customizeContextMenu: customizeContextMenuFunction,
  report: {
    dataSource: {
      filename: 'data/retail-data.json'
    }
  }
});

pivot.on('fieldslistopen', function() {
  if (pivot.getOptions().grid.type == 'flat') {
    let aggregations = document.querySelectorAll(".fm-aggr-display");
    for (let aggregation of aggregations) {
      aggregation.remove()
    }
  }
});

function customizeContextMenuFunction(items, data, viewType) {
  if (viewType == "flat") {
    return items.filter(item => item.id !== "aggregation");
  }
}


function switchToFlat() {
  let options = pivot.getOptions();
  options.grid.type = "flat";
  pivot.setOptions(options);
  pivot.refresh();
}

function switchToCompact() {
  let options = pivot.getOptions();
  options.grid.type = "compact";
  pivot.setOptions(options);
  pivot.refresh();
}