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/flexmonster.js"></script>
<button onclick="addRecord()">Update data: add one record</button>
<button onclick="editRecords()">Update data: edit two records</button>
<div id="pivot-container"></div>
CSS
.updated {
animation: BLINK 1s infinite;
}
@-webkit-keyframes BLINK {
0%,
49% {
background-color: yellow;
}
50%,
100% {
background-color: none;
}
}
JavaScript
let pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
report: {
dataSource: {
data: getData(),
mapping: {
"Category": {
"type": "string"
},
"Price": {
"type": "number"
},
"Country": {
"type": "string"
},
"RowId": {
"type": "id"
},
"DeleteRow": {
"type": "delete"
}
}
},
"slice": {
"rows": [{
"uniqueName": "Category"
}],
"columns": [{
"uniqueName": "Country"
},
{
"uniqueName": "[Measures]"
}
],
"measures": [{
"uniqueName": "Price"
}]
}
}
});
function adjustStyling(dataForUpdate) {
let updatedId = dataForUpdate.reduce((accum, record) => {
accum.push(record.RowId);
return accum;
}, []);
flexmonster.customizeCell((cell, data) => {
if (data.type != "value" || !data.recordId) return;
if (!data.recordId.some((id) => {
return updatedId.includes(id);
})) return;
cell.addClass("updated");
});
}
function addRecord() {
const dataForUpdate = [{
"Category": "Cars",
"Country": "Spain",
"Price": 51844,
"RowId": 7
}]
flexmonster.updateData({
data: dataForUpdate
}, {
partial: true
});
adjustStyling(dataForUpdate);
}
function editRecords() {
const dataForUpdate = [{
"Category": "Accessories",
"Country": "USA",
"Price": 400,
"RowId": 1
},
{
"Category": "Bikes",
"Country": "UK",
"Price": 3000,
"RowId": 2
}
]
flexmonster.updateData({
data: dataForUpdate
}, {
partial: true
});
adjustStyling(dataForUpdate);
}
function getData() {
return [{
"Category": "Accessories",
"Country": "USA",
"Price": 242,
"RowId": 1
},
{
"Category": "Bikes",
"Country": "UK",
"Price":...