Skip to Content

List binding with filtered data in XML view

Dear gurus

I hope you are doing well

Currently i'm trying to bind a filtered data to a list control in xml view in the oninit event of the controller the odata service url is like this

http://mikmo.mylocalhost.com/MIKMOWCFDataService.svc/view_VendorGroup?$filter=VendorID%20eq%201

i used the code below

var myList = this.getView().byId("lstVendorGroups");
var sListURI = "http://mikmo.mylocalhost.com/MIKMOWCFDataService.svc";
			var oListModel = new sap.ui.model.odata.ODataModel(sListURI, false);
			var oListModelJson = new sap.ui.model.json.JSONModel();
			oListModel.oHeaders = {
				"DataServiceVersion": "2.0",
				"MaxDataServiceVersion": "2.0"
			};
oListModel.read("/view_VendorGroup", null, ["vendorID=" + window.VendorID], null, function(oData, oResponse) {
				oListModel.setData(oData);
				oListModel.loadData(oData);


			}, null);
			oListModelJson.attachRequestCompleted(function(oEvent) {
			//How to bind the list in here 	
			});
myList.setModel(oListModel, "VendorGroups");

and here is the list xml

<List growing="true" growingThreshold="100" headerText="{i18n>businessareas}" id="lstVendorGroups"
								items="{VendorGroups>/view_VendorGroup}">
								<items>
									<!--<ObjectListItem title="{VendorGroups>GroupName}" type="Active" press=".onItemSelected" />-->
									<StandardListItem id="stListItem" title="{VendorGroups>GroupName}"/>
								</items>
							</List>

Can anyone give me a hint on how to bind the data as the code i wrote is not running

Thanks in advance

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Dec 23, 2016 at 07:28 AM

    Hi Karim,

    Please try this..

    var sListURI = "http://mikmo.mylocalhost.com/MIKMOWCFDataService.svc";
    var oListModel = new sap.ui.model.odata.ODataModel(sListURI, false);
    var oListModelJson = new sap.ui.model.json.JSONModel();
    oListModel.oHeaders = {
    			"DataServiceVersion": "2.0",
    			"MaxDataServiceVersion": "2.0"
    		};
    oListModel.read("/view_VendorGroup", null, ["vendorID=" + window.VendorID], null, 
    	function(oData, oResponse) {		
    		var modelData=[];
    		for(var i = 0; i < oData.results.length; i++) {
    			modelData.push(oData.results[i]);
    		}
    		oListModelJson.setData(modelData);
    	}
    );
    this.getView().setModel(oListModelJson, "VendorGroups");
    <List growing="true" growingThreshold="100" headerText="{i18n>businessareas}" id="lstVendorGroups"
    								items="{VendorGroups>/}">
    	<items>
    		<ObjectListItem title="{VendorGroups>GroupName}" type="Active" press="onItemSelected" />						
    	</items>
    </List>
    

    Best Regards,

    Amit

    Add comment
    10|10000 characters needed characters exceeded