0

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

Mar 16 at 08:51 AM

247

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?

capture.png (179.0 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

6 Answers

Best Answer
Pareen Karpe Mar 16 at 12:10 PM
0

Hi.

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

Please refer attachment

scn.png


scn.png (17.6 kB)
Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

0

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

0
Karthik A Mar 16 at 09:47 AM
0

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Karthik,

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

0

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.

0
Kuldeep Singh Mar 16 at 11:30 AM
0
Share
10 |10000 characters needed characters left characters exceeded
Sai Ram Dinesh Pallapotu Mar 16 at 01:23 PM
0

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);

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Sai Ram Dinesh,

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

Regards,

Ramya

0
Mahesh kumar palavalli Mar 17 at 03:19 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Michael Devine Mar 23 at 06:34 AM
0

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);

}

});

});

Share
10 |10000 characters needed characters left characters exceeded