Skip to Content
avatar image
Former Member

Filtering OData Model data at client side (SAP UI5 program)

I have got all the data from Gateway Server to my SAPUI5 program. Now, I dont want to show all the data which I got but want to show only one particular line item. I tried putting filter but it is not working.

Can some one please help me how to use filter in OData model. Please note that I am trying to filter at client side and not at server side

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 14, 2015 at 02:52 PM

    Hello All,

    Firstof all thanks for the help provided by all of you which made me learn baby steps in creating a OData service and access it through SAP UI5 program. I am almost done but have one last stage issue, request your help.

    I have implemented getEntity() method so that I can pass a parameter in the URL and get the line item related to that URL. The below URL is working fine when I execute it from browser or from netweaver gateway server directly .... below is the URL which works fine (reads a specific record as per URL parameter)

    http://<NetWeaver Gateway Domain>:8000/sap/opu/odata/sap/ZUI5_SAMPLEUSERINFO_SRV/UserInfoSampleSet('123098')

    The above URL gives me one expected entry in XML format.

    However, if I use below code in my SAPUI5 program it still retrives all the three records. Please see below code.

    var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZUI5_SAMPLEUSERINFO_SRV/");

    oModel.read("/UserInfoSampleSet('123098')/");

    var oTable = new sap.ui.table.Table({width : "100%", visibleRowcount : 5});

    oTable.addColumn(new sap.ui.table.Column({label : new sap.ui.commons.Label({text : "UserID"}), template : new sap.ui.commons.TextView({text : "{Zuserid}"})}));

    oTable.addColumn(new sap.ui.table.Column({label : new sap.ui.commons.Label({text : "User Address"}), template : new sap.ui.commons.TextView({text : "{Zaddr}"}), visible : true}));

    oTable.addColumn(new sap.ui.table.Column({label : new sap.ui.commons.Label({text : "Country"}), template : new sap.ui.commons.TextView({text : "{Zcountry}"}), visible : true}));

    oTable.setModel(oModel);

    oTable.bindRows({path : "/UserInfoSampleSet"});

    return oTable;

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Chandrashekhar Mahajan

      As I guessed it was a simple mistake. I did not replace apotrophe...which I replaced now and it works fine.

      Thanks a lot Chandra and thanks a lot Jason moors and all others on the post who helped me.

      Closing the thread.

  • Jan 12, 2015 at 10:25 AM

    If you want to filter an OData model, the filter logic is on the server. Or, as the SAPUI5 docs mention it:

    The OData model is a server-side model: the dataset is only available on the server and the client only knows the currently visible rows and fields. Sorting and filtering is done on the server. The client has to send a request to the server to accomplish these tasks.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I am basically a Java portal developer so definitely I think I did not do proper set-up at gateway server and that could be leading to these issues.

      Coming to your question of implementing TDATASET_GET_ENTITY method....what I did is..

      right click on GET_ENTITY(query) and then did the mapping using RFC. And then generated artifacts.

      Attached screenshot

      Message was edited by: Sun 197895

  • Jan 09, 2015 at 09:30 PM

    https://cdchsb401.tyson.com/sap/ui5/1/sdk/#docs/api/symbols/sap.ui.model.odata.ODataModel.html

    you may use the OData query syntax:

    http://www.odata.org/documentation/odata-version-2-0/uri-conventions/

    or you could also use the
    oData.read function and passing filters.. look into the sdk and look for the filter object

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Dennis Seah

      Hi Dennis,

      No luck....I am still getting all data šŸ˜”. Used below code.

      var oModel = new sap.ui.model.odata.ODataModel();

      oModel.read("/sap/opu/odata/sap/ZSCAPP_SRV/", null,[ "$filter=val eq '1000940272' and key eq 'Scid'"]);

      in the above line when I use 'null' as one of the parameter it throws ''null pointer error". But when I remove the 'null' value then it works but then it gives me whole data which means it is not filtering.

  • Jan 10, 2015 at 05:49 PM

    HiĀ  ,


    For general purpose filtering of odata you can use ?$filter = property eq 'value'

    I your case you can useĀ  abc.xsodata/TDataSet?$filter = Scid eq 'value'


    This should filter your odata values as ScidĀ  = value


    You can refer :Home | OData - The Protocol for REST APIs

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 12, 2015 at 04:01 PM

    Thanks all for the help.

    Today I learned few things though was not able to fix my filter issue.

    But after going through few other posts and specially which Jason mentioned, I feel I have not properly set-up my Odata service which I would be working upon now.

    Thanks again.

    Add comment
    10|10000 characters needed characters exceeded