cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

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

sun197895
Participant
0 Likes
7,973

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

View Entire Topic
SergioG_TX
SAP Champion
SAP Champion
0 Likes

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

sun197895
Participant
0 Likes

Hi Sergio,

For some reason filter is not working even though the syntax seems to be correct. Do we have to do any configuration at the Gateway server to make the filter work? Please advice. Below is the code which I using to filter.

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

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

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.setModel(oModel);

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

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

return oTable;

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

.

Former Member
0 Likes

Hi Sun

You should do it this way.

-D

sun197895
Participant
0 Likes

Thanks for your reply Dennis ..

oModel.read("/EntitySet('15')/Items", null,[ "$filter=val eq 'full' and key eq 'one'"]);

Can you please guide me what I should substitute for my scenario...like

In my case :

Entity Set      :      TDataSet

Property which I want to filter is :      Scid

Vaue of the Scid I am looking for is :     Scid = '12345'

So now, please tell me how my statement should look like .... should it look like below ?

oModel.read("/TDataSet('12345')/Scid", null,[ "$filter=val eq '12345' and key eq 'Scid'"]);



Former Member
0 Likes

Hi Sun

I believe it should be

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

-D

sun197895
Participant
0 Likes

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.