How to use updateData for adding/updating/removing partial data
Data source
by ilaria_nunziante
HTML
<link rel="stylesheet" href="https://cdn.flexmonster.com/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<button id="btn" onclick="updateRecord()">Update</button>
<button id="btn" onclick="deleteRecord()">Delete</button>
<div id="pivot-container"></div>
JavaScript
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 430,
report: {
"dataSource": {
"type": "json",
"data": [{
"DeleteRow": false,
"RowId": "1",
"Product": "Cake",
"Qty": 10,
"Price": 10,
"Week": 37
},
{
"DeleteRow": false,
"RowId": "2",
"Product": "Cake",
"Qty": 10,
"Price": 10,
"Week": 36
}
],
"mapping": {
"Product": {
"type": "string"
},
"Qty": {
"type": "number"
},
"Price": {
"type": "number"
},
"Week": {
"type": "string"
},
"DeleteRow": {
"type": "delete"
},
"RowId": {
"type": "id"
}
}
},
"slice": {
"rows": [{
"uniqueName": "Product"
}],
"columns": [{
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "Qty",
"aggregation": "sum"
},
{
"uniqueName": "Price",
"aggregation": "sum"
}
]
}
}
});
function update(dataForUpdate) {
flexmonster.updateData({
data: dataForUpdate
}, {
partial: true
});
}
function updateRecord() {
var dataForUpdate = [{
"RowId": "1",
"Product": "Cake",
"Qty": 10,
"Price": 10,
"Week": 37
}
]
this.update(dataForUpdate);
}
function deleteRecord() {
var dataForUpdate = [{
"RowId": "1",
"Product": "Cake",
"Qty": 10,
"Price": 10,
"Week": 37,
"DeleteRow": true
}
]
this.update(dataForUpdate);
}