Skip to Content

Dynamic SuggestionItem not working for contains filter

Hi All,

I tried to follow SAPUI5 demo on dynamic suggestion item whereby on event "suggest" I add new filter for the suggestion item binding.

The link to the demo is here: Sample: Input - Suggestions - Dynamic

The only difference with the sample is I am using oData model instead of Json and I use Contains as the Filter Operator.

handleSuggest: function(oEvent) {
                        var sTerm = oEvent.getParameter("suggestValue");
                        var aFilters = [];
                        if (sTerm) {
                            aFilters.push(new Filter("CompanyName", sap.ui.model.FilterOperator.Contains, sTerm));
                        }
                        oEvent.getSource().getBinding("suggestionItems").filter(aFilters);
                    }

When I debug the oData service in the backend, I notice getEntitySet return correctly based on the filter.

However, it seems like the input field behaviour still only show the result based on Start With filter because it will only suggest records that start with the search term that I typed.

Is the example given by SAP only applicable for StartsWith filter?

If yes, I found it quite redundant because the suggestion items itself already use Start With condition as default.

Is there a way to force my new filter result to be used as suggestion items shown for this specific input?

Thank you.

Regards,

Abraham

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Dec 10, 2015 at 03:12 AM

    Hi Abraham,

    According to sap.m.Input code, I guess the default filter is set to 'StartsWith' filter operator.

    I didn't find a way to change it, as you already mentioned if we go through explored sample even that way it is not working. However you can raise this as an issue and check with UI5 team? Issues · SAP/openui5 · GitHub

    Regards,

    Sai Vellanki.


    Capture.PNG (16.8 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 09, 2015 at 07:06 AM

    Hi All,

    It is quite odd that I asked based on SAP sample but seems like no suggestion yet about this.

    Is it because my question is not clear enough or more information needed?

    Thank you.

    Regards,

    Abraham

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 09, 2015 at 09:25 PM

    not working here.

    i end up with using SelectDialog


    Add a comment
    10|10000 characters needed characters exceeded

    • Thank you everyone for the response.

      Hmm, so it seems like it is also not working for everyone.

      I plan to use SelectDialog also but feels like user experience will be better if user can just type in whatever they think of and the system display records that contains that search term.

      It would be good if SAP can confirm that this sample that they give is only working for StartWith filter and not for any other filter even though it is quite redundant because without this filter the suggestionItem already work with beginsWith in the first place.

  • author's profile photo Former Member
    Former Member
    Posted on Sep 16, 2016 at 04:03 PM

    Hi Abraham,


    thanks a lot for your nice solution 😊

    You solved my problem with suggestions, now I have what I need 😊

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 16, 2016 at 05:04 PM

    Hi Former Member / @Abraham Bukit,

    I am not sure, why I haven't provided a proper answer for this question. 😭

    More robust way to achieve this kind of requirement would be extending Input control to accept 'contains' as suggestion filter.


    Will this sample help? Plunker

    You can type any of the below values:


              var aData = [{
                "Name": "Power Projector 4713"
              }, {
                "Name": "Power Tag"
              }, {
                "Name": "Webcam Small"
              }, {
                "Name": "Webcam"
              }, {
                "Name": "Monitor Locking Cable"
              }, {
                "Name": "Laptop Case"
              }, {
                "Name": "Laptop Small"
              }, {
                "Name": "USB Stick 16 GByte"
              }, {
                "Name": "Deskjet Super Highspeed"
              }, {
                "Name": "Deskjet Super1"
              }, {
                "Name": "Deskjet Super2"
              }];
    

    Regards,

    Sai.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.