This is a migrated thread and some comments may be shown as answers.

"dettaching" custom row filter

3 Answers 107 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daní
Top achievements
Rank 1
Daní asked on 13 Jul 2009, 02:02 PM
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í

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 13 Jul 2009, 03:17 PM
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.
0
Daní
Top achievements
Rank 1
answered on 13 Jul 2009, 03:49 PM
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.
0
Rossen Hristov
Telerik team
answered on 14 Jul 2009, 11:39 AM
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.
Tags
GridView
Asked by
Daní
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Daní
Top achievements
Rank 1
Share this question
or