Skip to Content
0

Include input suggestions to one of the input fields using odata

Mar 20, 2017 at 06:15 AM

63

avatar image

Hi All,

I am trying to include input suggestions to one of the input fields.

The suggestions should come from the bonded odata.(Model)

I am able to hard core the value and filter it, but not sure how to pass the input the user enters to the odata and get the suggestions.

With this, filters : [ { path : 'Position',operator : 'EQ',value1:'S' } ] }, i am able to see the suggessions that starts with letter "S".

Instead of that, I want to pass user input, how do I do that?

Here's my code:

<Input id="cb11" type="Text" placeholder="Select Position" showSuggestion="true" liveChange="handleSuggest"

suggestionItems="{ path: '/Position_GetListSet', sorter: { path: 'Stext' },

filters : [ { path : 'Position',operator : 'EQ',value1:'S' } ] }" visible= "false" >

<suggestionItems>

<SuggestionItem text="{Stext}" description="{Stext}" key="{Stext}"/>

</suggestionItems>

</Input>

Controller code:

handleSuggest: function(oEvent)

{

var cocdInput = oEvent.getSource();

var aFilters = [];

var sTerm = cocdInput.getValue();

if (sTerm)

{ aFilters.push(new sap.ui.model.Filter("Position", sap.ui.model.FilterOperator.Contains, sTerm));

}

oEvent.getSource().getBinding("suggestionItems").filter(aFilters); cocdInput.setShowSuggestion(true);

cocdInput.setFilterSuggests(false);

cocdInput.removeAllSuggestionItems(); },

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

1 Answer

Best Answer
Somesh Sharma Mar 20, 2017 at 09:46 AM
0

Hi Lalitha,

Please find below the working code.Only need to change the View.

	<Input id="cb11" type="Text" placeholder="Select Position" showSuggestion="true" liveChange="handleSuggest"
				suggestionItems="{ path: '/Position_GetListSet', sorter: { path: 'Stext' }}">
				<suggestionItems>
					<core:Item text="{Stext}" key="{Stext}"/>				
                                </suggestionItems>
			</Input>

For reference please check this link.

Regards,

Somesh

Show 1 Share
10 |10000 characters needed characters left characters exceeded

It's working now.

Thanks for your response:)

0