JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
HTML
<link rel="stylesheet" href="https://cdn.flexmonster.com/2.3/demo.css">
<script src="https://cdn.flexmonster.com/2.9.66/flexmonster.js"></script>
<button onclick="updateData()">Update 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
const pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/2.9.66/",
licenseFilePath: "https://cdn.flexmonster.com/jsfiddle.charts.key",
width: "100%",
height: 300,
report: {
dataSource: {
data: getData(),
mapping: {
"Category": {
type: "string"
},
"Bucket": {
type: "string"
},
"Price": {
type: "number"
},
"RowId": {
type: "id"
}
}
},
slice: {
rows: [{
uniqueName: "Category"
},
{
uniqueName: "[Measures]"
}
],
columns: [{
uniqueName: "Bucket"
}],
measures: [{
uniqueName: "Price",
}]
}
}
});
function updateData() {
const dataForUpdate = [{
"Category": "Accessories",
"Bucket": "M1",
"Price": 400,
"RowId": 1
}];
flexmonster.updateData({
data: dataForUpdate
}, {
partial: true
});
}
function getData() {
let data = [];
for (let i = 10; i < 50; i++) {
data.push({
"Category": "Accessories",
"Price": 242.356356353573574646464,
"Bucket": "M" + i,
"RowId": i
});
}
return data;
}