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": "1150499",
"Qty": 10,
"Price": 10,
"Week": 37
},
{
"DeleteRow": false,
"RowId": "2",
"Product": "1150499",
"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": {
"reportFilters": [{
"uniqueName": "Week",
"sort": "unsorted"
}],
"rows": [{
"uniqueName": "Product",
"sort": "unsorted"
}],
"columns": [{
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "Qty",
"aggregation": "sum"
},
{
"uniqueName": "Price",
"aggregation": "sum"
}
]
}
}
});
function update(dataForUpdate) {
flexmonster.updateData({
data: dataForUpdate
}, {
partial: true
});
}
//ho dovuto eliminare il field DeleteRow=false altrimenti si rompe l'update
function updateRecord() {
var dataForUpdate = [{
"RowId": "1",
"Product": "1150499",
"Qty": 10,
"Price": 10,
"Week": 37
},
{
"RowId": "2",
"Product": "1150499",
"Qty": 10,
"Price": 10,
"Week": 36
},
{
"RowId": "700652_36_2509_DG_4_1",
"Product": "1150499",
"Price": 80,
"Week": 36
},
{
...