cancel
Showing results for 
Search instead for 
Did you mean: 

How to load suggestion model only when onSuggest triggered

martin_zaman
Explorer
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

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();
},
martin_zaman
Explorer
0 Kudos

That would be the most elegant solution, however the suggestion-model is loading with suspended: true on initial page-load.

martin_zaman
Explorer
0 Kudos

ahh suspend functionality is since 1.38/1.40... Im using 1.28 🙂

Answers (2)

Answers (2)

0 Kudos

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
          });
}
former_member228602
Contributor
0 Kudos

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

martin_zaman
Explorer
0 Kudos

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