JSFiddle - React, Tailwind, and code Playground

Demos

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"></div>

CSS

.fm-custom-cell {
  display: flex !important;
  align-items: center !important;
  font-size: 12px !important;
}

.fm-custom-cell .flag-icon {
  width: 21px !important;
  height: 16px !important;
  margin-left: 0 !important;
  margin-right: 2px !important;
}

#fm-pivot-view .fm-grid-layout .fm-custom-cell.fm-expanded .fm-expanded-icon::before, 
#fm-pivot-view .fm-grid-layout .fm-custom-cell.fm-collapsed .fm-collapsed-icon::before {
  top: -2px;
  height: 16px;
}

JavaScript

const pivot = new Flexmonster({
  container: "#pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  height: 550,
  toolbar: true,
  report: {
    dataSource: {
      type: "json",
      filename: "data/retail-data.json",
      mapping: {
        "Order Date": {
          type: "year/quarter/month/day",
        },
      },
    },
    slice: {
      rows: [
        {
          uniqueName: "Country",
          filter: {
            members: [
              "country.[australia]",
              "country.[usa]",
              "country.[japan]",
              "country.[canada]",
            ],
          },
        },
      ],
      columns: [
        {
          uniqueName: "Order Date",
        },
        {
          uniqueName: "[Measures]",
        },
      ],
      measures: [
        {
          uniqueName: "Price",
          aggregation: "sum",
          format: "currency",
        },
      ],
      sorting: {
        column: {
          type: "desc",
          tuple: [],
          measure: {
            uniqueName: "Price",
            aggregation: "sum",
          },
        },
      },
    },
    formats: [
      {
        name: "",
        thousandsSeparator: ",",
        decimalSeparator: ".",
        decimalPlaces: 2,
        nullValue: "-",
      },
      {
        name: "currency",
        currencySymbol: "$",
      },
    ],
  },
})

let lastFilteredField

pivot.on("filteropen", function (params) {
  lastFilteredField = null
  let applyFilterButton = document.querySelector("#pivot-container #fm-pivot-view .fm-filter-view button.fm-ui-btn-dark")
  if (applyFilterButton) {
    applyFilterButton.addEventListener("click", ()=>{ lastFilteredField = params.hierarchy.uniqueName },true,);
  }
})

pivot.on("filterclose", function () {
  if (lastFilteredField) {
    const sort = pivot.getSort(lastFilteredField)
    if (sort !== "unsorted") {
      pivot.sortValues("columns", "unsorted")
      pivot.sortValues("rows", "unsorted")
    }
  }
})