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

Clear all filters button

4 Answers 666 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ColinBlakey
Top achievements
Rank 2
ColinBlakey asked on 14 Jun 2013, 06:46 PM
I have a complex RadGrid with many columns and filters on all the columns. As the use can end up with a complex set of filter I want to add a 'clear all filters' button. As it is a parent/detail grid I figured I would use the space next to the filters created by the expand/collapse column. So I managed to 'successfully' put a new image button in that space with the following code which I have in my Grid ItemDataBound method..

// Creating filtering row clear all filters button
if ((e.Item.ItemType == GridItemType.FilteringItem))
{
    var clearFilterButton = new RadButton
    {
        ButtonType = RadButtonType.StandardButton,
        Height = 22,
        Width = 22
    };
 
    clearFilterButton.Image.EnableImageButton = true;
    clearFilterButton.Image.ImageUrl = string.Format("../App_Themes/{0}/Images/ClearFilter.png", Page.Theme);
    clearFilterButton.ToolTip = "Clear current filter(s)";
    clearFilterButton.Click += ClearButton_Click;
 
    var expandCollapseColumn = (GridTableCell) e.Item.Controls[0];
    expandCollapseColumn.Controls.Add(clearFilterButton);
}

I'm assuming I have this all wrong as I have two problems.
1) Clicking the button makes it disappear
2) Clicking the button never fires the clearbutton event.

Can anyone help and maybe this should be a feature in the RadGrid control in the future?

Thanks

Colin

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Jun 2013, 05:42 AM
Hi,

I guess you want to clear the filter textbox values on a button click.Please try this code on the button click event.

C#:
protected void FilterButtonClear_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();
  }


Thanks,
Princy
0
ColinBlakey
Top achievements
Rank 2
answered on 17 Jun 2013, 01:27 PM
Princy,

I've already seen this demo and one or two others and have code which works from a separate button (ala the demo) and also a command bar button. What I'm trying to achieve is adding the button next to the filters in the empty space created by the expand./collapse column.

<telerik:RadGrid ID="viewStatusRadGrid" EnableHierarchyExpandAll="true" ...
    <!-- Add expand/collapse column -- Adds space for clear filter button
    <ClientSettings AllowExpandCollapse="True" />
    <MasterTableView DataKeyNames="ID" TableLayout="Auto" AllowNaturalSort="false">
        <Columns>                          
        <telerik:GridBoundColumn ..../>
                ....
    </MasterTableView>                 
    <Scrolling AllowScroll="false" />
</telerik:RadGrid>

Thanks

Colin
0
Kostadin
Telerik team
answered on 19 Jun 2013, 12:07 PM
Hi Colin,

I prepared a small sample based on your scenario and attached it to this thread. As you could see the button click event is being fired and the filter is cleared properly. Could you please give it a try and let me know how it differs from your real setup.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
ColinBlakey
Top achievements
Rank 2
answered on 20 Jun 2013, 12:50 PM
This is where it's a pain. I agree that the sample code works fine but when I have this code in my current application it does not work. This would suggest that something else is causing this to fail. Time for some trial and error testing to figure out the cause.

Thanks

Colin
Tags
Grid
Asked by
ColinBlakey
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
ColinBlakey
Top achievements
Rank 2
Kostadin
Telerik team
Share this question
or