Skip to Content
0

Can't bind oData service to select element

Oct 05, 2017 at 03:30 PM

56

avatar image
Former Member

Hi,

I am new to UI5 and after having searched a lot, I cant find a solution to bind the oData service to a select element in my code. The requirement is to get the input from the first drop-down to filter second drop-down. The first dropdown workd perfectly fine.

The second dropdown seems to not bind the items to the element.

First Dropdown view.xml

Second dropdown view.xml

controller.js (first approach)

Second approach

I am not sure what am I missing here but both the approach doesn't work. Could you please let me know what is missing?

Regards

Sai

firstapproach.png (19.1 kB)
jsonmodel.png (2.6 kB)
subcat.png (30.7 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member Oct 27, 2017 at 10:56 AM
0

Hi,

This is now fixed. I used the following approach and it worked

this.getView().byId("idSIssSubCat").setModel(this.oIssueCategoryModel);

var oItemSelectTemplate = new sap.ui.core.Item({ key : "{ProdCategory}:"+"{Subcategory}", text : "{Description}" }); this._oView.byId("idSIssSubCat").bindAggregation("items","/results",oItemSelectTemplate);

var sServiceUrl = this._oComponent.getMetadata().getConfig().serviceConfig.serviceUrl;

var oConfig = {

metadataUrlParams: {},

json: true,

// loadMetadataAsync : true,

defaultBindingMode: "TwoWay",

defaultCountMode: "Inline",

useBatch: false

};

this.oDataModel = new sap.ui.model.odata.ODataModel(sServiceUrl, oConfig);

var that = this;

var uri = "/IssueSubCategorySet?$filter=ProdCategory eq '" + oEvent.getSource().getSelectedItem().getKey() + "'";

this.oDataModel.read(uri,

{ success : function(oData)

{ that.oIssueCategoryModel.setData(oData);

sap.m.MessageToast.show("Success!");

},

error : function(oError)

{

zmclaren.prd.util.messages.showErrorMessage(oError);

},

async : false

});

Share
10 |10000 characters needed characters left characters exceeded
Settipalli Raj Oct 05, 2017 at 10:48 PM
0

Hi There,

In your first approach, change the code to:

subCatIss.bindItems({
  path:"/IssueSubCategorySet",
  filters:[new sap.ui.model.filter.Filter({path:'ProdCategory',operator:'EQ',value1:oEvent.getSource().getSelectedKey()],
  template:oItemSelectTemplate
});<br>

This should correctly encode the service URL and should work. bindAggregation should also work if you use filters array in binding and not appending "$filter" directly to URL.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi,

Thanks for your reply. I tried both bindItems and bindAggregation with the filters array, the service is not called at all. The control doesn't reach the service I developed.

Regards

Sai

0
Arjun Biswas Oct 10, 2017 at 09:07 AM
0

Consider your select is in the fragment :

<Select change="selectChange" showSecondaryValues="true">
</Select>

Now from your controller you can bind the model values like this:

var mModel = new sap.ui.model.json.JSONModel(); //initialise your model from a JSON file
				
				this._model.read("/UserSet",null,null,false,function(oData){
					mModel.setData(oData);
				},function(){
					
				});
				var oItemSelectTemplate = new sap.ui.core.Item({
				            key : "{Userid}",
				            text : "{Userid}"
				        }); //Define the template for items, which will be inserted inside a select element
				var mySelectMenu = this.oDialogFragment.getContent()[0].getContent()[2]; //Get a reference to the UI element, Select to bind data
				mySelectMenu.setModel(mModel);// set model your_data_model to Select element
				mySelectMenu.bindAggregation("items","/results",oItemSelectTemplate); //bind aggregation, item to Select element with the template selected above

Hope this helps,

Regards.

Share
10 |10000 characters needed characters left characters exceeded