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>

<button onclick="showTotals()">Show (sub)totals</button>

<button onclick="showGrandTotals()">Show grand totals</button>


<button onclick="showAllTotals()">Show both</button>


<button onclick="hideAllTotals()">Hide all</button>
<div id="pivot-container"></div>

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    slice: {
      rows: [{
        uniqueName: "Category",
        filter: {
          members: ["Accessories", "Cars"]
        }
      }, {
        uniqueName: "Country",
        filter: {
          members: ["Canada", "France", "Germany"]
        }
      }],
      columns: [{
        uniqueName: "Color",
        filter: {
          members: ["red"]
        }
      }],
      measures: [{
        uniqueName: "Price"
      }],
      expands: {
        rows: [{
            tuple: [
              "category.[accessories]"
            ]
          },
          {
            tuple: [
              "category.[cars]"
            ]
          }
        ]
      }
    }
  }
});

function showTotals() {
  let options = flexmonster.getOptions();
  options.grid.showTotals = "on";
  options.grid.showGrandTotals = "off";
  flexmonster.setOptions(options);
  flexmonster.refresh();
}

function showGrandTotals() {
  let options = flexmonster.getOptions();
  options.grid.showTotals = "off";
  options.grid.showGrandTotals = "on";
  flexmonster.setOptions(options);
  flexmonster.refresh();
}


function showAllTotals() {
  let options = flexmonster.getOptions();
  options.grid.showTotals = "on";
  options.grid.showGrandTotals = "on";
  flexmonster.setOptions(options);
  flexmonster.refresh();
}


function hideAllTotals() {
  let options = flexmonster.getOptions();
  options.grid.showTotals = "off";
  options.grid.showGrandTotals = "off";
  flexmonster.setOptions(options);
  flexmonster.refresh();
}