Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with Direct ODataModel binding to controls and assigning it to JSON model

former_member243729
Participant
0 Kudos

Hi,

I have 2 tables (sap.ui) and to the first table I am binding oDataModel directly (meaning, not calling oDataModel.read method). This is how my first Table code looks like which works fine (First block of code below). But now, I am trying to assign the ODataModel's oData to a JSON Model (which I am able to) but the binding to the another table controle is not working (second & third blocks of code below). Please let me know what I am missing here.

//View.XML
<ui:Table id = "oTb1" rows = "{directBind>/DEPARTSet}">
		<ui:columns>
			<ui:Column>
				<Label text = "Department ID" />
				<ui:template>
					<Text text="{directBind>SunDeptId}"/>
				</ui:template>
			</ui:Column>
		</ui:columns>
	</ui:Table>

//Contoller.js

handleLoadTab1: function(oEvent){
		var oTab1 = this.getView().byId("oTb1");
		this.getView().setModel(this.getOwnerComponent().getModel(), "directBind");
	},

//View.XML
<ui:Table id = "oTb3" rows = "{Table3>/DEPARTSet)}">
		<ui:columns>
			<ui:Column>
				<Label text = "Department ID" />
				<ui:template>
					<Text text="{Table3>SunDeptId}"/>
				</ui:template>
			</ui:Column>
		</ui:columns>
	</ui:Table>

//Controller.js
handleLoadTab3: function(oEvent){
			var oTab3 = this.getView().byId("oTb3");
			var oJsonMod = new sap.ui.model.json.JSONModel();
			oJsonMod.setData(JSON.stringify(this.getView().getModel("directBind").oData));
			oTab3.setModel(oJsonMod, "Table3");
		},

  • SAP Managed Tags:
1 REPLY 1

Joseph_BERTHE
Active Contributor
0 Kudos

Hi,

When using JSon model in table binding context, then you have to initialize the model directBind with an empty property:

component.js :

this.setModel(JSONModel({ DEPARTSet: [] }), "Table3");

Try this, it should work 😉

Regards,

Joseph

  • SAP Managed Tags: