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

How to Clear and Show/Hide Filters in A two level Rad Grid hierarchy

3 Answers 511 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 17 Sep 2009, 05:10 PM

Folks,

I have Two level hierarchy Rad Grid.  Allow filtering is enabled in both Master/DetailTables. Below codes (which I am using from Telerik Demos) works for Master Table. 

I would like to know is it possible 1) when Filters are cleared in Master Table, Detail Tables Filters are also Cleared; 2) When Filter Show/Hide is checked in Master Table it applies to Detail Table also (i.e. Show/Hide Filters in Detail Table)

I am using RadControls for ASP.NET AJAX Q2 2009  with VS 2008 (Service pack 1)

Thanks a lot.

gc_0620

_________________

1) How to Clear the Filters in Detail Table when Clearing Filters in Master Table.

<asp:Button ID="Button_Clear_Filters" CssClass="form-button" Text="Clear all Filters" OnClick="Button_Clear_Filters_Click"
runat="server"></asp:Button>

 protected void Button_Clear_Filters_Click(object sender, EventArgs e)
    {
        foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
        {
            column.CurrentFilterFunction = GridKnownFunction.NoFilter;
            column.CurrentFilterValue = string.Empty;

        }
        RadGrid1.MasterTableView.FilterExpression = string.Empty;
        RadGrid1.MasterTableView.Rebind();

    }

2) How to Show/Hide Filters in Detail Table when Show/Hide Filters in Master Table.

<td class="style3"  >
       Show filtering item?  <input id="Radio3" type="radio" runat="server" name="showHideGroup" checked="true" onclick="showFilterItem()" /><label for="Radio1">Yes</label>
            <input id="Radio4" type="radio" runat="server" name="showHideGroup" onclick="hideFilterItem()"/><label for="Radio2" >No</label>
       </td>

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

            <script type="text/javascript">
               
                function showFilterItem() {
                    $find('<%=RadGrid1.ClientID %>').get_masterTableView().showFilterItem();
                }
                function hideFilterItem() {
                    $find('<%=RadGrid1.ClientID %>').get_masterTableView().hideFilterItem();
                }
               

            </script>

        </telerik:RadCodeBlock>

3 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 23 Sep 2009, 12:52 PM
Hello  Ghulam,

I recommend that you clear the filters in the detail tables using the following code:
protected void Button_Clear_Filters_Click(object sender, EventArgs e) 
    { 
        foreach (GridColumn column in RadGrid1.MasterTableView.Columns) 
        { 
            column.CurrentFilterFunction = GridKnownFunction.NoFilter; 
            column.CurrentFilterValue = string.Empty; 
 
        } 
        RadGrid1.MasterTableView.FilterExpression = string.Empty; 
        RadGrid1.MasterTableView.Rebind(); 
    LoopHierarchyRecursive(RadGrid1.MasterTableView); 
 
    } 
 
 
void LoopHierarchyRecursive(GridTableView gridTableView) 
   foreach (GridColumn column in gridTableView.Columns) 
        { 
            column.CurrentFilterFunction = GridKnownFunction.NoFilter; 
            column.CurrentFilterValue = string.Empty; 
 
        } 
   gridTableView.FilterExpression = string.Empty; 
   gridTableView.Rebind();   
 
 
   foreach (GridNestedViewItem nestedViewItem in gridTableView.GetItems(GridItemType.NestedView)) 
   {      
 
       if (nestedViewItem.NestedTableViews.Length > 0) 
       { 
    
          LoopHierarchyRecursive(nestedViewItem.NestedTableViews[0]); 
    
       } 
   }  
 

For more information please take a look at the Traversing detail tables/items in Telerik RadGrid help topic.

You can also
Show/Hide Filters in Detail Table when Show/Hide Filters in Master Table using the same logic for traversing the tables.

All the best,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
gc_0620
Top achievements
Rank 1
answered on 23 Sep 2009, 03:27 PM

Thanks Mira for your response. Your answer for question #1 is working fine.
 

I wish you could give me a hand for question #2 (How to Show/Hide Filters in Detail Table when Show/Hide Filters are checked/unchecked in Master Table).  As you notice I am using the same Java  script for Show Hide filters from this Telerik Demo:

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/filtering/defaultcs.aspx
 

I would like to incorporate hide/show filter funcationality for Detail Table within the same Javascript Functions as above demo rather using another button click event. Below is the code for my Detail Table.

<DetailTables>
        <telerik:GridTableView runat="server" DataSourceID="SqlDataSource2" DataKeyNames="UserLocationsPrimaryKey"
                Width="100%"  CommandItemDisplay= "TopAndBottom" Name = "JobPerson"   AllowAutomaticDeletes="true" AllowAutomaticInserts="true"  AllowAutomaticUpdates="true">
 </telerik:GridTableView>
</DetailTables>

 

If it is not possible, then I will have to remove filtering options in Detail Table.

I am using Telerik Controls for less than a year. Still learning process.

Sincerely,

gc_0620

0
Mira
Telerik team
answered on 25 Sep 2009, 12:01 PM
Hi gc_0620,

To show the filters with the previously selected from the user settings, you should save the grid settings on a per user basis as shown in the corresponding help topic and then restore the settings traversing the detail tables as in the Traversing detail tables/items in Telerik RadGrid help topic.

I hope this will help you.

Sincerely yours,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Mira
Telerik team
gc_0620
Top achievements
Rank 1
Share this question
or