Search code examples
xamarinxamarin.formsxamarin.androidxamarin.iostelerik

Telerik control RadAutoComplete is getting reset after updating ItemSource Xamarin


I am using Telerik's RadAutoComplete for having an autocomplete field. It is working fine with static data but on the basis of input received by user in autocomplete field, I have to execute the API and fetch data from there. List received in API response will be visible in autocomplete's suggestion view.

As soon as I am assigning my response to the ItemSource of RadAutoComplete, the text entered in the autocomplete is getting reset. For example: If I want to search "Friday", I entered "Fr" in autocomplete field. After receiving the response from the API that "Fr" will be removed from the autocomplete automatically and autocomplete text will be "".

XAML:

                         <telerikInput:RadAutoComplete
                                    BorderColor="LightGray"
                                    FilteredItemsChanged="autoCompleteUsers_FilteredItemsChanged"
                                    ItemsSource="{Binding UserList}"
                                    SearchThreshold="3"
                                    ShowSuggestionView="True"
                                    SuggestionItemSelected="autoCompleteUsers_SuggestionItemSelected"
                                    TextSearchPath="Name">

                                    <telerikInput:RadAutoComplete.SuggestionItemTemplate>
                                        <DataTemplate>
                                            <StackLayout HeightRequest="20">
                                                <Label
                                                    Margin="2"
                                                    HorizontalOptions="Start"
                                                    Text="{Binding Item.Name}"
                                                    TextColor="Black"
                                                    VerticalOptions="Center" />
                                            </StackLayout>
                                        </DataTemplate>
                                    </telerikInput:RadAutoComplete.SuggestionItemTemplate>
                                </telerikInput:RadAutoComplete>

Event

        void autoCompleteUsers_FilteredItemsChanged(System.Object sender, Telerik.XamarinForms.Input.AutoComplete.FilteredItemsChangedEventArgs e)
        {
            var searchedText = (sender as RadAutoComplete).Text;
            viewController.GetUserList(searchedText);
        }

   
         public async Task GetUserList(string searchedText)
        {
           // **reassigning userList with the response of API**
           UserList = await _APIservice.GetUsers(searchedText);
        }

Solution

  • Try using RadAutoCompleteView, it is recommended for Remote search.

    https://docs.telerik.com/devtools/xamarin/controls/autocompleteview/autocompleteview-remote-search?_ga=2.230265054.335708323.1661762900-2099335098.1639588237