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="pivot-container">The component will appear here</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;
}

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  height: 300,
  //Used to show the table sizes on each change
  reportchange: () => {
    let sizes = flexmonster.getTableSizes();
    showOutput(JSON.stringify(sizes, null, 4));
  },
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    slice: {
      rows: [{
        uniqueName: "Category"
      }],
      columns: [{
          uniqueName: "Country",
          filter: {
            exclude: [
              "country.[canada]",
              "country.[united kingdom]"
            ]
          }
        },
        {
          uniqueName: "[Measures]"
        }
      ],
      measures: [{
        uniqueName: "Price",
        aggregation: "sum"
      }]
    },
  }
});

pivot.customizeContextMenu(function(items, data, viewType) {
  //Do not add new ,enu option when multiple cells are selected
  if (!Array.isArray(data))
    items.push({
      label: "Increase column width",
      handler: function() {
        //Reset sizes to make a selected column wider
        flexmonster.setTableSizes({
          columns: [{
            idx: data.columnIndex,
            width: 200
          }]
        });
      }
    });
  return items;
});


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