Skip to Content
avatar image
Former Member

How to load suggestion model only when onSuggest triggered

Hi,

we have a lot of input fields with suggestion functionality on one page.

The suggestion models (aggregations) are loaded on start (initial loading).

How is it possible to load the suggestions on typing or on focus?

I tried following:

<Input
				id="productInput"
				type="Text"
                                value="anotherModel"
				placeholder="Enter Product ..."
				showSuggestion="true"
				suggest="handleSuggest">
			</Input>

and:

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

If this is possible, the binding should only processed once.

Or binding should processed onFocus...

Thanks,

Martin

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 20, 2017 at 04:06 AM

    Add suspended property in your element binding.

    <Input
         id="productInput"
         type="Text"
         value="anotherModel"
         placeholder="Enter Product ..."
         showSuggestion="true"
         suggest="handleSuggest"
         suggestionRows = "{path: 'ProductSet',
    			suspended: true}"	
    >
    </Input>

    And in the event where you want to load the data add the resume call

    handleSuggest : function(oEvent){
         var sTerm = oEvent.getParameter("suggestValue");
         var aFilters = [];
         if (sTerm) {
              aFilters.push(new Filter("SEARCH", sap.ui.model.FilterOperator.Contains, sTerm));
         }
         oEvent.getSource().getBinding("suggestionRows").filter(aFilters);
         oEvent.getSource().getBinding("suggestionRows").resume();
    },
    
    Add comment
    10|10000 characters needed characters exceeded

  • Feb 17, 2017 at 06:32 PM

    Hello Martin,

    A quick question . When you mean lot of suggestion models, you are referring to model bindings on search field and not services themselves right. In other words the underlying odata for all suggestions are all the same. When you say binding should only be processed once it depends on how you you need it.

    In case you only binding once then you need to pull all the data at once and further suggestions should be triggered from client side. So you can use a client side model like jsonmodel. Else like traditional application fire the server side odata model and pull only data that comply to the search query.

    You also have a client mode odataModel and find more info here .

    Thanks and Regards,

    Veera

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      each input field has his own suggestion-model. And loading all models once would affect the performance.

      So the goal ist to load these models after initial load, when the user needs it. The solution with suspended: true is nice, but not working yet.

      Thanks and regards,

      Martin

  • avatar image
    Former Member
    Feb 18, 2017 at 06:15 PM

    Hi Martin,

    Attach browser based focus event to the input in onAfterRendering method. Which will set the model only after focusing the Input.

    Use the handleSuggest method as it is because you need to filter the data on entering in the input.

    onAfterRendering: function()
    {
         var oInput = this.getView().byId(“oInput”);
        oInput.attachBrowserEvent(“focus”,
              function(event){
                  var oModel = new sap.ui.model.odata.OdataModel(url); 
                  // this model is for your reference , use the model that you want to use
                  oInput.setModel(oModel); // set the model that you want to use
              });
     var oInput2 = this.getView().byId(“oInput2”);
        oInput.attachBrowserEvent(“focus”,
              function(event){
                       oInput2.setModel(oModel2); // set the model that you want to use
              });
    }
    Add comment
    10|10000 characters needed characters exceeded