cancel
Showing results for 
Search instead for 
Did you mean: 

List binding with filtered data in XML view

karim_mohamed2
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

amit5ingh
Participant
0 Kudos

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

karim_mohamed2
Participant
0 Kudos

Thanks Amit for your reply

But when i used your code it throws an error that there is no method for Length

Thanks again for your consideration