RadGrid Clear Filters

22 posts, 0 answers
  1. Chamara
    Chamara avatar
    37 posts
    Member since:
    Jun 2011

    Posted 03 Nov 2011 Link to this post


    I have a telerik RadGrid with AutoGenerateColumns-AtRuntime=true.i need to clear the filters in the radgrid on a button click.i have the following code which is not working

      foreach (GridColumn column in  gridSearchL3.MasterTableView.OwnerGrid.Columns)
           
    {
                column
    .CurrentFilterFunction = GridKnownFunction.NoFilter;
                column
    .CurrentFilterValue = string.Empty;
           
    }
              gridSearchL3
    .MasterTableView.FilterExpression = string.Empty;

    please help.

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 03 Nov 2011 Link to this post

    Hello,


    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="true" AllowFilteringByColumn="true">
                 OnNeedDataSource="RadGrid2_NeedDataSource"
            </telerik:RadGrid>
     
     <asp:Button ID="Button1" runat="server" Text="clear filter" OnClick="Button1_Click" />
    void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       {
           dynamic data = new[] {
                   new { ID1 = 1, ID2 = 2, ID3=3},
                   new { ID1 = 4, ID2 = 5, ID3=6}
                   
               };
           RadGrid2.DataSource = data;
       }


    void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridColumn column in RadGrid2.MasterTableView.OwnerGrid.Columns)
            {
                column.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column.CurrentFilterValue = string.Empty;
            }
            RadGrid2.MasterTableView.FilterExpression = string.Empty;
            RadGrid2.Rebind();
        }

    Note : after remove filter expression we must have to re assign datasource and bind it.

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chamara
    Chamara avatar
    37 posts
    Member since:
    Jun 2011

    Posted 03 Nov 2011 Link to this post

    when the grid is rendered there are nearly 10 auto generated columns in the grid.but when i run the following code and use a breakpoint, it shows the column count as 2 (RadGrid2.MasterTableView.OwnerGrid.Columns). why is it not getting the autogenerated columns.because of this filters are not cleared

    foreach (GridColumn column in RadGrid2.MasterTableView.OwnerGrid.Columns)
            {
                column.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column.CurrentFilterValue = string.Empty;
            }

    following is my radgrid

     <telerik:RadGrid ID="gridSearchL3" runat="server" AllowPagg="True" AutoGenerateColumns="true"  
                 GridLines="None" Skin="Office2007" Height="415px" 
                 OnExcelMLExportRowCreated="gridSearchL3_ExcelMLExportRowCreated" OnExcelMLExportStylesCreated="gridSearchL3_ExcelMLExportStylesCreated"
                OnGridExporting="gridSearchL3_GridExporting"  oninit="gridSearchL3_Init" OnNeedDataSource="RadGrid1_NeedDataSource"
                Font-Names="Eras Medium ITC" Font-Size="Small" PageSize="50" 
                 AllowFilteringByColumn="True" onitemcreated="gridSearchL3_ItemCreated" 
                
                 onselectedindexchanged="gridSearchL3_SelectedIndexChanged" 
                 AllowSorting="True" ShowStatusBar="True" AllowPaging="True">
                   <FilterItemStyle Font-Names="Eras Medium ITC" Font-Size="XX-Small" />
                   <GroupingSettings CaseSensitive="False" />
                <ExportSettings Excel-Format="ExcelML" ExportOnlyData="True" 
                    FileName="PinC Group" IgnorePaging="True" OpenInNewWindow="True">
                    <Excel Format="ExcelML" />
                </ExportSettings>
                <ClientSettings>
                    <ClientEvents OnRowClick="onRowClick" OnRowSelected="RowSelected" />
                    <Selecting AllowRowSelect="True" />
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                </ClientSettings>
                <AlternatingItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                <GroupHeaderItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                <SortingSettings EnableSkinSortStyles="false" /> 
                <MasterTableView ClientDataKeyNames="Document #,Revision,hID,ID" Font-Names="Eras Medium ITC" 
                       Font-Size="X-Small">
               
                    <CommandItemSettings ExportToPdfText="Export to Pdf" />


                    <Columns>


                        <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="template" >
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="ToggleRowSelection" AutoPostBack="true"/>
                            </ItemTemplate>
                            <HeaderTemplate>
                                <asp:CheckBox ID="CheckBoxHeader" OnCheckedChanged="Header_checkedChange" runat="server" AutoPostBack="true"/>
                            </HeaderTemplate>
                        </telerik:GridTemplateColumn>
                    
                        <telerik:GridButtonColumn  Text="View" CommandName="Select" UniqueName="LinkColumn"></telerik:GridButtonColumn>
                    
                    </Columns>
                    <ItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                    <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                    <FilterItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                </MasterTableView>
                <EditItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                <FooterStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                <HeaderStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                <FilterItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                   <CommandItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                   <ActiveItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                   <ItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                   <PagerStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" 
                       HorizontalAlign="Left" Mode="NextPrevNumericAndAdvanced" />
                   <SelectedItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                   <FilterMenu Font-Names="Eras Medium ITC" Font-Size="X-Small" 
                    Skin="Office2007" EnableRoundedCorners="True">
                   </FilterMenu>
                   <HeaderContextMenu Font-Names="Eras Medium ITC" Font-Size="X-Small" 
                       Skin="Simple">
                   </HeaderContextMenu>
                   </telerik:RadGrid>
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 03 Nov 2011 Link to this post

    Hello,

    try with below code snippet.
    foreach (GridColumn column in RadGrid2.MasterTableView.Columns)
    //foreach (GridColumn column in RadGrid2.MasterTableView.AutoGeneratedColumns)
            {
                column.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column.CurrentFilterValue = string.Empty;
            }

    Note : try this code with page_prerener or grid_prerender Event.

    Thanks,
    Jayesh Goyani
  6. Chamara
    Chamara avatar
    37 posts
    Member since:
    Jun 2011

    Posted 03 Nov 2011 Link to this post

    hi!
    thanx for the reply.still no luck.tried adding the code in to both events.still it gets the column count as 2
  7. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 03 Nov 2011 Link to this post

    Hello,

    let me know "RadGrid2.MasterTableView.AutoGeneratedColumns" working or not ?

    Thanks,
    Jayesh Goyani
  8. Chamara
    Chamara avatar
    37 posts
    Member since:
    Jun 2011

    Posted 03 Nov 2011 Link to this post

    hi jayesh!

    got it working.thanx for u'r help.working code is as follows

     foreach (GridColumn column in gridSearchL3.MasterTableView.AutoGeneratedColumns)
            {
                column.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column.CurrentFilterValue = string.Empty;
            }
  9. Amrit
    Amrit avatar
    4 posts
    Member since:
    May 2013

    Posted 14 May 2013 Link to this post

    <

     

     

    tr align="right">

     

     

     

        <td>

     

     

     

            <a href="YourPageName.aspx">Reset Filters</a>

     

     

     

        </td>

     

     

     

    </tr>

     

  10. Calvin
    Calvin avatar
    4 posts
    Member since:
    Apr 2014

    Posted 19 Mar 2015 Link to this post

    Dear Sir,

    The above function works well for standard filter, how about clearing the checkbox filter?

    Thanks.
  11. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 24 Mar 2015 in reply to Chamara Link to this post

    Hello Calvin,

    Is your issue was resolved?

    Thanks,
    Jayesh Goyani
  12. Calvin
    Calvin avatar
    4 posts
    Member since:
    Apr 2014

    Posted 24 Mar 2015 in reply to Jayesh Goyani Link to this post

    Yes. It is resolved.

    Thanks.
  13. Salman
    Salman avatar
    3 posts
    Member since:
    Jul 2014

    Posted 28 Aug 2015 Link to this post

    I am unable to find 

    Gird.masterTableView

  14. Salman
    Salman avatar
    3 posts
    Member since:
    Jul 2014

    Posted 28 Aug 2015 Link to this post

    solved:

    Found some thing regarding telerik Rad gridview Filtering in windows form application I was trying to Remove All filters from radgridview and after a hectic day I found it my self to remove all filters

    if(radgridView1.filterDiscriptor.count>0)
    {
    radgridView1.filterDiscriptor.clear();
    }

    or

    foreach(telerik.windows.data.filterDiscriptor
    fdObejct in radgridview1.filterDiscriptor)
    {
    fdObject.value=string.empty;
    }

  15. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 02 Sep 2015 Link to this post

    Hi Salman,

    The following approach should work for clearing the grid filters:
    foreach (GridColumn column in RadGrid2.MasterTableView.OwnerGrid.Columns)
    {
        column.CurrentFilterFunction = GridKnownFunction.NoFilter;
        column.CurrentFilterValue = string.Empty;
    }
    RadGrid2.MasterTableView.FilterExpression = string.Empty;
    RadGrid2.Rebind();

    These code snippets are applicable to RadGrid control from the Telerik toolkit for ASP.NET AJAX. If you are using another grid control, you should direct your queries in the respective forum section for the technology in question:
    http://www.telerik.com/forums/winforms/gridview

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  16. Urshela
    Urshela avatar
    1 posts
    Member since:
    Jan 2015

    Posted 29 Sep 2015 in reply to Eyup Link to this post

    how do i clear a specific filterexpression but i have 3 columns on my grid 2 textboxes and one dropdown. I have filter all not i want to clear only the dropdown on a button here my code but its not working 

     foreach (GridColumn column in InvoiceItemDisplayGrid.MasterTableView.RenderColumns)
                    {
                        if (column is GridBoundColumn)
                        {
                            GridBoundColumn boundColumn = column as GridBoundColumn;
                            if (boundColumn.DataField.Equals("ConsignorName"))
                            {
                                boundColumn.CurrentFilterFunction = GridKnownFunction.NoFilter;
                                boundColumn.CurrentFilterValue = string.Empty;
                                InvoiceItemDisplayGrid.MasterTableView.Rebind();
                                InvoiceItemDisplayGrid.Rebind();
                                var filterExpression = InvoiceItemDisplayGrid.MasterTableView.FilterExpression.Replace(".ToString()", String.Empty);

                                InvoiceItemDisplayGrid.MasterTableView.FilterExpression = filterExpression;
                                InvoiceItemDisplayGrid.Rebind();
                            }
                        }
                    }

  17. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 02 Oct 2015 Link to this post

    Hi Chamara,

    Please try to use the RenderColumns collection instead as demonstrated in the attached web site samples.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  18. Vinit
    Vinit avatar
    1 posts
    Member since:
    May 2015

    Posted 19 Oct 2015 in reply to Eyup Link to this post

    Both the examples attached are clearing all the filters unlike what the user is asking. I also have a checkbox filter which load with default value of nothing checked, but when it is checked it returns only True filter values. But when unchecked it returns False values only.

     Task Title | Is Allocated

    Task 1 | True

    Task 2 | True

    Task 3 | False

    Task 4 | False

     

    Default view is All rows.

    When Check box checked:(Expected)

     Task Title | Is Allocated
    Task 1 | True
    Task 2 | True

     When Checkbox unchecked (Not correct)

     Task Title | Is Allocated
    Task ​3 | ​False

    Task ​4 | False

     I have code similar to the previous poster and have explicitly cleared the checkbox by using the Column Collections.
     Unsure how we can clear only specific column filters and not all filters.

  19. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 22 Oct 2015 Link to this post

    Hi Vinit,

    You can initiate a filter command with NoFilter function to clear the applied filtering of a single column:
    http://www.telerik.com/forums/radgrid-enable-filter-code-behind#cel1slcp-U-pmV28CfXTrg

    Hope this helps. Please give it a try and let me know if it works for you.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  20. Salim
    Salim avatar
    10 posts
    Member since:
    Apr 2012

    Posted 18 Jan in reply to Eyup Link to this post

    Hi, 

    When I apply a filter to a column, the column become Yellow. 

    When I reset the filter, the filter is reset but the column color remain yellow. 

    How can reset the color also ? 

    Thanks

  21. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 21 Jan Link to this post

    Hello,

    Please try traversing the MasterTableView.RenderColumns or MasterTableView.AutoGeneratedColumns instead and let me know about the result.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  22. Salim
    Salim avatar
    10 posts
    Member since:
    Apr 2012

    Posted 21 Jan in reply to Eyup Link to this post

    Thanks but MasterTableView.RenderColumns and MasterTableView.AutoGeneratedColumns don't work
  23. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 26 Jan Link to this post

    Hello Salim,

    Please download and run the RadGridFilterClearAll.zip and RadGridFilterClearFromClient.zip samples provided in one of my previous posts and let me know about the result.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017