Reputation: 71
I want to create a custom Suggestion for a input field in SAPUI5. I managed to create a tabular suggestion which include 3 columns {Name
, AdName
, Telno
}.
This is my code:
<Input id="_txtCustomerName" liveChange="liveChange" placeholder="{i18n>customername}" showTableSuggestionValueHelp="false"
suggestionItemSelected="suggestionSelected" startSuggestion="1" showSuggestion="true" suggest="suggest" suggestionRows="{/results}" >
<suggestionColumns>
<Column hAlign="Begin" popinDisplay="Inline" demandPopin="true">
<Label text="{i18n>customername}"/>
</Column>
<Column hAlign="Center" popinDisplay="Inline" demandPopin="true" minScreenWidth="Tablet">
<Label text="{i18n>address}"/>
</Column>
<Column hAlign="End" popinDisplay="Inline" demandPopin="true">
<Label text=" {i18n>phoneno}"/>
</Column>
</suggestionColumns>
<suggestionRows>
<ColumnListItem>
<cells>
<Label text="{Name}"/>
<Label text="{AdName}, {City}"/>
<Label text="{Telno}"/>
</cells>
</ColumnListItem>
</suggestionRows>
</Input>
It loaded the data from ABAP server to the SuggestionRows property properly, the only filtered by Name
. Now I want to filter the suggestionTable by Name
and Telno
as well. Any suggestion ?
P/s: I tried to follow a guide from this thread: https://archive.sap.com/discussions/thread/3811696 but it seems not working for me.
suggest: function(oEvent) {
var sValue = oEvent.getParameter("suggestValue");
var filters = new sap.ui.model.Filter([
new sap.ui.model.Filter("Name",
sap.ui.model.FilterOperator.Contains,
sValue),
new sap.ui.model.Filter("Telno",
sap.ui.model.FilterOperator.Contains,
sValue)
], false);
oEvent.getSource().getBinding("suggestionRows").filter(
[filters]);
}
it returns undefind for oEvent.getSource().getBinding("suggestionRows")
, means I can't find the suggestionRows
aggregation.
Upvotes: 0
Views: 1726
Reputation: 3994
The sap.m.Input control will filter the data by "Name" even if you add your own filter. You will have to disable the default filters & add your own filter logic. You can disable it by changing the filterSuggests property to false.
<Input id="_txtCustomerName" filterSuggests="false" ....
This will disable the default filtering logic used by the control as mentioned here. Now your custom filter logic should work.
Upvotes: 1