Add "Clear filter" icon to all your GridCheckBox columns

Thread is closed for posting
1 posts, 0 answers
  1. 49D2949C-281D-48B1-9767-C99F52F36F16
    49D2949C-281D-48B1-9767-C99F52F36F16 avatar
    185 posts
    Member since:
    Oct 2012

    Posted 18 Dec 2013 Link to this post


    RadControls version
    .NET version
    Visual Studio version
    programming language
    browser support

    all browsers supported by RadControls

    This little snippet add a little icon near your Checkbox columns filter, so that you can clear filters, otherwise after the first time you filter the column clicking on the filter checkbox, you'll only be able to filter true/false values and the only way to remove filtering and get both values would be resorting to HeaderContext menu.
    The script is very simple, it's executed in the grid ItemCreated event and scans for all your Checbox colums.
    In the zip an appropriate icon for the Telerik default skin is also provided, remember to edit the script with the real path pointing to where you'll place the icon.
    Very simple but very useful in my opinion.

    Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemCreated
                Dim grid As RadGrid = DirectCast(sender, RadGrid)
                ' Tweak filter items
                If TypeOf e.Item Is GridFilteringItem Then
                    Dim fltItem As GridFilteringItem = DirectCast(e.Item, GridFilteringItem)
                    For Each column As GridColumn In grid.Columns
                        ' Add remove filters buttons for boolean columns
                        If column.ColumnType = "GridCheckBoxColumn" And column.Display Then
                            AddClearFilterButton(column.UniqueName, fltItem, grid)
                        End If
                End If
    End Sub
    Private Sub AddClearFilterButton(columnName As String, fltItem As GridFilteringItem, grid As RadGrid)
                'Dim grid As GridTableView = fltItem.OwnerTableView
                Dim clearFilterButton As New ImageButton
                clearFilterButton.ImageUrl = "PATH_TO_YOUR_ICON_EDIT_THIS/grid-remove-filters.png"
                AddHandler clearFilterButton.Click, Sub(sender As Object, e As ImageClickEventArgs)
                                                        grid.MasterTableView.GetColumn(columnName).CurrentFilterFunction = GridKnownFunction.NoFilter
                                                        grid.MasterTableView.GetColumn(columnName).CurrentFilterValue = String.Empty
                                                        grid.MasterTableView.FilterExpression = String.Empty
                                                    End Sub
    End Sub

    It's in VB.NET but if you need C# version just head to Telerik Code converter. Beware of the AddHandler part for the click event if you convert to C# maybe this part will need a little bit of extra love from you ;)
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.