cancel
Showing results for 
Search instead for 
Did you mean: 

Can't bind oData service to select element

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

});

Answers (2)

Answers (2)

former_member484715
Contributor
0 Kudos

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.

settipalli_raj
Explorer
0 Kudos

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.

Former Member
0 Kudos

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