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,988

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
Qualiture
SAP Mentor
SAP Mentor
0 Likes

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.

sun197895
Participant
0 Likes

Thanks for the response Robin. I have this problem going on for many days now and it is 10th day today.

I got your point that we have to do filtering at server side and not at client side. But can you tell how we can do it. I tried multiple ways in my SAP UI5 program but failed in every way. Please see where I need to correct.

Entity Set : TDataSet

Property with which I want to filter : Scid

I am sending request to client in below ways...

1) This gives me all the data as before which makes me believe that filter is not working.

var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZSCAPP_SRV/",["$filter=val eq '1000940272' and key eq 'Scid'"]);

oTable.setModel(oModel);

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

2) This also gives me all data as before which makes me think that filter is not working with this approach as well.

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

oTable.setModel(oModel);

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

With the definition which you pasted in your reply, I guess the second way of filtering is wrong as I am here trying to filter at client and not at server. Having said that, someone on the blog said that the second way of filtering worked for him.

Qualiture
SAP Mentor
SAP Mentor
0 Likes

Hi Sun,

I believe the 2nd option should be correct, although I;m not sure if you can directly specify a filter in pthe path when doing bindRows().

Alternatively, you could try the following:

var filter = new sap.ui.model.Filter("Scid", sap.ui.model.FilterOperator.EQ, : "12345");

table.bindRows("/TDataset",null,null,[filter]);

NB: Although you specify the filter in the client, the actual filtering takes place on the server, and it will only return the filtered data

sun197895
Participant
0 Likes

Tried Robin...but still getting all rows

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

var filter = new sap.ui.model.Filter("Scid", sap.ui.model.FilterOperator.EQ, "1000940272");

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

oModel.read("/TDataSet", null, filter);

oTable.setModel(oModel);

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

return oTable;

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

Do I need to implement getEntity(Read) method in gateway server ?

jmoors
Active Contributor
0 Likes

If you look in the developer tools, on the network tab, do you see the filter parameters as part of the HTTP request?

Also, have you checked that your oData service supports filtering? http://scn.sap.com/docs/DOC-43000

Regards,

Jason

sun197895
Participant
0 Likes

Hi Jason,

I have attached the screenshot which has the trace. From the trace I can see the filter appended to the URL but not doing the job. I am still getting all the items which means filter is not working. Below is the code I have used.

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

oTable.setModel(oModel);

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

Thanks in advance.

sun197895
Participant
0 Likes

Now if I change the filtering slightly like below then it still load me all the data without filtering. However, in the developer tools I see a message which says that 'I have not implemented 'TDATASET_GET_ENTITY' METHOD. Below is the code which I used and the error message.

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

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

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

2015-01-12 18:28:06 The following problem occurred: HTTP request failed500,Internal Server Error,<?xml version="1.0" encoding="utf-8"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code>SY/530</code><message xml:lang="en">Method 'TDATASET_GET_ENTITY' not implemented in data provider class</message><innererror><transactionid>54A97706DD470A12E10000000A298945</transactionid><timestamp>20150112125759.8021610</timestamp><Error_Resolution><SAP_Transaction>Run transaction /IWFND/ERROR_LOG on SAP NW Gateway hub system and search for entries with the timestamp above for more details</SAP_Transaction><SAP_Note>See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)</SAP_Note></Error_Resolution><errordetails><errordetail><code>/IWBEP/CX_MGW_NOT_IMPL_EXC</code><message>Method 'TDATASET_GET_ENTITY' not implemented in data provider class</message><propertyref/><severity>error</severity></errordetail></errordetails></innererror></error> - 

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

sun197895
Participant
0 Likes

Jason,

to your second question whether OData service supports filtering...

I have checked in the properties in the gateway project and it has the filter option ticked. When I checked the metadata I do not see the filterable attribute....please check below..the filterable attribute for some other properties is 'false' but for Scid it is not showing up. But when I chekedin the Gateway project the property has the filterable check-box checked.

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

<Property Name="Amnt" Type="Edm.String" Nullable="false" MaxLength="20" sap:label="Char20" sap:creatable="false" sap:updatable="false" sap:sortable="false"/>


<Property Name="Scid" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Character Field Length = 10" sap:creatable="false" sap:updatable="false" sap:sortable="false"/>


<Property Name="Zdesc" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Char" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>


<Property Name="Curr" Type="Edm.String" Nullable="false" MaxLength="3" sap:label="3-Byte field" sap:creatable="false" sap:updatable="false" sap:sortable="false"sap:filterable="false"/>


<Property Name="Sctyp" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Character Field Length = 10" sap:creatable="false" sap:updatable="false" sap:sortable="false"sap:filterable="false"/>


<Property Name="Createdby" Type="Edm.String" Nullable="false" MaxLength="20" sap:label="Char20" sap:creatable="false" sap:updatable="false" sap:sortable="false"/>


<Property Name="Pdate" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Character Field Length = 10" sap:creatable="false" sap:updatable="false" sap:sortable="false"sap:filterable="false"/>



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

jmoors
Active Contributor
0 Likes

It's difficult to comment without what you have implemented the oData service, however it looks like you are trying to retrieve an particular entity, rather than the collection, have you implemented the method TDATASET_GET_ENTITY?

Regards,

Jason


jmoors
Active Contributor
0 Likes

Have you changed the filter values, perhaps you need to clear the metadata cache? You could try clearing the cache of the gateway server via transaction /IWFND/CACHE_CLEANUP.

regards,

Jason

sun197895
Participant
0 Likes

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