Skip to Content

FIltering in Odata Model having Gateway service

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);
}
);
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Mar 06, 2017 at 11:04 AM
    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 });
    Add comment
    10|10000 characters needed characters exceeded

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

    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);
    
    
    Add comment
    10|10000 characters needed characters exceeded

  • Mar 03, 2017 at 06:42 AM

    Hi Ketan,

    Thanks. It worked.

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

    Add comment
    10|10000 characters needed 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?

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

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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