Skip to Content
0

How to load suggestion model only when onSuggest triggered

Feb 17, 2017 at 03:33 PM

125

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

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

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();
},
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0
Former Member
Former Member

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

0
Veeraraghavan Narasimhan
Feb 17, 2017 at 06:32 PM
0

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

Show 1 Share
10 |10000 characters needed characters left 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

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

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
          });
}
Share
10 |10000 characters needed characters left characters exceeded