user8358835
user8358835

Reputation:

Best practice in Xamarin Forms to perform a filter search

I need to perform a filter search with dynamic fields and i am not sure about the best way to do this.

We have a lot of documents with different fields and would like these to be used like a filter search.

Can someone point me in the right direction?

Example of what I am looking to do.

Upvotes: 1

Views: 2150

Answers (1)

zafar
zafar

Reputation: 2064

If you are using MVVM pattern. Here are the steps:

  • Declare ObservableCollection<ItemType> for each of the drop down lists in your ViewModel.
  • Create SelectedType1, SelectedType2 etc. properties for selected values corresponding to each drop down list.
  • Attach SelectionChanged and TextChanged method handlers for each drop down lists in the view which updates the corresponding selection properties in the ViewModel.
  • Delcare ObservableCollection<SearchResultType> SearchResults in the ViewModel which holds the search results for the given search.
  • Declare SearchCommand property in the ViewModel which executes the Search method.
  • Declare Search method which essentially makes a web request call or a local database search query depending on your requirement. This search method now has access to all the drop down selections/text typed by the user.
  • Insert the results obtained in the search method into the SearchResults collection.
  • Bind the SearchResults collection to the ListView.ItemsSource in the View.
  • Bind the SearchCommand to the search action button (top right button in your view).

Happy coding!

Upvotes: 1

Related Questions