on 02-17-2017 3:33 PM
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 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();
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
});
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.