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="wrapper">
  <div id="pivotContainer"></div>
</div>

CSS

#wrapper {
  width: 500px;
  height: 700px;
  overflow: scroll;
}

JavaScript

var pivot = new Flexmonster({
  container: "pivotContainer",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  width: "100%",
  height: "100%",
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    options: {
      grid: {
        type: "classic"
      }
    }
  }
});

let container = document.getElementById("pivotContainer");
let defaultWidth = container.getBoundingClientRect().width;
let avgColWidth = 165;
let minColWidth = 500;

flexmonster.on("reportcomplete", () => {
  flexmonster.off("reportcomplete");
  flexmonster.on("update", () => {
    let resWidth = 0;
    if (flexmonster.getOptions().grid.type == "classic") {
      resWidth = (flexmonster.getRows().length + flexmonster.getMeasures().length) * avgColWidth;
      if (resWidth < minColWidth) {
        resWidth = defaultWidth;
      }
    }
    container.style.width = `${resWidth}px`;
    flexmonster.refresh();
  });

  //to restrict manual switch to compact
  flexmonster.on("reportchange", () => {
    if (flexmonster.getOptions().grid.type == "compact") {
      flexmonster.setOptions({
        grid: {
          type: "classic"
        }
      });
      flexmonster.refresh();
    }
  })
});