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>

<p>Click the <b>Get Members</b> button to output members of the <code>Geography</code> field under the component using the <a href="https://www.flexmonster.com/api/getmembers/" target="_blank">getMembers</a> method.</p>

<button onclick="getMembers()">Get Members</button>

<button onclick="getReport()">Get Report</button>

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

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

CSS

.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;
}

code {
    font-size: 105%;
    color: #DF3800;
    background-color: #f5f5f5;
    padding: 1px 4px;
    font-family: monospace !important;
    border-radius: 4px;
}

p {
  font-size: 15px;
  line-height: 1.5;
  padding-right: 10px;
  padding-left: 10px;
}

a {
  color: #00a45a;
  text-decoration: none;
}

button {
  margin-left: 10px;
}

#pivot-container {
  margin-top: 10px;
}

JavaScript

let pivot = new Flexmonster({
  container: "#pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/sales_data_without_types.csv",
      mapping: {
        "Region": {
          hierarchy: "Geography"
        },
        "State": {
          parent: "Region",
          hierarchy: "Geography"
        },
        "City": {
          parent: "State",
          hierarchy: "Geography"
        }
      }
    },
    slice: {
      rows: [{
        uniqueName: "Geography",
      }],
      columns: [{
          uniqueName: "Category"
        },
        {
          uniqueName: "[Measures]"
        }
      ],
      measures: [{
        uniqueName: "Revenue",
        aggregation: "sum"
      }],
      drills: {
        rows: [{
          tuple: ['geography.[midwest]']
        }]
      }
    }
  }
});

function getMembers() {
  let members = flexmonster.getMembers("Geography");
  showOutput(JSON.stringify(members, null, 2));
}

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

function getReport() {
  let report = pivot.getReport();
  showOutput(JSON.stringify(report, null, 4));
}

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