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="updateWithData()">
Update data(with data)
</button>
<button onclick="updateEmptyData()">
Update data(no data)
</button>
<div id="pivot-container"></div>

CSS

h2 {
  text-align: center;
}

p {
  font-size: 15px;
  line-height: 1.5;
  padding-right: 10px;
  padding-left: 10px;
}

a {
  color: #00a45a;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
    font-size: 105%;
    color: #DF3800;
    background-color: #f5f5f5;
    padding: 1px 4px;
    font-family: monospace !important;
    border-radius: 4px;
}

JavaScript

pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  report: {
    dataSource: {
      data: [{
          "Color": "green",
          "Country": "Canada",
          "Price": 174
        },
        {
          "Color": "red",
          "Country": "USA",
          "Price": 166
        }
      ],
      mapping: {
        "Color": {
          type: "string"
        },
        "Country": {
          type: "string"
        },
        "Price": {
          type: "number"
        }
      }
    },
    slice: {
      rows: [{
        uniqueName: "Country"
      }],
      columns: [{
          uniqueName: "Color"
        },
        {
          uniqueName: "[Measures]"
        }
      ],
      measures: [{
        uniqueName: "Price"
      }]
    }
  }
});

function updateWithData() {
  pivot.updateData({
    data: [{
        "Color": "blue",
        "Country": "USA",
        "Price": Math.ceil(Math.random()*100)
      },
      {
        "Color": "black",
        "Country": "Canada",
        "Price": Math.ceil(Math.random()*100)
      }
    ]
  });
  console.log("Data slice", pivot.getReport().slice);
}


function updateEmptyData() {
  pivot.updateData({
    data: []
  })
  console.log("No data slice", pivot.getReport().slice);
}