Reputation: 3
I have a requirement from where I am modifying The model data and keeping in controller variable in JSON format . Now i need to bind that in Table . Could you please help me .
I have searched everywhere . I didn't get the exact answer.
for (var i = 0; i < agrdata.length; i++) {
if (agrdata[i].vendno === this.selectedven) {
//var array = {"vendno": agrdata[i].vendno};
var percent = agrdata[i].revenue / 999 * 100;
This.FilterAgr.push({
vendno: agrdata[i].vendno,
agrno: agrdata[i].agrno,
revenue: agrdata[i].revenue,
percent: percent.toFixed(2)
});
}
}
I want to display FilterAGr in My VIew Table . How to bind this.
Upvotes: 0
Views: 227
Reputation: 3765
Create your JSON model in manifest:
"models": {
"jsonModel": {
"type": "sap.ui.model.json.JSONModel"
}
},
Put data in your JSON model in your controller:
var oLocalModel = this.getModel("jsonModel");
var aFilterAgr = [];
for (var i = 0; i < agrdata.length; i++) {
if (agrdata[i].vendno === this.selectedven) {
var percent = agrdata[i].revenue / 999 * 100;
aFilterAgr.push({
vendno: agrdata[i].vendno,
agrno: agrdata[i].agrno,
revenue: agrdata[i].revenue,
percent: percent.toFixed(2)
});
}
}
oLocalModel.setProperty("/TableData", aFilterAgr); //Put table data in your JSON model
Bind JSON model to your table in your XML view:
<Table items="{jsonModel>/TableData}">
More information about JSON models
Upvotes: 2