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>
<link rel="stylesheet" href="https://cdn.flexmonster.com/flexmonster.min.css">
<div id="shadow-host"></div>

JavaScript

const shadowHost = document.getElementById('shadow-host');
const shadowRoot = shadowHost.attachShadow({ mode: 'open' });
const shadowContent = document.createElement('div');
shadowContent.innerHTML = `
  <link rel="stylesheet" href="https://cdn.flexmonster.com/flexmonster.min.css">
  <div id="pivot-container"></div>
`;
shadowRoot.appendChild(shadowContent);

const pivotContainer = shadowRoot.getElementById('pivot-container');

let pivot = new Flexmonster({
  container: pivotContainer,
  componentFolder: "https://cdn.flexmonster.com/",
   toolbar: true,
  report: {
    dataSource: {
      "filename": "data/data.csv"
    },
    slice: {

      "rows": [{
          "uniqueName": "Category"
        },
        {
          "uniqueName": "Country"
        },
        {
          "uniqueName": "Destination"
        }
      ],
      "columns": [{
          "uniqueName": "Color"
        },
        {
          "uniqueName": "[Measures]"
        }
      ],
      "measures": [{
        "uniqueName": "Price",
        "aggregation": "sum"
      }]
    }
  },
  beforetoolbarcreated: customizeToolbar
});

function customizeToolbar(toolbar) {
  let tabs = toolbar.getTabs();
  toolbar.getTabs = function() {
    let exportTab = tabs.find(tab => tab.id == "fm-tab-export");
    if (!exportTab) return tabs;
    let exportToPdfTab = exportTab.menu.find(tab => tab.id == "fm-tab-export-excel");
    exportToPdfTab.handler = () => {
      exportToExcel();
    }
    return tabs;
  }
}

function exportToExcel() {

  const reportCopy = pivot.getReport()
  pivot.on("aftergriddraw", () => {
    pivot.off("aftergriddraw");
    pivot.exportTo('excel', null, () => {
      pivot.setReport(reportCopy)
    });
  });
  pivot.expandAllData();
}