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>
<div id="pivot-container"></div>
<p/>
<div id="pivot-container-1"></div>
JavaScript
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 350,
toolbar: true,
report: {
dataSource: {
filename: "data/data.csv"
},
options: {
grid: {
type: "flat"
}
},
slice: {
rows: [{
uniqueName: "Color"
}, {
uniqueName: "Country"
}],
columns: [{
uniqueName: "Business Type"
}, {
uniqueName: "[Measures]"
}],
measures: [{
uniqueName: "Price"
}],
}
}
});
pivot.on('cellclick', onClick);
function onClick(e) {
var cell = pivot.getSelectedCell();
if (cell.type != "header") openNewPivot(cell);
}
var pivot1 = null;
var openNewPivot = function(cell) {
console.log(">>", cell);
var measure = cell.measure.uniqueName;
var rowTuple = [];
for (var i = 0; i < cell.rows.length; i++) {
rowTuple.push(cell.rows[i].uniqueName);
}
var columnTuple = [];
for (var i = 0; i < cell.columns.length; i++) {
columnTuple.push(cell.columns[i].uniqueName);
}
console.log(
"Click on cell: "
+ "measure: " + measure
+ ", rows: " + rowTuple.join()
+ ", column: " + columnTuple.join()
);
//the new pivot is created based on some new data in this sample
//you can use info from cell to prepare the data set for the new pivot
var report = {
dataSource: {
data: [{
"Business Type": "Value Added Reseller",
"Color": "blue",
"Price": Math.random()
}, {
"Business Type": "Specialty Bike Shop",
"Color": "green",
"Price": Math.random()
}, {
"Business Type": "Warehouse",
"Color": "purple",
"Price": Math.random()
}]
},
slice: {
rows: [{
uniqueName: "Color"
}],
columns: [{
uniqueName: "Business Type"
}, {
...