Skip to Content
0
Former Member
Jun 17, 2015 at 12:04 PM

How to read data from one view in SAPUI5 and display it on the next view

1702 Views

Hi Everyone,

I am trying to create a simple application with two views. my Details.view.js contains a table with multiple rows. When i click on a row, I wish to open the data from the selected row, in a different view- Contact.view.js.

I can navigate to the other view on clicking on a row, but i have no idea how to read and display data from that row in the second view.

This is my code-

var oLayout = new sap.ui.commons.layout.MatrixLayout('oLayout');

oLayout.setWidth('100%');

var oTable = new sap.ui.table.DataTable('oTable');

oTable.addColumn(new sap.ui.table.Column({

label : new sap.ui.commons.Label({text : "Employee ID"}),

template : new sap.ui.commons.TextField({value : "{EmpId}"})

}));

oTable.addColumn(new sap.ui.table.Column({

label : new sap.ui.commons.Label({text : "Name"}),

template : new sap.ui.commons.TextField({value : "{Name}"})

}));

oTable.attachRowSelect(function(oEvent){

sap.ui.getCore().byId("oShell").removeAllContent();

sap.ui.getCore().byId("oShell").addContent(sap.ui.getCore().byId("<id of the view contact>"));

});

var sUrl = "/sap/opu/odata/sap/ZEIS_SRV/";

var oModel = new sap.ui.model.odata.ODataModel(sUrl, true);

sap.ui.getCore().setModel(oModel);

oTable.setModel(oModel);

oTable.bindRows("/EmpDetailsSet");

oLayout.createRow(oTable);

return oLayout;

My Contact.view.js has a similar table defined.

How do I display the selected row in the second view?

Thank You in advance.