JSFiddle - React, Tailwind, and code Playground
Events
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">The component will appear here</div>
JavaScript
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
height: 550,
report: {
dataSource: {
data: getData(),
mapping: {
Color: {
type: "string",
},
Country: {
type: "string",
},
RowId: {
type: "id",
},
Price: {
type: "number",
},
},
},
options: {
grid: {
type: "flat",
showGrandTotals: false,
},
editing: true,
},
},
})
pivot.on("datachanged", function (e) {
console.log("datachanged", e)
const target = e.data[0];
//Step 1: update data in the dataset
let data = getData();
data.map(row => {
if (row[target.field] == target.oldValue)
row[target.field] = target.value
})
console.log(data);
//Step 2: refresh data
pivot.updateData({
type: "json",
data: data,
partial: true
})
//Step 3: save the report
pivot.save();
})
function getData() {
return [
{
Color: "green",
Country: "USA",
RowId: 1,
Price: 174,
},
{
Color: "red",
Country: "Canada",
RowId: 2,
Price: 30,
},
{
Color: "blue",
Country: "France",
RowId: 3,
Price: 283,
},
{
Color: "purple",
Country: "Germany",
RowId: 4,
Price: 371,
},
]
}