Share via

SearchBar problems

Eduardo Gomez 4,316 Reputation points
2022-03-16T08:33:31.073+00:00

Hello

Can somebody explain to me, why am I experiencing an Issue with my search bar, everything works fine, until I delete a character

 public virtual async void TextToSearchAction(string SeachTerm) {

            if (!string.IsNullOrWhiteSpace(SeachTerm)) {

                var FilteredItems = FireBaseNotebookNotes.Where(item =>
                item.Name.ToLowerInvariant().Contains(SeachTerm.ToLowerInvariant())).ToList();

                FireBaseNotebookNotes.Clear();

                foreach (var Item in FilteredItems) {
                    FireBaseNotebookNotes.Add(Item);
                }

            } else {
                FireBaseNotebookNotes = await App.FirebaseService.ReadAsync(AppConstant.Notebooks);
                SearchBarVisibility = false;
                ProfileVisibility = true;
            }
        }

Demo: https://reccloud.com/u/4m8y3h5

I put a breakpoint and the observable gets clear for some reason, I am adding, when it contains, so why am I experiencing this strange behavior

https://github.com/eduardoagr/DuoNotes/tree/UpdatesToDatabase

Developer technologies | .NET | Xamarin
0 comments No comments

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,971 Reputation points
    2022-03-17T04:08:26.257+00:00

    Hello,​ @Eduardo Gomez

    why am I experiencing an Issue with my search bar, everything works fine, until I delete a character

    This is because the 'FireBaseNotebookNotes' collection has been changed when entering a string. To ensure that the search is performed in the complete data collection, please retrieve the data before searching.

    Here is the sample code, you could refer to it

       public virtual async void TextToSearchAction(string SeachTerm)  
       {  
           if (!string.IsNullOrWhiteSpace(SeachTerm))  
           {  
               FireBaseNotebookNotes = await App.FirebaseService.ReadAsync(AppConstant.Notebooks);//add this line  
         
               var FilteredItems = FireBaseNotebookNotes.Where(item =>  
               item.Name.ToLowerInvariant().Contains(SeachTerm.ToLowerInvariant())).ToList();  
         
               FireBaseNotebookNotes.Clear();  
         
               foreach (var Item in FilteredItems)  
               {  
                   FireBaseNotebookNotes.Add(Item);  
               }  
           }  
           else  
           {  
               FireBaseNotebookNotes = await App.FirebaseService.ReadAsync(AppConstant.Notebooks);  
               SearchBarVisibility = false;  
               ProfileVisibility = true;  
           }  
       }  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.