Items filtering and search highlighting

10 posts, 1 answers
  1. Alexey
    Alexey avatar
    21 posts
    Member since:
    Aug 2013

    Posted 03 Jul 2014 Link to this post

    Hello
    First of all I'll describe what I want to get. I have a list of items. I need a search in this list and highlighting found text.
    I don't want use CollectionViewSource for filtering, because of its special handing of SelectedItem (IsSynchronizedWithCurrentItem="True" is a bad idea, because I need behavior when no item selected, IsSynchronizedWithCurrentItem="False" also not good because when ListBox.SelectedItem has some value then correcponding item in list is not highlighted).
    The best I've found is JumpList, because it have filters and working with SelectedItem as I want.
    The second problem is search highlighting. In item template I've added RichTextBox with three runs:
    <Run Text="{Binding Name, Converter={StaticResource TextBeforePattern}}" Foreground="{Binding Path=., Converter={StaticResource selectedColorConverter}}"/><Run Text="{Binding Name, Converter={StaticResource TextPattern}}" Foreground="{Binding Path=., Converter={StaticResource searchColorConverter}}"/><Run Text="{Binding Name, Converter={StaticResource TextAfterPattern}}" Foreground="{Binding Path=., Converter={StaticResource selectedColorConverter}}"/>
    Each converter checks return a part of the Name property: text before found pattern, pattern and text after found patter (example, Name="Integration", SearchPattern="gra"; part of text are: "Inte", "gra", "tion").

    But I've found problem: if JumpList item after filtering didn't change its position (e.g. first item in list), then JumpList will not update it and search pattern in this item will not highlighted. Example, list contains items "aaa", "aab", "bcd", "zza"; setting search pattern to "a"; as result "aaa", "aab", "zza"; but becasue of "aaa" and "aab" didn't change their position JumpList will update only "zza" item and only "zza" will get highlighting.

    Any suggestion?
  2. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 07 Jul 2014 Link to this post

    Hello Alexey,

    Thank you for contacting us.

    You can use the RadJumpList.RefreshData() method to force the list to update its data. You may also want to take a look at this article from our online documentation that demonstrates how to use the RadAutoComplete box to filter the items in an external control: http://www.telerik.com/help/windows-phone/radautocompletebox-features-filteredsuggestions.html

    I hope this helps. Please, let us know if you have further questions.

    Regards,
    Rosy Topchiyska
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Alexey
    Alexey avatar
    21 posts
    Member since:
    Aug 2013

    Posted 07 Jul 2014 in reply to Rosy Topchiyska Link to this post

    I used exactly RefreshData() method. But I've described case in which some items are not updating.
    Thanks for link to example. I'll try it
  5. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 10 Jul 2014 Link to this post

    Hi Alexey,

    Unfortunately, we could not reproduce this problem on our side. The RefreshData() method reevaluates the template of each item in the control when called. Could you please send us a sample project that reproduces the issue and we will try to find out where the problems comes from.

    I look forward to your reply.

    Regards,
    Rosy Topchiyska
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Alexey
    Alexey avatar
    21 posts
    Member since:
    Aug 2013

    Posted 10 Jul 2014 in reply to Rosy Topchiyska Link to this post


    Here is example.

    Try to enter only one character in input box (e.g. "b", "bc" etc.). Sometimes it could work, but in most cases - not. Filter is working, items are filtering but templates are not updating

  7. Alexey
    Alexey avatar
    21 posts
    Member since:
    Aug 2013

    Posted 10 Jul 2014 in reply to Alexey Link to this post

    P.S. Rename PhoneApp1.png to PhoneApp1.zip because forum didn't allow me attach archive
  8. Alexey
    Alexey avatar
    21 posts
    Member since:
    Aug 2013

    Posted 10 Jul 2014 in reply to Alexey Link to this post

    I've discovered interesting thing: If I'm using list of s strings as data source then highlighting is ok, all items are updating after calling RefreshData. But of I'm using list of some class instances then not all items are refreshing after RefreshData call.
  9. Answer
    Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 15 Jul 2014 Link to this post

    Hi Alexey,

    Thank you for the project.

    You will have to raise the PropertyChanged() event for the Model items when you wish to update the template of the RadJumpList items. Since the filter descriptor iterates through all items in the ItemsSource, it is convenient to raise the event in the descriptor predicate. I have attached a modified version of your project to demonstrate how to do this:
    • Your Model class inherits from the ViewModelBase class that provides support for property changed notifications and I have added RaisePropertyChanged(..) method.
    • In the filterByName descriptor predicate the Model.RaisePropertyChanged(..) method is called.

    I hope this helps. Please, let us know if you have any other questions.

    Regards,
    Rosy Topchiyska
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Alexey
    Alexey avatar
    21 posts
    Member since:
    Aug 2013

    Posted 15 Jul 2014 in reply to Rosy Topchiyska Link to this post

    Hello
    Thank you for example. This one works as expected.
    Also I want to point that current documentation doesn't have description for this behavior. I mean that with FilterDescriptor not all items in JumpList updates their templates, only items that changed their visibility or position because of filtering.
  11. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 18 Jul 2014 Link to this post

    Hi Alexey,

    Actually, this is the expected behavior of the control. The template is reapplied to all items from the list, but the DataTemplate has bindings only to your model. Since the model data is never changed, and you rely on external mechanism to update the template, the DataTemplate can not know when something has changed and reevaluate its bindings.

    I hope this is useful. Please, let us know if you have further questions.

    Regards,
    Rosy Topchiyska
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
DevCraft banner