cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 search on DataSet

Former Member
0 Kudos

Hi there, I would like to know, if someone has managed to implement a search in the DataSet control, that works like the suggest event in the normal searchField? The DataSet has only a search event, that get fired after hitting "enter".

Any suggestions? Thx

View Entire Topic
WouterLemaire
Active Contributor
0 Kudos

Hi,

Put following code in the search event

var sQuery = oEvent.getParameter("query");

var oBinding = oDataSet.getBinding("items");

oBinding.filter(!sQuery ? [] : [new sap.ui.model.Filter("title", sap.ui.model.FilterOperator.Contains, sQuery)]);

oDataSet.setLeadSelection(-1);

Here you have an example:

https://sapui5.hana.ondemand.com/sdk/#test-resources/sap/ui/ux3/demokit/DataSet.html

Kind regards,

Wouter

Former Member
0 Kudos

Hi Wouter, thank you for the reply, Your code is for searching the data set and it's already in and working. But my problem was the "search" event itself. It get fired after pressing the ENTER key and I was looking for a solution to make it work after entering a charachter. I'm missing a  "suggest" event.

Kind regards, Chis

angel_dichev
Active Participant
0 Kudos

One way to do that is to create a new search object

sap.ui.commons.SearchField

and implement the attachSuggest method

something like this

var search = new sap.ui.commons.SearchField(

         "mySearch", {

          enableListSuggest : false,

          enableClear : true,

          startSuggestion : 0,

          value :  "Search"

         });

search.attachSuggest(function(oEvent) {

        oController._searchMe(oEvent

          .getParameter("value"));

       }, oController)

in controller

_searchMe = function (query) {

     //get DS object and apply the filter you mentioned above

     //filtering will be triggered be on a keystroke

}