cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in Filtering data in SAP UI5 received from Netweaver Gateway using Odata Model

sun197895
Participant
0 Kudos

Hi,

Problem with filtering OData model.

1) I have a autocomplete control.

2) I bind this auto complete field to the data which I received in the OData model from gateway server.

3) Now, user selects a particular value and populates the auto-complete field.

4) User clicks on a button. When the button is clicked, my table should be displayed with that particular shopping Cart item.

Basically I am trying to get all the data from Netweaver gateway and then filter it at the client side. However, I get all the data displayed as rows in table so I think my filter for OData is not working. Please let me know what mistake I am doing. Thanks in advance.

Below is the code I am using..

-------------------

var arr = [];

var oButton =new sap.ui.commons.Button({text : "Search"});

var oAutoComp = new sap.ui.commons.AutoComplete();

              

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

new sap.ui.getCore().setModel(oModel);   

               

oAutoComp.bindItems({ path : "/TDataSet", template : new sap.ui.core.ListItem({text : "{Scid}"})});

               

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 : "Scid"}), template : new sap.ui.commons.TextView({text : "{Scid}"}), visible : true}));       

               

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

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

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

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

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

               

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

               

oButton.attachPress(function(oEvent){

                   

var autoVal = oAutoComp.getValue();

var listBinding = oTable.getBinding();                   

var f1 = new sap.ui.model.odata.Filter('Scid', [{operator:"EQ", value1:autoVal}]);

listBinding.filter([f1]);           

               });

               

arr.push(oAutoComp);

arr.push(oButton);

arr.push(oTable);

               

return arr;

---------------------------------------

Accepted Solutions (0)

Answers (1)

Answers (1)

pinakipatra
Contributor
0 Kudos

Hi ,


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

I your case you can use oTable.bindRows({path: "/TDataSet?$filter = Scid eq 'value' "});


This should filter your odata values as Scid  = value


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

sun197895
Participant
0 Kudos

Thanks for the reply Pinaki.

But unfortunately for me the filter is not working. Now if I apply the filter as mentioned by you then I get no records...No Data.

oTable.bindRows({path: "/TDataSet?$filter=Scid eq '1000940272'"});

But I am sure there is a record with this value. If I do not put any filter then I can get many records and out of which 1000940272 is one value for property Scid.

Below is the screen shot.

pinakipatra
Contributor
0 Kudos

HI please check what is the name of the entity in the odata .
In the browser please enter the  odata  file path ie. 10.****/*********/****.xsodata?$format = xml(if possible attach a screenshot) in the browser url bar

You should be able to see the entity sets (tables that you are exposing).
Then type in the browser url bar 10.****/*********/****.xsodata/Entitysetname

then you should be able to see the entity named Scid

if it is there then it must work

**Entityname?$filter=ID eq '0001' ***no space between '?$filter' and'='

sun197895
Participant
0 Kudos

Hi Pinaki

Please find attached screenshot.

And also I did not put sapce as you mentioned.

Also, I have put below URL in the address bar and was expecting one record as filter was there. But I got all records which I was getting even without applying filter...as like in below 2nd URL. So basically, I am seeing any difference in the output when I use below two URLs

http://<domain>:<port>/sap/opu/odata/sap/ZSCAPP_SRV/TDataSet?$filter=Scid eq '1000940272'

http://<domain>:<port>/sap/opu/odata/sap/ZSCAPP_SRV/TDataSet

Let me know if you need any more info. Thanks.

Message was edited by: Sun 197895

Message was edited by: Sun 197895

Message was edited by: Sun 197895

pinakipatra
Contributor
0 Kudos

Hi , works fine for me ...i  am not sure why it does not work for you ..