on 08-14-2015 1:47 PM
Hi
I am trying to read north wind odata model as below.
var oModel = new sap.ui.model.json.JSONModel("http://services.odata.org/V3/Northwind/Northwind.svc/Products?$format=json");
sap.ui.getCore().setModel(oModel,"northwind");
and I am able to set the values to my table with the below code.
var oTable = new sap.ui.table.Table("tableId",{
visibleRowCount: 5,
editable: false
});
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "ProductID"}),
visible: true,
template: new sap.ui.commons.TextView({text: "{northwind>ProductID}"})
}));
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Product Name"}),
visible: true,
template: new sap.ui.commons.TextView({text: "{northwind>ProductName}"})
}))
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Quantity PerUnit"}),
visible: true,
template: new sap.ui.commons.TextView({text: "{northwind>QuantityPerUnit}"})
}));
oTable.bindRows("northwind>/value");
I am trying to read selected row in the above table with the below code.
var oTable = sap.ui.getCore().byId('tableId');
//var data[];
var selected = oTable.getSelectedIndex();
if(selected ==-1) {
alert("select a row");
}else{
$("#formId").slideDown(function() {
//var data = oTable.getModel('northwind').oData['Products('+ selected +')'];
var data = oTable.getModel('northwind').getData();
console.log(data);
and i am able to see the data in browser console.(screen shot attached). But I am unable to read the values from the variable data.
I tried with data.length, data.getProperty(), but it's not returning any values.
Any help
Thanks
Ravi
Hi Ravi,
try it with data.value.
This seems to be the array with the requested objects
Regards
Daniel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Durga,
Please tel me why it is "Assumed Answer" even though it is a general question and answered many times in this forum.
Please mark this Discussion with a Correct Answer (closes, but does not lock the Discussion) and Helpful Answer where appropriate. Seehttp://scn.sap.com/community/support/blog/2013/04/03/how-to-close-a-discussion-and-why Even if you discovered the solution without any outside contributions, it helps others to understand what the solution turned out to be. Do not use Assumed Answered as it confuses anyone looking for the specific answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"data" is an object. so it's sowing all the data. if you want to get selected row data then go either of this way.
var obj = evt.getSource().getBindingContext("northwind").getObject();
console.log(obj);
console.log(obj.ProductName);
or,
var model=that.getView().getModel("northwind"); var path = evt.getSource().getParent().getBindingContextPath(); var data=model.getProperty(path);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See these example to get table data in various methods,
http://jsbin.com/tipokenuki/1/edit?html,js,console,output
http://jsbin.com/kipese/7/edit?html,js,output
And you can see lot of working examples here -
use odatamodel instead of json model. Bec json model is client side so its not able to read the data from that server.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.