How to get the different typenames with custom filter

6 posts, 1 answers
  1. Mads
    Mads avatar
    25 posts
    Member since:
    Nov 2014

    Posted 06 Jan 2015 Link to this post

    If I have a cell with string values
    "value1" "value2" "value3"

    In my custom filter, how do I get these values?

    I have made this custom one, but I have hard coded the values

    CustomItems = new ObservableCollection<CheckBoxCustomFilterType>
    {
        new CheckBoxCustomFilterType { Checked = false, Text = "5016" },
        new CheckBoxCustomFilterType { Checked = true, Text = "25835" }
    };


    I need to get them instead and create a list, how would I retrieve those values? I cant seem to find an example, the date one is not applicably here

    <UserControl
        x:Class="Systematic.KVK.InseminationPlan.UIL.Details.Windows.SemenBucket.CustomFilters.CheckBoxFilterControl"
        xmlns:localization="clr-namespace:Systematic.KVK.InseminationPlan.Localization"
        xmlns:customFilters="clr-namespace:Systematic.KVK.InseminationPlan.UIL.Details.Windows.SemenBucket.CustomFilters"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="300">
        <UserControl.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="/Systematic.KVK.WPFCommon;component/Style/ModernStyles.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </UserControl.Resources>
     
        <Border x:Name="LayoutRoot" BorderThickness="1" BorderBrush="{StaticResource DarkGreenHoverColor}" Padding="5"
                Background="{StaticResource White}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="120" />
                    <ColumnDefinition Width="120" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
     
                <CheckBox Margin="3, 0, 0, 8" Content="{x:StaticExtension localization:SemenBucketTexts.SelectAll}" Click="SelectAll" />
     
                <telerik:RadGridView
                    Name="CheckBoxGridView"
                    Grid.Column="0"
                    Grid.ColumnSpan="2"
                    Grid.Row="1"
                    AutoGenerateColumns="False"
                    CanUserDeleteRows="False"
                    CanUserSelect="False"
                    ShowColumnHeaders="False"
                    CanUserReorderColumns="False"
                    BorderThickness="0"
                    HorizontalAlignment="Left"
                    ItemsSource="{Binding CustomItems}">
                    <telerik:RadGridView.Columns>
     
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=IsSelected}" Header=""
                                                EditTriggers="CellClick" IsReadOnly="True">
                            <telerik:GridViewDataColumn.HeaderCellStyle>
                                <Style TargetType="{x:Type telerik:GridViewHeaderCell}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate>
                                                <CheckBox Margin="3, 0, 0, 8"
                                                    Command="{Binding Path=DataContext.SelectedAllCommand, ElementName=ListTabViewName}"
                                                    IsChecked="{Binding Path=DataContext.ShouldAllBeChecked, ElementName=ListTabViewName}"
                                                    HorizontalAlignment="Left" VerticalAlignment="Center" />
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </telerik:GridViewDataColumn.HeaderCellStyle>
                            <telerik:GridViewDataColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding Path=Checked, Mode=TwoWay}"
                                              Content="{Binding Path=Text}"
                                              HorizontalAlignment="Left" VerticalAlignment="Center" />
                                </DataTemplate>
                            </telerik:GridViewDataColumn.CellTemplate>
                        </telerik:GridViewDataColumn>
     
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
     
                <Button Grid.Column="0" Grid.Row="2" Name="FilterButton"
                        Content="{x:StaticExtension localization:SemenBucketTexts.Filter}" Click="OnFilter" Margin="9" />
                <Button Grid.Column="1" Grid.Row="2" Name="ClearButton"
                        Content="{x:StaticExtension localization:SemenBucketTexts.Clear}" Click="OnClear" Margin="9" />
            </Grid>
        </Border>
    </UserControl>
    Codebehind
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Windows;
    using System.Windows.Controls;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.GridView;
    using Telerik.Windows.Data;
     
    namespace Systematic.KVK.InseminationPlan.UIL.Details.Windows.SemenBucket.CustomFilters
    {
        /// <summary>
        /// Interaction logic for CheckBoxFilterControl.xaml
        /// </summary>
        public partial class CheckBoxFilterControl : IFilteringControl
        {
            public ObservableCollection<CheckBoxCustomFilterType> CustomItems { get; set; }
            private GridViewBoundColumnBase column;
            private CompositeFilterDescriptor compositeFilter;
     
            public CheckBoxFilterControl()
            {
                InitializeComponent();
     
                CustomItems = new ObservableCollection<CheckBoxCustomFilterType>
                {
                    new CheckBoxCustomFilterType { Checked = false, Text = "5016" },
                    new CheckBoxCustomFilterType { Checked = true, Text = "25835" }
                };
                 
                DataContext = this;
            }
     
            private void OnFilter(object sender, RoutedEventArgs e)
            {
                column.DataControl.FilterDescriptors.Clear();
     
                compositeFilter = new CompositeFilterDescriptor();
                compositeFilter.LogicalOperator = FilterCompositionLogicalOperator.Or;
                string dataMember = column.DataMemberBinding.Path.Path;
                foreach (var checkBoxCustomFilterType in CustomItems)
                {
                    if (checkBoxCustomFilterType.Checked)
                    {
                        var filter = new FilterDescriptor(dataMember, FilterOperator.IsEqualTo, checkBoxCustomFilterType.Text);
                        compositeFilter.FilterDescriptors.Add(filter);
                    }
                }
     
                if (!column.DataControl.FilterDescriptors.Contains(compositeFilter))
                {
                    column.DataControl.FilterDescriptors.Add(compositeFilter);
                }
     
                IsActive = true;
            }
     
            private void OnClear(object sender, RoutedEventArgs e)
            {
                column.DataControl.FilterDescriptors.Reset();
     
                IsActive = false;
            }
     
     
            public void Prepare(Telerik.Windows.Controls.GridViewColumn column)
            {
                this.column = column as GridViewBoundColumnBase;
                if (this.column == null)
                {
                    return;
                }
            }
     
            public bool IsActive { get; set; }
     
            private void SelectAll(object sender, RoutedEventArgs e)
            {
                var checkbox = (sender as CheckBox);
                if (checkbox == null || checkbox.IsChecked == null)
                {
                    return;
                }
     
                foreach (var checkBoxCustomFilterType in CustomItems)
                {
                    checkBoxCustomFilterType.Checked = checkbox.IsChecked.Value;
                }
            }
        }
    }
  2. Mads
    Mads avatar
    25 posts
    Member since:
    Nov 2014

    Posted 08 Jan 2015 in reply to Mads Link to this post

    Anyone that can help with this, I need a list of all unique names in the colomn so that I can create my own custom "checkbox style" filter

    So if my custom values are {Name = "name1", Value = 1}, {Name = "name2", Value = 2} etc. then when I create a filter on the Name column, I want to get a list with {"name1", "name2"}
  3. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Jan 2015 Link to this post

    Hi,

    You can always attach to the DistinctValuesLoading event of RadGridView and modify the ones that our data engine has calculated. You can also check the Display All Distinct Values article in our documentation for some sample code on using this event. As to defining a custom filtering control, you can find the Custom Filtering Controls article.

    I will try to elaborate more on how the filtering actually works. It is a data operation which means it is done by building and executing a LINQ query appending proper Where clause over the source collection. 
    For example:
    var result = collection.Where(item => item.Property == "Something");

    So, if you can build such a LINQ query appending Where clause based on the DataMemberBinding or FilterMemberPath set for a column and your custom "checkbox  Style" filter, then RadGridView will also be able to filter the respective column. Otherwise, this will not be possible.

    Regards,
    Dimitrina
    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.

     
  4. Mads
    Mads avatar
    25 posts
    Member since:
    Nov 2014

    Posted 08 Jan 2015 in reply to Dimitrina Link to this post

    With those examples I just get the event, so if I put that in my filter class
    using System.Collections.ObjectModel;
    using System.Windows;
    using System.Windows.Controls;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.GridView;
    using Telerik.Windows.Data;
     
    namespace Systematic.KVK.InseminationPlan.UIL.Details.Windows.SemenBucket.CustomFilters
    {
        /// <summary>
        /// Interaction logic for CheckBoxFilterControl.xaml
        /// </summary>
        public partial class CheckBoxFilterControl : IFilteringControl
        {
            public ObservableCollection<CheckBoxCustomFilterType> CustomItems { get; set; }
            private GridViewBoundColumnBase column;
            private CompositeFilterDescriptor compositeFilter;
     
            public CheckBoxFilterControl()
            {
                InitializeComponent();
     
                CustomItems = new ObservableCollection<CheckBoxCustomFilterType>
                {
                    new CheckBoxCustomFilterType { Checked = false, Text = "5016" },
                    new CheckBoxCustomFilterType { Checked = true, Text = "25835" }
                };
                 
                DataContext = this;
            }
     
            private void OnRadGridViewDistinctValuesLoading(object sender, GridViewDistinctValuesLoadingEventArgs e)
            {
                e.ItemsSource = ((Telerik.Windows.Controls.RadGridView)sender).GetDistinctValues(e.Column, false);
            }
     
            private void OnFilter(object sender, RoutedEventArgs e)
            {
                column.DataControl.FilterDescriptors.Clear();
     
                compositeFilter = new CompositeFilterDescriptor();
                compositeFilter.LogicalOperator = FilterCompositionLogicalOperator.Or;
                string dataMember = column.DataMemberBinding.Path.Path;
                foreach (var checkBoxCustomFilterType in CustomItems)
                {
                    if (checkBoxCustomFilterType.Checked)
                    {
                        var filter = new FilterDescriptor(dataMember, FilterOperator.IsEqualTo, checkBoxCustomFilterType.Text);
                        compositeFilter.FilterDescriptors.Add(filter);
                    }
                }
     
                if (!column.DataControl.FilterDescriptors.Contains(compositeFilter))
                {
                    column.DataControl.FilterDescriptors.Add(compositeFilter);
                }
     
                IsActive = true;
            }
     
            private void OnClear(object sender, RoutedEventArgs e)
            {
                column.DataControl.FilterDescriptors.Reset();
     
                IsActive = false;
            }
     
     
            public void Prepare(Telerik.Windows.Controls.GridViewColumn column)
            {
                this.column = column as GridViewBoundColumnBase;
                if (this.column == null)
                {
                    return;
                }
            }
     
            public bool IsActive { get; set; }
     
            private void SelectAll(object sender, RoutedEventArgs e)
            {
                var checkbox = (sender as CheckBox);
                if (checkbox == null || checkbox.IsChecked == null)
                {
                    return;
                }
     
                foreach (var checkBoxCustomFilterType in CustomItems)
                {
                    checkBoxCustomFilterType.Checked = checkbox.IsChecked.Value;
                }
            }
        }
    }


    If I just add the 
    private void OnRadGridViewDistinctValuesLoading(object sender, GridViewDistinctValuesLoadingEventArgs e)
    method to my filter as shown it will not be fired, where is it I am supposed to hook up to that event? I cant see that in any example, the example only shows those 3-4 lines
  5. Mads
    Mads avatar
    25 posts
    Member since:
    Nov 2014

    Posted 09 Jan 2015 Link to this post

    Fixed it with 

    public void Prepare(Telerik.Windows.Controls.GridViewColumn column)
    {
        this.column = column as GridViewBoundColumnBase;
     
        var distinctValues = ((RadGridView)column.Parent).GetDistinctValues(column, false);
     
        foreach (long distinctValue in distinctValues)
        {
            CustomItems.Add(new CheckBoxCustomFilterType {Checked = false, Text = distinctValue.ToString()});
        }
     
        if (this.column == null)
        {
            return;
        }
    }
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Jan 2015 Link to this post

    Hello,

    You can subscribe for the event initially or in the constructor of the page. Please note this event will be fired once the user clicks on the filtering funnel in column's header to open the filtering control.

    Regards,
    Dimitrina
    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