on 10-09-2014 12:34 PM
Hi Guys,
sorry to bother you again, but developing SAP Fiori like Uis is really hard for me. Right now I can't get the Data from an oData Service into a simple sap.m.Table. This is how the oData Object that I get from the Service looks like:
As you can see, I have two Objects in the results Array. Each object contains Strings which I want to display in a sap.m.Table. This is my JS code for the table:
initBHeftModel : function(context) {
// Using OData model to connect against a real service
var VersBP = context.getObject().bp;
var url = "proxy/http/crs.rz.sys.aok.de:8841/sap/opu/odata/sap/ZCM22_SERVICES_SRV_01/";
var oModel = new sap.ui.model.odata.ODataModel(url, false);
var filterArray = new Array();
var BPFilter = new sap.ui.model.Filter("Bpartner", sap.ui.model.FilterOperator.EQ, VersBP);
filterArray.push(BPFilter);
var params = {
context : null,
urlParameters : null,
async : false,
filters : filterArray,
sorters : null,
success : function(oData, response) {
var JSONBHeft = new sap.ui.model.json.JSONModel();
console.log(oData);
JSONBHeft.setData(oData);
sap.ui.getCore().setModel(JSONBHeft, "VersBHeft");
var bhtable = sap.ui.getCore().byId("bheftPageId").byId("BHeftTable");
var oTemplate = new sap.m.ColumnListItem(
{cells: [
new sap.m.Text({text : "{Guid}"}),
new sap.m.Text({text : "{Kjahr}"}),
new sap.m.Text({text : "{Hjahr}"})
]
});
bhtable.bindItems("/VersBHeft/oData/results", oTemplate);
// bhtable.bindAggregation("items", "/VersBHeft/oData/results", oTemplate);
console.log(sap.ui.getCore().byId("bheftPageId").byId("BHeftTable").getBindingContext("VersBHeft"));
},
error : function(err) {
}
};
oModel.read("BonuseintragSet", params);
}
}
This might show all the stuff that I tried to get the data into the table. The function gets called, when someone selects a field in the Master view. The table in the Detail view only shows No Data.....and it did this for hours.....
I read a lot other discussions about similar problems, but I have the problem, that I cannot transfer those solutions to my oData Structure. I guess that I am not addressing the data in the right way.
I am looking forward hearing from you
Finally....
We figured out, that the the data the comes back after performing the read Method is not an oData Model. Thus we constructed a new JSON model with the respone-data. After this model was binded to the table, the data was displayed correctly. Here is the code:
initBHeftModel : function(context) {
var VersBP = context.getObject().bp;
var url = "proxy/http/crs.rz.sys.aok.de:8841/sap/opu/odata/sap/ZCM22_SERVICES_SRV_01/";
var oModel = new sap.ui.model.odata.ODataModel(url);
var filterArray = new Array();
var BPFilter = new sap.ui.model.Filter("Bpartner", sap.ui.model.FilterOperator.EQ, VersBP);
filterArray.push(BPFilter);
var params = {
context : null,
urlParameters : null,
async : false,
filters : filterArray,
sorters : null,
success : function(oData, response) {
var json = new sap.ui.model.json.JSONModel(oData);
var oTemplate = new sap.m.ColumnListItem(
{cells: [
new sap.m.Text({text : "{Guid}"}),
new sap.m.Text({text : "{Kjahr}"}),
new sap.m.Text({text : "{Hjahr}"})
]
});
var table = sap.ui.getCore().byId("bheftPageId").byId("BHeftTable");
table.setModel(json);
table.bindAggregation("items", { path: "/results", template : oTemplate});
},
error : function(err) {
}
};
oModel.read("BonuseintragSet", params);
}
Thanks to everybody who contributed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nils,
I got the solution from you answer only. But i have one doubt why the path is path: "/results"???
THanks
Nishant
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nishant,
I can only guess but I think it is because you use the read method for reading sets of entities and single entities. If you read a single entity, the data is stored in the oData object and if you read a set the data is stored in the results property of that object.
Maybe it is done this way to be a little bit generic.
Looking at your Code,
It seems you are missed to set the model to table instance which has the runtime data.
bhtable.setModel(<your Model instance>);
bhtable.bindAggregation("items", "<your data path>", oTemplate);
Regards,
Meganadhan S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Meganadhan,
you are right, I missed that step. After I added the model to the table (the method needed a name for the model, otherwise it would give me an "undefined is not a function error") I can now see, that the table knows the model.
bhtable.setModel(oData,"test");
I tried several different data paths, but none of them worked.....
I am able to bind and see the data using below code
var url = "/sap/opu/odata/sap/YMEDEMO_SRV/Vendor_open_itemSet";
var oJsonModel = new sap.ui.model.json.JSONModel();
oJsonModel.loadData(url, null, false);
oTable.setModel(oJsonModel);
oTable.bindAggregation("items", {
path: "/d/results", <<<Your data path at runtime
template: oTemplate
});
Where:
oTable is instance of my sap.m.table
oTemplate is instance of my template
Hope this will be useful!
Regards,
Meganadhan S
Hi,
I already tried that path but it still shows me "No Data".
I can just guess that there is something wrong with the model or with the table.....
Does anybody know a Sample implementation of an oData Service, where someone performs a read with a $filter and binds that data to a table?
Thanks and regards,
Nils
Hi,
Instead of
bhtable.bindItems("/VersBHeft/oData/results", oTemplate);
Use,
bhtable.bindItems("/BonuseintragSet", oTemplate);
Regards,
Chandra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.