JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
August 08, 2019
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="row-data" class="info">
Click on a cell containing data and row data will appear here
</div>
<div id="flat-pivot-container">The component will appear here</div>
CSS
.info {
width: 100%;
text-align: center;
padding: 20px;
background: #fdfd96;
}
JavaScript
var pivot = new Flexmonster({
container: "flat-pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
report: {
dataSource: {
data: getData()
},
options: {
grid: {
type: "flat"
}
}
},
width: 900
});
pivot.on('cellclick', function(cell) {
var rowData = findElement(cell.recordId);
document.getElementById("row-data").innerText = JSON.stringify(rowData);
});
function findElement(keyValue) {
var data = getData();
for(var i = 1; i<data.length; i++){
if ((data[i]).id === keyValue) {
return data[i];
}
}
}
function getData() {
return [{
"id": {
type: "id"
},
"Color": {
type: "string"
},
"M": {
type: "string"
},
"W": {
type: "string"
},
"Country": {
type: "string"
},
"State": {
type: "string"
},
"City": {
type: "string"
},
"Price": {
type: "number"
},
"Quantity": {
type: "number"
}
},
{
"id": 1,
"Color": "green",
"M": "September",
"W": "Wed",
"Country": "Canada",
"State": "Ontario",
"City": "Toronto",
"Price": 174,
"Quantity": 22
},
{
"id": 2,
"Color": "red",
"M": "March",
"W": "Mon",
"Time": "1000",
"Country": "USA",
"State": "California",
"City": "Los Angeles",
"Price": 1664,
"Quantity": 19
},
{
"id": 3,
"Color": "red",
"M": "January",
"W": "Mon",
"Country": "Canada",
"State": "Quebec",
"City": "Montreal",
"Price": 1190,
"Quantity": 292
},
{
"id": 4,
"Color": "green",
"M": "August",
"W": "Fri",
"Time": "1000",
"Country": "USA",
"State": "California",
"City": "Los Angeles",
"Price": 1222,
"Quantity": 730
},
{
"id": 5,
"Color":...