Skip to Content
Author's profile photo Ranjit Rao

Filtering Data from an Odata Service in Table in SAPUI5

In my previous blogs I have shown how to bind data to a table via Odata Model. Now, Here I would show how to filter the data fetch from an odata service.

The  oData service we would use here is:


If we have to filter an odata service using our service url we have to ‘$filter’ and apply it with the desired equation. For example ,if we have to fetch data for the employees who fall under the CompanyId SAP, then our url should be something like this:

Filtering$filter=CompanyId eq ‘SAP’

Now, we will see how to implement this filter in an SAPUI5 project.

Generally, we bind Items to a Table somewhat like this:

oTable.bindItems(“/Employees”, template);

Lets go through this bindItems() method. This is a method which is extended from sap.m.ListBase.

bindItems(sPath, oTemplate,oSorter, aFilters): sap.m.ListBase

sPath : path to a list in the model

oTemplate : the control template for this aggregation.

oSorter : the initial sort order(optional)

aFilters : the predefined filters for this aggregation(optional).

aFilters is the parameter here which we will be using to set the filter for the Table as shown.


var oFilters = [ new sap.ui.model.Filter(“<Column for filter>”,“<Operator>”, <Filter Value>) ];

oTable.bindItems(“/Employees”, template, null, oFilters);  

If our criteria is to fetch data  for Employees with CompanyID SAP, then our code will be:


var oFilters = [ new sap.ui.model.Filter(“CompanyId”,“EQ”, “SAP”) ];

oTable.bindItems(“/Employees”, template, null, oFilters);

Now, Lets create a small application to implement this:

Open Eclipse, Create a New SAPUI5<mobile> project with a View named MainView<javascript view> .

Paste the following code in the “createContent: function(oController)” of the view.js page:


var oPage = new sap.m.Page({

            title: “Company Details”,


             var oItemTemplate = new sap.ui.core.Item({

                    key: “{key}”,

                    text: “{text}”


                var combobox = new sap.m.ComboBox(“cmb1”,{

                    items: [ {

                           “key” : “*”,

                           “text” : “All Data”


                             “key” : “SAP”,

                           “text” : “SAP”


                           “key” : “ITelO”,

                           “text” : “ITelO”


                 template: oItemTemplate,

                    selectionChange: oController.Selection


             var oLabel= new sap.m.Label(“lbl”,{

                    text: “Select a Value”


             var oTable = new sap.m.Table({

                     id : “Countries”,

                    mode: sap.m.ListMode.None,

                    columns: [

                    new sap.m.Column({

                           width: “1em”,

                           header: new sap.m.Label({

                                 text: “ID”


                    }),new sap.m.Column({

                           width: “1em”,

                           header: new sap.m.Label({

                                 text: “Company Id”


                    }),new sap.m.Column({

                           width: “1em”,

                           header: new sap.m.Label({

                                 text: “First Name”


                    }),new sap.m.Column({

                           width: “1em”,

                           header: new sap.m.Label({

                                 text: “Last Name”





             var template = new sap.m.ColumnListItem({

                     id : “first_template”,

                    type: “Navigation”,

                    visible: true,

                    selected: true,

                    cells: [

                                new sap.m.Label({

                           text: “{Id}”


                   new sap.m.Label({

                           text: “{CompanyId}”


                   new sap.m.Label({

                           text: “{FirstName}”


                   new sap.m.Label({

                           text: “{LastName}”




             var oFilters = null;

             oTable.bindItems(“/Employees”, template, null, oFilters);  




             return oPage;

Paste the following code in the “onInit : function()” method of the controller.js page

onInit : function()” method of the controller.js

var oModel = new sap.ui.model.odata.ODataModel(“proxy/https/”, false);


Paste the following code in the below the onInit() method of the controller.js page

Selection: function(evt)

Selection : function(evt) {

                                        var oFilters=null;

                                        var oSelectedKey = sap.ui.getCore().byId(“cmb1”).getSelectedItem().getKey();


                                        var oFilters = [ new sap.ui.model.Filter(“CompanyId”,“EQ”, oSelectedItem) ];

          sap.ui.getCore().byId(“Countries”).bindItems(“/Employees”,sap.ui.getCore().byId(“first_template”), null, oFilters);


Now save and run the application.



Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Any way to add multiple filters? I mean I want to filter the data based on 2 fields.

      Author's profile photo Michael Appleby
      Michael Appleby

      Please create a new Discussion marked as a Question.  Comments to a Blog (or Document) is not the right vehicle for asking questions as the results are not easily searchable.  Once your issue is solved, a Discussion with the solution (and marked with Correct Answer) makes the results visible to others experiencing a similar problem.  If a blog or document is related, put in a link.

      NOTE: Getting the link is easy enough for both the author and Blog.  Simply MouseOver the item, Right Click, and select Copy Shortcut.  Paste it into your Discussion.  You can also click on the url after pasting.  Click on the A to expand the options and select T (on the right) to Auto-Title the url.

      Thanks, Mike (Moderator)

      SAP Technology RIG