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
Chandrashekhar Mahajan replied
here you are binding aggregation to table. it means bindRows expect entity collection which is /UserInfoSampleSet. hence the call will go to get_entityset method of DPC_EXT class.
you can put the filter logic in get_entityset method and then get the value of UserID and accordingly get the filtered data into collection
|OData Query||Method Parameter||Alternative way to get the value||Coding required to implement Query Operation|
|UserCollection?$filter=UserID eq '123' and LastName eq 'Mahajan'||IT_FILTER_SELECT_OPTIONS and IV_FILTER_STRING||DATA: my_filter_options TYPE/iwbep/t_mgw_select_option,|
my_filter_string TYPE string.
my_filter_options =io_tech_request_context->get_filter( )->get_filter_select_options( ).
my_filter_string = io_tech_request_context->get_filter( )->get_filter_string( ).
As mentioned in the table, you will get the value in method importing parameter or by using code provided in alternative way. Check the code in How to Develop Query Options for an OData Service Using Code-Based Implementation
put external breakpoint in method get_entityset and accordingly put the logic. once you will get the UserID say in variable lv_userid, pass it to select query as below
DATA: lt_userinfo TYPE TABLE OF zuserinfo,
ls_userinfo LIKE LINE OF lt_userinfo,
ls_entity LIKE LINE OF et_entityset.
*Get data from ZUSERINFO table
SELECT * FROM zuserinfo INTO TABLE lt_userinfo where userid = lv_userid.
LOOP AT lt_userinfo INTO ls_userinfo .
ls_entity-userid = ls_userinfo-userid.
ls_entity-firstname = ls_userinfo-firstname.
ls_entity-lastname = ls_userinfo-lastname.
ls_entity-email = ls_userinfo-email.
ls_entity-phone = ls_userinfo-phone.
ls_entity-country = ls_userinfo-country.
APPEND ls_entity TO et_entityset.