Skip to Content

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

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)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Mar 16, 2017 at 12:10 PM

    Hi.

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

    Please refer attachment

    scn.png

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 16, 2017 at 09:47 AM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 16, 2017 at 11:30 AM
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 16, 2017 at 01:23 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 17, 2017 at 03:19 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 23, 2017 at 06:34 AM

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

    }

    });

    });

    Add comment
    10|10000 characters needed characters exceeded