cancel
Showing results for 
Search instead for 
Did you mean: 

Dropdown List for one column of a table with Odata binding.

former_member300568
Participant
0 Kudos
Hi All,

I have to display a table with three columns, and third column should have value from entityset zentity2 ( ID, Description)

Entity1 is the actual display of table ( name, flag ,desc{ three values from zentity2 as dropdown}).

Code in my view

	<ColumnListItem>
									<cells>
										<ObjectIdentifier text="{name}"></ObjectIdentifier>
										<ObjectIdentifier text="{flag}"></ObjectIdentifier>
										<ObjectIdentifier text="{desc}"></ObjectIdentifier>
										<Text text="{desc}"/>
										<Select items="{entity2}">
											<!-- here's the relative dropdown binding -->
											<core:Item key="{id}" text="{Description}"/>
										</Select>
									</cells>
								</ColumnListItem>

In My Controller

var oModel = new sap.ui.model.json.JSONModel();

oModel.setData(oData);

this.getView().setModel(oModel);

As of now, I see a table with just three columns and no drop down in description column.

Accepted Solutions (1)

Accepted Solutions (1)

RaminS
Participant

You need a "/" before the entity2 set, otherwise it thinks entity2 is a property of entity1

<cells>
	<ObjectIdentifier text="{name}"></ObjectIdentifier>
	<ObjectIdentifier text="{flag}"></ObjectIdentifier>
	<Select items="{/entity2set}" selectedKey="{id_in_entity1}">
		<core:Item key="{id}" text="{Description}"/>
	</Select>
</cells><br>
former_member300568
Participant
0 Kudos

HI @rshafaiottawa, Thanks.

My Meta data for Entity1 is below , as you can see in my view below , I am displaying only procdesc,optinflg and zfreqdes (need this as drop down) , Attaching the error as well.error.png

{
"d" : {
"results" : [
{
"__metadata" : {
"id" : "http://jfbsapags01.genmills.com:36520/sap/opu/odata/sap/ZSD_CUSTOMER_360_SRV/ZZCONTACT360(proctyp='ZALO',freqid=1)",
"uri" : "http://jfbsapags01.genmills.com:36520/sap/opu/odata/sap/ZSD_CUSTOMER_360_SRV/ZZCONTACT360(proctyp='ZALO',freqid=1)",
"type" : "ZSD_CUSTOMER_360_SRV.ZZCONTACT360Type"
},
"proctyp" : "ZALO",
"freqid" : 1,
"procdesc" : "04 ALLOCATION AUTO-CUT",
"optinflg" : "X",
"zfreqdesc" : "ONCE PER DAY"
},

My Metadata for entity2 is below , This has totally 3 rows of data, which is what i am expecting to see in my drop down.

  "d" : {
"results" : [
{
"__metadata" : {
"id" : "http://jfbsapags01.genmills.com:36520/sap/opu/odata/sap/ZSD_CUSTOMER_360_SRV/Z_FREQDESC360(freqid=1,zfreqdesc='ONCE%20PER%20DAY')",
"uri" : "http://jfbsapags01.genmills.com:36520/sap/opu/odata/sap/ZSD_CUSTOMER_360_SRV/Z_FREQDESC360(freqid=1,zfreqdesc='ONCE%20PER%20DAY')",
"type" : "ZSD_CUSTOMER_360_SRV.Z_FREQDESC360Type"
},
"freqid" : 1,
"zfreqdesc" : "ONCE PER DAY"
},

I changed my View like this

	<content>
<Table id="idTable" items="{/entity1}">
<columns>
<Column >
<header>
<Label design="Bold" text="Process Type"></Label>
</header>
</Column>
<Column>
<header>
<Label design="Bold" text="OptIn"></Label>
</header>
</Column>
<Column demandPopin="true" hAlign="Begin" minScreenWidth="Tablet">
<header>
<Label design="Bold" text="Frequency"></Label>
</header>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectIdentifier text="{procdesc}"></ObjectIdentifier>
<ObjectIdentifier text="{optinflg}"></ObjectIdentifier>
<ObjectIdentifier text="{zfreqdesc}"></ObjectIdentifier>
<Text text="{zfreqdesc}"/>
<Select items="{/entity2}" selectedKey="{freqid}">
<!-- here's the relative dropdown binding -->
<core:Item key="{freqid}" text="{zfreqdesc}"/>
</Select>
</cells>
</ColumnListItem>
</items>
</Table>
RaminS
Participant
0 Kudos

Why do you use names "entity1" and "entity2" in the code? Your odata entity names are ZZCONTACT360Type and Z_FREQDESC360Type

Do you change the names when you assign to a local Json model ?

former_member300568
Participant
0 Kudos

I have the correct entity name in my view ZZCONTACT360 and Z_FREQDESC360 , I just changed in the code while pasting here.

Also , should we not pass the enityset name which is ZZCONTACT360 and Z_FREQDESC360 and not the entity type names(ZZCONTACT360 and Z_FREQDESC360) right?

RaminS
Participant
0 Kudos

Yes, entityset names should be used.

Put a breakpoint in your controller and see what the odata looks like. What does the Network tab show under payload of your GET event?

former_member300568
Participant
0 Kudos

this is the code I have in the controller.

sap.ui.define([<br>	"sap/ui/core/mvc/Controller",<br>	"sap/ui/model/json/JSONModel",<br>	"sap/ui/model/odata/ODataModel "<br>], function (Controller, JSONModel,OData) {<br>	"use strict";<br>	return Controller.extend("zsdcust360test1.zsdcust360test1.controller.communicationflag", {<br>		onInit: function () {<br>			var oModel = 	var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZSD_CUSTOMER_360_SRV");;<br>			oModel.setData(OData);<br>			this.getView().setModel(oModel);<br>		}<br>	});<br>});

I am having error in the Get Event in my Network tab.

Failed to resolve dependencies of 'zsdcust360test1/zsdcust360test1/controller/communicationflag.controller.js'<br> -> 'sap/ui/model/odata/ODataModel .js': failed to load 'sap/ui/model/odata/ODataModel .js' from resources/sap/ui/model/odata/ODataModel .js: script load error  <br> ModuleError: Failed to resolve dependencies of 'zsdcust360test1/zsdcust360test1/controller/communicationflag.controller.js'<br> -> 'sap/ui/model/odata/ODataModel .js': failed to load 'sap/ui/model/odata/ODataModel .js' from resources/sap/ui/model/odata/ODataModel .js: script load error
RaminS
Participant
0 Kudos

Why do you have sap/ui/model/odata/ODataModel "?

First of all, there is an extra space before the closing ", which is causing an error finding the library.
Second, that library is deprecated, replaced by sap.ui.model.odata.v2.ODataModel
Third, why do you need that in your controller, your manifest.json should define the odata service and model, in your controller you just use the model's read method to bindElement to your view or any specific control.

I suggest you look at some samples or demo SAPUI5 apps, before continuing on this path.

.

former_member300568
Participant
0 Kudos

I am already Binding Element in my view and that just displays the data as table without a dropdown. , Should I use template? and bindAggregation?

also, freqid is key in both my entities.

Answers (1)

Answers (1)

RaminS
Participant
0 Kudos

You seem to have changed the code you posted above. Now it's hard to read as it's all in one line. But your error is still about the dependency define statement, with the extra space. You need to get rid of that before anything else.