"dettaching" custom row filter

4 posts, 0 answers
  1. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 13 Jul 2009 Link to this post

    Hello,

    I'd like to allow user enable or disable the custom row filter using a togglebutton. Based on your example source code, I'm able to enable the row filter when togglebutton is checked, but is there any esay way to restore the gridview, that's removing , or dettaching, the row filter?
    Thanks.
    Daní
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 13 Jul 2009 Link to this post

    Hello Daní,

    You can use the FilterDescriptors property of the grid in order to define and undefine filtering. Here is how to do it from a checkbox:

    <UserControl x:Class="Ticket226810.Page" 
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
                   xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
        <Grid> 
          <Grid.RowDefinitions> 
            <RowDefinition Height="Auto"/> 
            <RowDefinition Height="Auto"/> 
          </Grid.RowDefinitions> 
          <CheckBox Name="englishOnlyCheckBox"  
                    Margin="10"  
                    Content="English Players Only"  
                    Checked="OnEnglishOnlyChecked"  
                    Unchecked="OnEnglishOnlyUnchecked" /> 
          <telerik:RadGridView Name="playersGrid"  
                               Grid.Row="1"  
                               AutoGenerateColumns="False" 
                               ColumnsWidthMode="Auto"
                <telerik:RadGridView.Columns> 
                    <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"
                    </telerik:GridViewDataColumn> 
                    <telerik:GridViewDataColumn Header="Number" DataMemberBinding="{Binding Number}"
                    </telerik:GridViewDataColumn> 
                    <telerik:GridViewDataColumn Header="Position" DataMemberBinding="{Binding Position}"
                    </telerik:GridViewDataColumn> 
                    <telerik:GridViewDataColumn Header="Country" DataMemberBinding="{Binding Country}"
                    </telerik:GridViewDataColumn> 
                </telerik:RadGridView.Columns> 
            </telerik:RadGridView> 
        </Grid> 
    </UserControl> 
     

    And the event handlers:

    using System.Windows.Controls; 
    using Telerik.Windows.Controls; 
    using Telerik.Windows.Data; 
     
    namespace Ticket226810 
        public partial class Page : UserControl 
        { 
            public Page() 
            { 
                InitializeComponent(); 
     
                this.playersGrid.ItemsSource = Club.GetPlayers(); 
            } 
     
            void OnEnglishOnlyUnchecked(object sender, System.Windows.RoutedEventArgs e) 
            { 
                this.playersGrid.FilterDescriptors.Clear(); 
            } 
     
            void OnEnglishOnlyChecked(object sender, System.Windows.RoutedEventArgs e) 
            { 
                this.playersGrid.FilterDescriptors.Add(new FilterDescriptor("Country", FilterOperator.IsEqualTo, "England")); 
            } 
        } 
     

    I have attached the small sample project that the above code snippets are from. You can use it as a starting point and build on it. Please, let me know if you have any problems or other questions.

    Kind regards,
    Ross
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 13 Jul 2009 Link to this post

    Thanks Ross for your quick response but is not what exactly meant. What I did was to reproduce your custom row filtering example. So, a filter row appears. What I want is to be abe to remove the filtering row from the GridView Header.
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 14 Jul 2009 Link to this post

    Hello Daní,

    Now I see what you mean. Unfortunately, this task is far from trivial, since the header cells were modified quite a bit.  However, we have gone the extra mile and come up with a possible solution for this problem. The only solution I can think of is to save all custom elements that were added and all original elements that were removed in some kind of class field and then show / hide them according to the toggle button. I have taken our sample and extended it quite a lot in order to achieve something similar. Have in mind that this is not a full-blown solution, but it can serve as a foundation for further fine tuning. You may need to tweak it or add additional logic in order to tailor it to your needs.

    I have attached the sample project. The places of interest are the Enable and Disable methods of the GridViewFilterRow. Basically, on Enable I show the custom elements and hide the original ones and on Disable I do the opposite. This should get you started. I hope it helps.

    Sincerely yours,
    Ross
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top