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

RadGrid Clear Filters

23 Answers 2170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chamara
Top achievements
Rank 1
Chamara asked on 03 Nov 2011, 11:21 AM

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.

23 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Nov 2011, 11:32 AM
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
0
Chamara
Top achievements
Rank 1
answered on 03 Nov 2011, 01:47 PM
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>
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Nov 2011, 01:53 PM
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
0
Chamara
Top achievements
Rank 1
answered on 03 Nov 2011, 02:01 PM
hi!
thanx for the reply.still no luck.tried adding the code in to both events.still it gets the column count as 2
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Nov 2011, 02:15 PM
Hello,

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

Thanks,
Jayesh Goyani
0
Chamara
Top achievements
Rank 1
answered on 03 Nov 2011, 05:13 PM
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;
        }
0
Amrit
Top achievements
Rank 1
answered on 14 May 2013, 07:23 AM

<

 

 

tr align="right">

 

 

 

    <td>

 

 

 

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

 

 

 

    </td>

 

 

 

</tr>

 

0
Calvin
Top achievements
Rank 1
answered on 20 Mar 2015, 03:50 AM
Dear Sir,

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

Thanks.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Mar 2015, 05:57 PM
Hello Calvin,

Is your issue was resolved?

Thanks,
Jayesh Goyani
0
Calvin
Top achievements
Rank 1
answered on 25 Mar 2015, 02:00 AM
Yes. It is resolved.

Thanks.
0
Salman
Top achievements
Rank 1
answered on 28 Aug 2015, 11:24 AM

I am unable to find 

Gird.masterTableView

0
Salman
Top achievements
Rank 1
answered on 28 Aug 2015, 02:47 PM

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;
}

0
Eyup
Telerik team
answered on 02 Sep 2015, 10:55 AM
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
0
Urshela
Top achievements
Rank 1
answered on 29 Sep 2015, 08:09 AM

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();
                        }
                    }
                }

0
Eyup
Telerik team
answered on 02 Oct 2015, 06:39 AM
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
0
Vinit
Top achievements
Rank 1
answered on 19 Oct 2015, 10:32 AM

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.

0
Eyup
Telerik team
answered on 22 Oct 2015, 08:22 AM
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
0
Salim
Top achievements
Rank 1
answered on 18 Jan 2016, 05:39 PM

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

0
Eyup
Telerik team
answered on 21 Jan 2016, 09:27 AM
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
0
Salim
Top achievements
Rank 1
answered on 21 Jan 2016, 03:41 PM
Thanks but MasterTableView.RenderColumns and MasterTableView.AutoGeneratedColumns don't work
0
Eyup
Telerik team
answered on 26 Jan 2016, 08:05 AM
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
0
Raymond
Top achievements
Rank 1
answered on 05 Mar 2020, 10:59 PM

The GridColumn Object has a method called ResetCurrentFilterValue.  The popup hint for that function says that it "Resets the values of the GridColumn.CurrentFilterFunction, GridColumnCurrentFilterValue, GridColumn.AndCurrentFilterFunction and GridColumn.AndCUrrentFilterValue properties to their defaults".  See attached image.

 

It does appear to reset the value, but not the function as the popup hint states. 

 

0
Eyup
Telerik team
answered on 10 Mar 2020, 05:14 AM

Hi Raymond,

 

In this case you can set the CurrentFilterFunction manually to NoFilter. The best way to clear the filters of the grid is this approach:
https://www.telerik.com/support/kb/aspnet-ajax/grid/details/reset-radgrid-state


I hope this will prove helpful.

Regards,
Eyup
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
Tags
Grid
Asked by
Chamara
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Chamara
Top achievements
Rank 1
Amrit
Top achievements
Rank 1
Calvin
Top achievements
Rank 1
Salman
Top achievements
Rank 1
Eyup
Telerik team
Urshela
Top achievements
Rank 1
Vinit
Top achievements
Rank 1
Salim
Top achievements
Rank 1
Raymond
Top achievements
Rank 1
Share this question
or