Search Description and Value

4 posts, 0 answers
  1. David
    David avatar
    51 posts
    Member since:
    Nov 2011

    Posted 26 May Link to this post

    I have a requirment where i must allow the user to search the code and the name of the item , I was going to use a keyvalue pair and let the control search both fields but how do i allow it to do it for example for picking list i am using the following an a Picker list control.

    However I want to be able to search both the code and name in the autocomplete view can you tell me how to achieve that.

     

    Say My Class has BomItems

     

    Property string Code {get;set;}

    Property string Name {get;set}

    Code=GYNA
    Name=Back Joint

     

    So if the user where to type in GYNA or Back Joint it would make the code be GYNA of that list

     

    01.warehouses = await database.GetWarehousesFromSage();
    02.     if (!warehouses.IsNullOrEmpty())
    03.     {
    04.         viewModel.Warehouses = warehouses.ToObservableCollection();
    05.         foreach(var warehouse in warehouses)
    06.         {
    07.             if (warehouse.Description =="")
    08.                 warehouse.Description = warehouse.Name;
    09. 
    10. 
    11.             PickerItems.Add(warehouse.WarehouseID.ToString(), warehouse.Description);
    12. 
    13.         }
    14.         pickWarehouse.ItemsSource = PickerItemList;
    15.     }

     

     

     

     

  2. Yana
    Admin
    Yana avatar
    4865 posts

    Posted 27 May Link to this post

    Hello David,

    With RadAutoCompleteView control you can create a custom filtering behavior where to define specific filtering logic - for example to search through more properties of the business object.  Please go through the following documentation topic where the approach is described in details:
    AutoCompleteView Filtering.

    Give it a try and if you have any additional questions, let me know.

    Regards,
    Yana
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. David
    David avatar
    51 posts
    Member since:
    Nov 2011

    Posted 11 Jun in reply to Yana Link to this post

    I understand the code but the documentation is missing the point on how do i hook up the to the xaml in the example xaml it doesn't reference the CustomAutoCompleteViewFilter at all may i ask how do I achieve that.

     

    public class CustomAutoCompleteViewFilter : IAutoCompleteFilter
    {
        public bool Filter(object item, string searchText, CompletionMode completionMode)
        {
            Person person = (Person)item;
            string lowerFirstName = person.FirstName.ToLower();
            string lowerLastName = person.LastName.ToLower();
            string lowerSearchText = searchText.ToLower();
            return lowerFirstName.Contains(lowerSearchText) || lowerLastName.Contains(lowerSearchText);
        }
    }
    Finally, use the
  4. Yana
    Admin
    Yana avatar
    4865 posts

    Posted 11 Jun Link to this post

    Hello David,

    In the CustomFilteringViewModel class there is a Filter property of type CustomAutoCompleteViewFilter  (the class that you've pointed out):

    public class CustomFilteringViewModel
    {
        public CustomFilteringViewModel()
        {
            this.Source = new ObservableCollection<Person>()
            {
               ...
            };
     
            this.Filter = new CustomAutoCompleteViewFilter();
        }
     
        public ObservableCollection<Person> Source { get; set; }
     
        public CustomAutoCompleteViewFilter Filter { get; set; }
    }


    Then, the AutoCompleteView's Filter property 
    is bound to that property of the ViewModel:

    <telerikInput:RadAutoCompleteView x:Name="аutoCompleteView"
                              Filter="{Binding Filter}"
                              TextSearchPath="FirstName"
                              ItemsSource="{Binding Source}"
                              Watermark="Search here..."
                              SuggestionViewHeight="300">

    which actually replaces the default filter behavior with the custom one.

    Let me know if any additional questions arise.

    Regards,
    Yana
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top