cancel
Showing results for 
Search instead for 
Did you mean: 

How to perform Search function in Fori Master List in SAPUI5?

former_member195820
Participant
0 Kudos

Hi all,

I have a MasterPage List and need to perform search in that list. I use XML coding for my view. I tried some code for my search field. But it throws me some error and my list is getting hidden after I perform search.

Here's the code what I have tried:

XML view:

<subHeader>
<Toolbar>
<SearchField id="idSearchSo" search="handleSOSearch"></SearchField>
</Toolbar>
</subHeader>
 <content>
 <List id="idMyRequestList" items="{/GS_Inbox_Pending_ListSet}">
 <items>
<ObjectListItem type="Navigation" title ="{EmployeeName}" 
	number="{AgeingDays}"
	numberUnit="{path: 'CreatedDate',type: 'sap.ui.model.type.Date',formatOptions: {style: 'medium'}}"
	press="handleSOSelect">
<attributes>
<ObjectAttribute text="{EmployeeId}"></ObjectAttribute>
</ObjectListItem>
</items>  
</List>

Controller.js:

handleSOSearch: function(oEvent){	
var aFilters = [];
var sQuery = oEvent.getParameter("query");
var oFilter = new sap.ui.model.Filter("EmployeeName","Contains",sQuery);
aFilters.push(oFilter);
						
var oList = this.getView().byId("idMyRequestList");
var oBinding = oList.getBinding("items");
oBinding.filter(aFilters);
},

Where am I going wrong? can someone help me with this?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi.

In your Odata while creating Entity Type mark property- 'EmployeeName' as Filterable.

Please refer attachment

scn.png

former_member195820
Participant
0 Kudos

Thanks for your reply. I'll ask my Backend team to work on this and will let you know if it works.

former_member195820
Participant
0 Kudos

Thanks for your help.It's working fine now.

Answers (5)

Answers (5)

0 Kudos

view.xml.

........

..........

<ToolbarSpacer/>

<SearchField id="filterQuery" width="50%" placeholder = "Enter a Product ID" search="onFilterProducts"/>

.......

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

controller.js

sap.ui.define([ "sap/ui/core/mvc/Controller",

"sap/ui/model/Filter",

"sap/ui/model/FilterOperator",

"myapp/model/formatter",

"sap/m/GroupHeaderListItem" ], function (Controller, Filter, FilterOperator, formatter, GroupHeaderListItem) {

"use strict"; return Controller.extend("myapp.controller.App", {

formatter: formatter,

......

.........

,

onFilterProducts : function (oEvent) {

// build filter array

var aFilter = [],

sQuery = oEvent.getParameter("query"),

// retrieve list control

oList = this.getView().byId("productsList"),

// get binding for aggregation 'items'

oBinding = oList.getBinding("items");

if (sQuery) { aFilter.push(new Filter("ProductID", FilterOperator.Contains, sQuery)); }

// apply filter; An empty filter array simply removes the filter

// which will make all entries visible again

oBinding.filter(aFilter);

}

});

});

maheshpalavalli
Active Contributor
0 Kudos

Can you check in the backend SAP tcode "/n/iwfnd/error_log"? it might be an issue from the backend, if it is not recorded there just check "st22" for any dumps.

Best Regards,
Mahesh

Former Member
0 Kudos

Hi,

Once try by adding FilterOperator in the Fitlter object like below

var filter = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, query);

former_member195820
Participant
0 Kudos

Hi Sai Ram Dinesh,

I had tried this already.It's not working.

Regards,

Ramya

Former Member
0 Kudos
karthikarjun
Active Contributor
0 Kudos

Will this helpful to you? https://plnkr.co/edit/VDS1xX?p=preview

former_member195820
Participant
0 Kudos

Hi Karthik,

Thanks for your reply. I tried that sample what you gave me. But still I get the same error:-(

karthikarjun
Active Contributor
0 Kudos

Sol1: Fine, Please check your ODATA service entity set. If the given parameter is filterable or not.

Sol2: Else, you should bind the data from ODATA to JSON data to resolve this kind of issues.