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="updateAllCaptions()">
  Update All Field Captions
</button>
<div id="pivot-container"></div>

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      mapping: {
        "Color": {
          caption: "color"
        },
        "Country": {
          caption: "MyCountry",
          folder: "Place"
        },
        "State": {
          caption: "MyState",
          folder: "Place"
        },
        "City": {
          caption: "MyCity",
          folder: "Place"
        },
        "Price": {
          type: "number",
          caption: "MyPrice"
        },
        "Quantity": {
          type: "number",
          caption: "MyQuantity"
        }
      },
      data: getData()
    },
    options: {
      configuratorActive: true
    },
    slice: {
      rows: [{
        "uniqueName": "City"
      }],
      columns: [{
        "uniqueName": "[Measures]"
      }],
      measures: [{
          "uniqueName": "Price",
          "aggregation": "sum"
        },
        {
          "uniqueName": "Quantity",
          "aggregation": "sum"
        }
      ]
    }
  }
});

function updateAllCaptions() {
  let report = pivot.getReport();

  // Provide the new field captions via a new mapping object:
  let newMapping = {
    "Color": {
      caption: "Color Identifier"
    },
    "Country": {
      caption: "Order Country",
      folder: "Order Location"
    },
    "State": {
      caption: "Order State",
      folder: "Order Location"
    },
    "City": {
      caption: "Order City",
      folder: "Order Location"
    },
    "Price": {
      type: "number",
      caption: "Price"
    },
    "Quantity": {
      type: "number",
      caption: "Quantity"
    }
  };

  // Update the mapping object:
  report.dataSource.mapping = newMapping;

  // Apply the changes in Flexmonster:
  pivot.setReport(report);
}

function getData() {
  return [{
      "Color": "green",
      "Country": "Canada",
      "State": "Ontario",
      "City": "Toronto",
      "Price": 174,
   ...