cancel
Showing results for 
Search instead for 
Did you mean: 

how to navigate from one entity set to another with primary key and foreign key relationship?

0 Kudos

This is the northwind odata service i have consumed in the i have taken categories entity set and displayed in the master page so now i have to navigate from master to detail when i click on the particular category and that should reflect in the url also

Accepted Solutions (0)

Answers (1)

Answers (1)

AbhishekSharma
Active Contributor
0 Kudos

Hi Manohar R,

You might want to look at Routing which you defined. If you want to show id in URL, you need to define routing in manifest.json which looks like you have already done.

Format should be like below:

{
"name": "BlankPage",
"pattern": "/blank/{id}",
"titleTarget": "",
"greedy": false,
"target": [
"BlankPage"
]
}

To get this value:

_routeMatched: function (e) {
pathVal = e.getParameter("arguments").id;
},

OR

Please try below working code:

Routing in manifest.json:

"routing": {
			"config": {
				"routerClass": "sap.m.routing.Router",
				"viewType": "XML",
				"viewPath": "SAPOpenCourse.com.view",
				"controlId": "app",
				"controlAggregation": "pages",
				"async": true,
				"bypassed": {
					"target": "notFound"
				}
			},
			"routes": [
				{
					"pattern": "",
					"name": "view1",
					"target": "View1"
				},
				{
					"name": "prod_details",
					"pattern": "prod_details",
					"titleTarget": "",
					"greedy": false,
					"target": [
						"prod_details"
					]
				}
			],
			"targets": {
				"View1": {
					"viewID": "view1",
					"viewName": "View1"
				},
				"prod_details": {
					"viewId": "prod_details",
					"viewName": "prod_details"
				},
				"notFound": {
					"viewName": "notFound",
					"transition": "show"
				}
			}
		},

View1.xml

Please remove unwanted code per your requirements.

<List selectionChange="onItemSelected" mode="SingleSelectMaster" noDataText="{i18n>noDataText}" id="lstProducts" items="{ path: '/ProductSet', sorter: { path: 'Category', group: true }, parameters: { expand: 'ToSupplier,ToSalesOrderLineItems' } }"
growing="true" growingThreshold="5" growingScrollToLoad="true">
<headerToolbar>
<Toolbar>
<Title text="Available Products"/>
<ToolbarSpacer/>
<SearchField width="50%" search="onFilterProducts"/>
</Toolbar>
</headerToolbar>
<items>	<ObjectListItem type="Navigation" title="{Name} ( {ProductID} )" intro="{Category}" number="{CurrencyCode} {Price}" 						numberState="{= ${Price} > 500 ? 'Error' : 'Success'}"> 										<attributes>											<ObjectAttribute text="{WebAddress}" id="__attribute4"/>										</attributes>										<firstStatus>											<ObjectStatus text="{ parts: [ {path: 'WeightUnit'}, {path: 'WeightMeasure'} ], formatter : '.formatter.delivery' }"/>										</firstStatus>										<secondStatus>											<ObjectStatus text="{ parts: [ {path: 'SupplierName'}, {path: 'Name'}, {path: 'TypeCode'} ] }"></ObjectStatus>										</secondStatus>	
</ObjectListItem></items>
</List>

View1.controller.js

onItemSelected: function(oEvent){
			var oComponent;
			oComponent=null;
			oComponent = sap.ui.component(sap.ui.core.Component.getOwnerIdFor(this.getView()));
			var oSelectedItem = oEvent.getParameter("listItem");
			var oContext = oSelectedItem.getBindingContext();
			var sPath = oContext.getPath();
			var oPnlControl = this.byId("pnlData");
			oPnlControl.bindElement({path:sPath});
			oPnlControl.setVisible(false);
			//var obj = oContext.getObject();
			//this.router.navTo("prod_details", {
			//	ProductID: obj.ProductID
			//});
			oComponent._setLineItem(sPath, true);
			MessageToast.show(sPath);
			var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
				oRouter.navTo("prod_details");
		},

Hope this helps..

Thanks-

Abhishek