cancel
Showing results for 
Search instead for 
Did you mean: 

Table Filter for Odata Model

gopi_nidjelli2
Participant
0 Kudos

Hi All,

      I have a table which has binding to a Odata Model. I have a search field at the top of the table which should filter my table values.

var sField = "profam";

     var sQuery = oEvent.getParameter("query");

  

  var filters = new sap.ui.model.Filter(sField, sap.ui.model.FilterOperator.Contains, sQuery);

   

     // update list binding

var list = this.getView().byId("table");

var binding = list.getBinding("items");

binding.filter(filters);

But the table is not filtering with the search criteria. 

Does Client Side Filter works for Odata model or we need to filter in the Odata ?

Thanks

Gopi

View Entire Topic
saivellanki
Active Contributor

Hi Gopi,

OData Model is a Server-Side Model and it supports server-side filtering.

But from 'v2' version of OData Model, you have an option to set the mode to 'Client' / 'Server' / 'Auto' depending on your use case.

You have to set the mode, when you're binding items to table, for example:


oTable.bindItems({

     path: 'yourBindingPath',

     parameters: {

          mode: sap.ui.model.odata.OperationMode.Client

     }

});

API: JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.OperationMo...


Regarding your issue: Since you didn't set any mode, it automatically picks 'Server' as the mode and does the filtering on server side. Your code looks fine. But, can you check the developer console and see if there are any errors?


Regards,

Sai.

gopi_nidjelli2
Participant
0 Kudos

Hi Sai,

I tried as below. The table gets refreshed but data is not filtered.

  var sQuery = oEvent.getParameter("query");
var sField = "Lbiprofam";
var oFilters = new sap.ui.model.Filter(sField, sap.ui.model.FilterOperator.Contains, sQuery);

var oTable = this.getView().byId("table");     
oTable.bindItems("/ZPRODFAM_HCISet",ItemTemplate,  sap.ui.model.odata.OperationMode.Client,oFilters );

Am I missing anything here?

Thanks Gopi

saivellanki
Active Contributor
0 Kudos

Gopi,

You have to set the mode at first when you bind items to table for the first time. No need to do it again when you filter the table.

Your below code is good (Actual Question Code), just set a break point and see where it is going wrong.



var sField = "profam";

var sQuery = oEvent.getParameter("query");

var filters = new sap.ui.model.Filter(sField, sap.ui.model.FilterOperator.Contains, sQuery);

// update list binding

var list = this.getView().byId("table");

var binding = list.getBinding("items");

binding.filter(filters);

Regards,

Sai.

gopi_nidjelli2
Participant
0 Kudos

Hi Sai,

        The First time data is fetched from Odata model. Based on the dropdown field I selected I want to filter the data by calling oModel.read(filters) or filter at client side.

If I set as Client side will the other code work? or do I need to set it to Auto?

Thanks

Gopi