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://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

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

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  width: "100%",
  customizeContextMenu: customizeContextMenu,
  height: 430,
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    slice: {
      rows: [{
        uniqueName: "Color"
      }, {
        uniqueName: "Country"
      }],
      columns: [{
        uniqueName: "Category"
      }, {
        uniqueName: "Size"
      }, {
        uniqueName: "[Measures]"
      }],
      measures: [{
        uniqueName: "Price",
        format: "currency"
      }],
    }
  }
});

let rowsExpanded = false;
let colsExpanded = false;

function customizeContextMenu(items, data, viewType) {
  //Expand rows
  if (data.rows.length > 0 && data.columns.length === 0) {
    if (!rowsExpanded) {
      items.push({
        label: "Expand All",
        handler: () => {
          pivot.expandAllData(true, "rows");
          rowsExpanded = true;
        }
      });
    } else {
      //Get all rows
      let rows = pivot.getReport().slice.rows.map(col => {
        return col.uniqueName
      }).reverse()
      items.push({
        label: "Collapse All",
        handler: () => {
          //Collapse them one by one
          rows.forEach(row => {
            pivot.collapseData(row)
          })
          rowsExpanded = false;
        }
      });
    }
  }
  //Expand columns
  if (data.rows.length === 0 && data.columns.length > 0) {
    if (!colsExpanded) {
      items.push({
        label: "Expand All",
        handler: () => {
          pivot.expandAllData(true, "columns");
          colsExpanded = true;
        }
      });
    } else {
      //Get all columns
      let columns = pivot.getReport().slice.columns.map(column => {
        return column.uniqueName
      }).reverse()
      items.push({
        label: "Collapse All",
        handler: () => {
          //Collapse them one by one
          columns.forEach(column => {
           ...