cancel
Showing results for 
Search instead for 
Did you mean: 

How to filter OData model at the backend?

Hi Gurus

I am quite new on UI5, I am developing a page to show a list using OData & XML View.

It works fine if I retrieve the whole data set and do filtering at the frontend.

But, I want to do filtering at the backend before the data passing to the browser to save bandwidth, how can I do that?

Below is the code I am using now:

Create and bind data model:

var sInvStockUrl = "/sap/opu/odata/SAP/Z_XXXX_SRV/";
//create model
var oStockModel = new ODataModel(sInvStockUrl,"stockModel");
//set model
 this.getView().byId("stockList").setModel(oStockModel,"stockModel");

Filtering when I click a button:

//create filters
var aFilter = [];
aFilter.push(new Filter("Field1", FilterOperator.EQ, "AAA"));
aFilter.push(new Filter("Field2", FilterOperator.EQ, "BBB"));
//apply filters
var oTable = this.getView().byId("stockList");
oTable.getBinding("items").filter(aFilter);

Thanks in advance!

Accepted Solutions (0)

Answers (2)

Answers (2)

maheshpalavalli
Active Contributor
0 Kudos

what is the issue you are facing now?, ur code seems to be fine... do u want to know what the code to be written in odata layer?

If yes, you need to use the filter the data in getentityset method(you will find an importing filters parameter)

Best Regards,

Mahesh

0 Kudos

Thanks for the reply.

I got the point, I thought in my code the filter works at UI5 layer, but actually it's on OData layer which is what I want.

John

maheshpalavalli
Active Contributor
0 Kudos

Yup.. Please close this Question if your query is solved.

Warm Regards,
Mahesh

junwu
Active Contributor
0 Kudos

do some google please