Skip to Content
0
Former Member
Aug 14, 2015 at 12:47 PM

JSON Model - Table Data access problem

220 Views

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

Attachments

Data.jpg (69.1 kB)