Skip to Content
0

FIltering in Odata Model having Gateway service

Mar 02, 2017 at 01:02 PM

314

avatar image

Hi,

I have a NW Gateway Odata Service having a Entity Set - "bankSet" and a column - "Bankkey".

I have created a odata Model for this service. Now, I want to filter contents of service for 1 specific "Bankkey" . How can I achieve this. I tried all solutions answered to similar question but nothing worked out.

I want to bing this data to a table in UI5.

var allFilters = new Filter("Bankkey", FilterOperator.EQ, "021000089");

oDataModel.read("/bankSet",null,null,{filters : allFilters},function(odata){
var datalist = odata.results;
var otable = that.getView().byId("idProductsTable");
var oModel = new sap.ui.model.json.JSONModel(datalist);
otable.setModel(oModel);
}
);
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
avatar image
Former Member Mar 06, 2017 at 11:04 AM
0
Hey Ankit,
When defining the OData model, you can pass $filter as a URL parameter.. this should do the trick.


var params = new Object();
params["$filter"] = "(Bankkey eq '021000089')";
var oModel = new sap.ui.model.odata.ODataModel(url, { serviceUrlParams : params });
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Leandro,

Thanks for answer. Your solution is working for only keyfields of dataset. Is there any other way to filter any field from dataset?

Thanks,

0
Former Member

Hi Ankit,

From my experience, you can only filter on keys, (I use the SAP Gateway yo exposure my data)...

Best

Leandro

0
avatar image
Former Member Mar 02, 2017 at 01:27 PM
0

HI Ankit,

Use this approach to bind data to the table with filters

this._oTable = this.byId("idTable");
this._oTemplate = this.byId("idTemplate").clone();

var sPath = "/bankSet";
this._oTable.bindItems({
	path: sPath,
	template: this._oTemplate
});
		
var oFilter = new sap.ui.model.Filter("Bankkey", "EQ", "021000089"),
    oBinding = this._oTable.getBinding("items");
oBinding.filter(oFilter);

Share
10 |10000 characters needed characters left characters exceeded
Ankit Garg Mar 03, 2017 at 06:42 AM
0

Hi Ketan,

Thanks. It worked.

If you know, how to filter in Odata Model itself, then please share it

Show 1 Share
10 |10000 characters needed characters left characters exceeded
this._oTable.bindItems({
	path: sPath,
	template: this._oTemplate,
        filters : [ new sap.ui.model.Filter({
              path : "Bankkey",
              operator : "EQ",
              value1 : "021000089"
        })]
});

If this is what you meant by Odata Model itself?

0
avatar image
Former Member Mar 05, 2017 at 06:58 PM
0

Hello Ankit,

Are you getting data without filtered content or any error.

What you have done is right. Is your gateway service working fine.

Also I suggest you to use mParameters, so that you don't miss any fields.

Regards,

Gowrinath

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Gowrinath,

My code is delivering filtered data, If I don't use success function.

But I want result to bind with Model, So, Success function is required.

var allFilters = new Filter("Bankkey", FilterOperator.EQ, "021000089");

oDataModel.read("/bankSet",null,null,{filters : allFilters}
);
0
Former Member

Hi Ankit,

What I mean to say is, while calling the odataModel.read method, pass the mParameters specifically like below

odataModel.read({filters: oFilter,

success : function(){}})

And also other parameters which are necessary. Also place breakpoint.

Give it a try.

Regards,

Gowrinath

0