HighlightTextBlock for Custom Type highlighting search term but not searching.

1 Answer 221 Views
GridView
Brian
Top achievements
Rank 1
Brian asked on 28 Oct 2021, 01:34 AM

I was following the SDK example for Highlighting a Custom Column and got it all implemented.  For mine it is highlighting the correct text but it isn't keeping those rows that should stay in the search results.  My project differs from the example project since I have the Grid bound to a DataTable of various columns and types whereas the example is bound to a list of objects.

My code for the Custom Column is here.  The column is bound to a custom type listed below this code.

publicclassAttributeListColumn: GridViewBoundColumnBase { public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem) { StackPanel mainContainer = new StackPanel { Orientation = Orientation.Horizontal }; if (cell.DataContext != null) { string glyphResourceKey = ((cell.DataContext as System.Data.DataRow)[DataMemberBinding.Path.Path] as ListValueContainer)?.GlyphResourceKey; System.Windows.Shapes.Path path = new System.Windows.Shapes.Path { Margin = new Thickness(0, 0, 5, 0), Fill = System.Windows.Media.Brushes.Black, Width = 13, Height = 13, Data = glyphResourceKey == null ? null : Application.Current?.TryFindResource(glyphResourceKey) as System.Windows.Media.Geometry, Visibility = glyphResourceKey == null ? Visibility.Collapsed : Visibility.Visible }; mainContainer.Children.Add(path); } //Add HighlightTextBlock to keep the SearchPanel functionality HighlightTextBlock htb = new HighlightTextBlock(DataControl.SearchStateManager); htb.SetBinding(HighlightTextBlock.HighlightTextProperty, new Binding($"[{DataMemberBinding.Path.Path}].Id")); cell.SetBinding(GridViewCell.IsHighlightedProperty, new Binding("ContainsMatch") { Source = htb, Mode = BindingMode.TwoWay }); SetHighlightTextBlockTextProperty(dataItem, htb); mainContainer.Children.Add(htb); return mainContainer; } public void SetHighlightTextBlockTextProperty(object dataItem, TextBlock textBlock) { if (this.DataMemberBinding != null) { var content = this.GetCellContent(dataItem); if (content != null) { textBlock.SetValue(TextBlock.TextProperty, (content as ListValueContainer).Id); } } else { textBlock.ClearValue(TextBlock.TextProperty); } } }


[TypeConverter(typeof(ListValueConverter))]
    public class ListValueContainer : IComparable, IEquatable<ListValueContainer>, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected string glyphResourceKey;
        protected List<string> values = new List<string>();

        public ListValueContainer()
        {
        }

        public ListValueContainer(string value, string glyphResourceKey = null)
        {
            values.Add(value);
            this.glyphResourceKey = glyphResourceKey;
        }

        public ListValueContainer(List<AttributeListLookup> lookupValues, string glyphResourceKey = null)
        {
            if (lookupValues != null)
            {
                lookupValues.ForEach(a => values.Add(a.Id));
            }
            this.glyphResourceKey = glyphResourceKey;
        }

        public string GlyphResourceKey
        {
            get
            {
                return glyphResourceKey;
            }
        }

        public List<string> Values
        {
            get
            {
                return values;
            }
        }

        public string Id
        {
            get
            {
                return string.Join(", ", values);
            }
        }

        public virtual void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, args);
            }
        }
}

Like I said the correct text highlights as you type in the GridView search bar, but those cells aren't actually getting filtered.

 

The HighlightTextBlock.HighlightTextProperty is being bound correctly but I'm guessing the GridViewCell.IsHighlightedProperty is what says if the row should stay in the GridView as you are typing?

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 01 Nov 2021, 01:59 PM

Hello Brian,

This seems related to the following case in the feedback portal. In summary, the highlighting doesn't work as expected because the search as you type filtering doesn't work. This happens, basically, because the expression tree we create internally for the filtering doesn't support nested paths that contain both CLR and dynamic properties.

To resolve this, you can use a few approaches:

  • Avoid using the ListValueContainer object and provide the corresponding properties (like Id) directly as columns in the DataTable.
  • Use business objects (like ObservableCollection<Club> from the example), instead of DataTable.
  • Try the alternative mentioned in the feedback item (with the ICustomTypeProvider).

Can you please try those suggestions and let me know how it goes?

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Brian
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or