on 01-16-2018 3:23 PM
Hi,
I want to filter the suggestions on a sap.m.searchField based on a fuzzy search.
In a first step I just try to get the full list with a simple filtering.
I have been able to implement suggestions on the sap.m.searchField and when I enter some characters in the searchField the suggestions that contain the characters are bolded.
But what I want to do is to show only the ones that contain the characters I type and not the other ones. How can I implement it?
I have taken as sample for my development the following sapui5 sample:
https://sapui5.hana.ondemand.com/#/sample/sap.m.sample.SearchFieldSuggestions/preview
And here you have my code.
Definition of the searchField:
<SearchField id="searchField" showRefreshButton="{= !${device>/support/touch} }" tooltip="{i18n>masterSearchTooltip}" width="100%"
search="onSearch"
enableSuggestions="true" suggest="onSuggest"
suggestionItems="{
path: '/bpg',
sorter: { path: 'GroupName' }
}">
<suggestionItems>
<SuggestionItem text="{GroupName}" description="{path: 'GroupCode'}" key="{GroupCode}"/>
</suggestionItems>
</SearchField>
Implementation of the onSuggest.
With the line
searchField.getBinding("suggestionItems").filter(filters);
commented the suggestions are presented without filters.
If I uncomment the line the suggestions are not anymore shown.
onSuggest: function(event) {
var searchField = this.byId("searchField");
var sValue = event.getParameter("suggestValue");
var filters = [];
if (sValue) {
filters = [
new sap.ui.model.Filter([
new sap.ui.model.Filter("GroupName", function(sText) {
return (sText || "").toUpperCase().indexOf(sValue.toUpperCase()) > -1;
}),
new sap.ui.model.Filter("GroupeCode", function(sDes) {
return (sDes || "").toUpperCase().indexOf(sValue.toUpperCase()) > -1;
})
], false)
];
}
//searchField.getBinding("suggestionItems").filter(filters);
searchField.suggest();
},
Do you have an idea where can be the problem?
In a second step I'll try to adapt the sample to work with a Fuzzy Search query but for the moment a simple filtering should be enough.
PS: I have checked the following thread for the fuzzy search but I'll like to keep using the searchField as created by Fiori Master-Detail template instead of using Input.
Thanks in advance for your ideas
Trinidad.
Hi,
Change the onSuggest function as below
onSuggest: function (event) {
var sValue = event.getParameter("suggestValue"),
aFilters = [];
if (sValue) {
aFilters.push(new Filter({
filters: [
new Filter("GroupName", FilterOperator.Contains, sValue.toUpperCase()),
new Filter("GroupCode", FilterOperator.Contains, sValue.toUpperCase())
],
and: false
}));
}
var oSource = event.getSource();
var oBinding = oSource.getBinding('suggestionItems');
oBinding.filter(aFilters);
oBinding.attachEventOnce('dataReceived', function () {
oSource.suggest();
});
},
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.