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

Clearing Parent / child only filter from code on 2012Q2

3 Answers 88 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sintayehu
Top achievements
Rank 1
Sintayehu asked on 20 Jun 2013, 09:06 PM

I am implementing a functionality that would allow users to clear Grid filtering for either Parent only or Child only grids.

I have a Hierarchical Grid and am using exampleGrid.FilterDescriptors.Clear(); on a button click.

My problem is
1 - that this wipes out all filtering on Parent and nested Grid. But I would like to clear filter only for parent or child.

2 - Another issue with the method I am calling is that even though it clear the filter the filter text boxes are not cleared automatically.

Any help is appreciated.

Here is my sample:

            I am basically calling " Parent / child Grid ".FilterDescriptors.Clear();


<telerik:RadGridView x:Name="ExampleGridView" FilteringMode="FilterRow" IsFilteringAllowed="True" CanUserSortColumns="True" ShowGroupPanel="True" ShowGroupFooters="True" Grid.Row="0" AutoGenerateColumns="False" ItemsSource="{Binding **somesource**}">


                <telerik:RadGridView.Columns>

                    <telerik:GridViewDataColumn DataMemberBinding="{Binding **}" Header="**" UniqueName="**"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding **}" Header="**" UniqueName="**"/>

                </telerik:RadGridView.Columns>

                <telerik:RadGridView.HierarchyChildTemplate>
                    <DataTemplate >
                        <telerik:RadGridView x:Name="ExampleChildGridView" 
                                     ItemsSource="{Binding ***}" 
                                     AutoGenerateColumns="False" ShowColumnFooters="True" CanUserSortColumns="True" IsFilteringAllowed="True" FilteringMode="FilterRow">

                                                        
<telerik:RadGridView.Columns>

<telerik:GridViewDataColumn DataMemberBinding="{Binding **}" Header="**" UniqueName="**"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding **}" Header="**" UniqueName="**"/>

</telerik:RadGridView.Columns>

                        </telerik:RadGridView>
                    </DataTemplate>
                </telerik:RadGridView.HierarchyChildTemplate>

                <telerik:RadGridView.ChildTableDefinitions>
                    <telerik:GridViewTableDefinition>
                        <telerik:GridViewTableDefinition.Relation>
                            <data:PropertyRelation ParentPropertyName="**SomeSource**" />
                        </telerik:GridViewTableDefinition.Relation>
                    </telerik:GridViewTableDefinition>
                </telerik:RadGridView.ChildTableDefinitions>


            </telerik:RadGridView>


3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 25 Jun 2013, 02:32 PM
Hello,

When a filtering is applied, or the FilterDescriptors of the GridView are cleared, then the entire View is re-created. That is why the hierarchical GridViews are recreated from scratch and all their descriptors are lost. To keep the filtering assigned for the hierarchy, you could subscribe for the RowLoaded and RowUnloaded events of the RadGridView and save all the additional settings/FilterDescriptors you would like to.

As to your second problem, this is the result as you clear the entire FilterDescriptors collection and not the descriptors per column. You can check this forum thread where the same issue has been discussed. 

Regards,
Didie
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sintayehu
Top achievements
Rank 1
answered on 28 Jun 2013, 02:12 PM

Thanks. I didn't have to save the nested filter descriptors and apply them back on row loaded.

However If it ever helps any one I have a snippet below.

1- Create a RadContext Menu for the RadGridView GridViewHeaderRow- good example on Demo site

2 - Get the current RadGridView as a parent of the clicked GridViewHeaderRow Item

example if the clicked item is 
            var header = menu.GetClickedElement<GridViewHeaderRow>();

           var currentRadGridView = header.ParentOfType<RadGridView>();  //Current can be parent or nested grid

            if (currentRadGridView != null)
            {
                //The RadMenuItem that will get added to the context menu
                var resetfilter= new RadMenuItem
                {
                    Header = "Reset Filter"
                };

                resetfilter.IsEnabled = currentRadGridView.FilterDescriptors.Count >= 1;

                //Hierarchical grids only
                if (currentRadGridView.HasHierarchy)
                {
                    var parentRadGridView = currentRadGridView; //current grid is a parent

                    // Enables clear Filter menu on parent grid if any child grid has filter
                    foreach (RadGridView nestedGridView in parentRadGridView.ChildrenOfType<RadGridView>())
                    {
                        if (nestedGridView.FilterDescriptors.Count >= 1)
                        {
                            resetfilter.IsEnabled = true
                            break;
                        }
                    }
                }
                
                //Menu is the RadContext Menu that is attached to the GridViewHeader

                menu.Items.Add(resetfilter);

                //Handles the reset filter menu click
                resetfilter.Click += (o, args) =>
                    {
                        currentRadGridView.FilterDescriptors.SuspendNotifications();

                        foreach (Telerik.Windows.Controls.GridViewColumn column in currentRadGridView.Columns)
                        {
                            column.ClearFilters();
                            currentRadGridView.FilterDescriptors.Clear();
                        }

                        currentRadGridView.FilterDescriptors.ResumeNotifications();

                        //In my case I use an attached behavior to select / remove operators , but when clearing filters the operators default back to origional setting and not to what the behavior set them on initial load. So to fake a Filter loading and filter created events I am saving my current Filtering mode and set the current filter mode to what it wasn't and putting it back to what it was. :)

                        FilteringMode currentFilteringMode = currentRadGridView.FilteringMode;

                        currentRadGridView.FilteringMode = (currentRadGridView.FilteringMode.Equals(FilteringMode.Popup)) ? FilteringMode.FilterRow : new FilteringMode(); //Triggers Filter loading in attached behaviour see GridViewFilterBehavior

                        currentRadGridView.FilteringMode = currentFilteringMode;

                    };
            }

0
Dimitrina
Telerik team
answered on 01 Jul 2013, 07:42 AM
Hello,

Thank you for sharing your solution with the community.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Sintayehu
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Sintayehu
Top achievements
Rank 1
Share this question
or