Skip to Content

Table Filter for Odata Model

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Aug 19, 2016 at 05:02 AM

    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.OperationMode


    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 19, 2016 at 04:41 AM

    Hi,

    Client Side Filter works irrespective of the data model, as it's filtering on the binding.


    Sample code, which is working fine for me


    var filters = [];

    var query = evt.getParameter("query");

    var filter = new sap.ui.model.Filter("SupplierName", sap.ui.model.FilterOperator.Contains, query);

    filters.push(filter);

    // update list binding

    var list = sap.ui.getCore().byId("listid");

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

    binding.filter(filters);

    Thanks,

    Namita

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 19, 2016 at 04:53 AM

    Hi Gopi,

    You can achieve this in many ways,

    1) If your filtering the data within the Collection then its better to store data in json Model and as times you want.

    ex:

    oTable = this.getView().byId("tableid");

    var odata Model = new sap.ui.model.odata.ODataModel("/XXX/YYYY");

    oModel.read("/UrCollection", null, null, true, function(oData, oResponse) {

    jsonModel = new sap.ui.model.json.JSONModel({oData.results });

    // bindmodel to controller

    oTable.setModel(jsonModel);


    }, function(oData, oResponse) { });



    //onClick of Search write this below code


    var searchString = this.getView().byId("idSrchField").getValue();

    var filters = new sap.ui.model.Filter("getBusinessAreaData", sap.ui.model.FilterOperator.Contains, searchString);

    // update list binding

    this.getView().byId("tableid").getBinding("items").filter(filters);

    2) writing filter Query option in url itself.

    use this method in case if you want updated data each and every time.

    var odataModel = new sap.ui.model.odata.ODataModel("/XXX/YYYY");

    odataModel .read("/UrCollection?$filter=Address/City eq 'Redmond'", null, null, true, function(oData, oResponse) {

    jsonModel = new sap.ui.model.json.JSONModel({oData.results });


    // bindmodel to controller

    oTable.setModel(jsonModel );



    }, function(oData, oResponse) { });

    For more information please refer below link.

    URI Conventions (OData Version 2.0) · OData - the Best Way to REST

    Thanks

    Venkat

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.