Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

JSON Model - Table Data access problem

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

Data.jpg (69077 B)
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question