Quick Filter Bar

12 posts, 1 answers
  1. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 17 Dec 2010 Link to this post

    Good Day,

    I would like to know if this is currently possible with the RadGrid, Please see image link. I would like a statusbar type control but in the radgrid so when a user adds a filer he will be able to quickly cancel all the filters or just disable/enable the filter quickly.

    If it's not possible can you please think of adding it to the next release as this will be a nice user experience addition.

    FilterStatus_Image
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 17 Dec 2010 Link to this post

    Hi Dean,

    You can do this by adding a RadHostItem to the RadGridView's TableElement, and a RadStatusStrip to the RadHostItem. Have a go with the following code. It's just a RadGridView on a form.

    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls
      
    Public Class Form1
      
        Private m_FilterCancelButton As RadButtonElement
        Private m_FilterLabel As RadLabelElement
      
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      
            Me.RadGridView1.EnableFiltering = True
            Me.RadGridView1.ShowFilteringRow = True
      
            Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None
            Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("Name"))
            Me.RadGridView1.Columns.Add(New GridViewDecimalColumn("Value"))
      
            Dim rowInfo As GridViewRowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A1"
            rowInfo.Cells(1).Value = 3
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A2"
            rowInfo.Cells(1).Value = 4
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A3"
            rowInfo.Cells(1).Value = 5
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A4"
            rowInfo.Cells(1).Value = 6
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A2"
            rowInfo.Cells(1).Value = 4
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A3"
            rowInfo.Cells(1).Value = 5
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A4"
            rowInfo.Cells(1).Value = 6
      
      
            Dim statusBar As New RadStatusStrip()
            statusBar.Dock = DockStyle.Bottom
            statusBar.StatusBarElement.GripStyle = ToolStripGripStyle.Hidden
      
            m_FilterCancelButton = New RadButtonElement()
            m_FilterCancelButton.Text = "-"
            AddHandler m_FilterCancelButton.Click, AddressOf FilterCancelButton_Click
      
            m_FilterLabel = New RadLabelElement()
            m_FilterLabel.Text = " Currently Unfiltered"
      
            statusBar.Items.Add(m_FilterCancelButton)
            statusBar.Items.Add(m_FilterLabel)
      
            Dim hostItem As New RadHostItem(statusBar)
            Me.RadGridView1.TableElement.Children.Add(hostItem)
      
        End Sub
      
        Private Sub FilterCancelButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            Me.RadGridView1.FilterDescriptors.Clear()
        End Sub
      
        Private Sub RadGridView1_FilterExpressionChanged(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.FilterExpressionChangedEventArgs) Handles RadGridView1.FilterExpressionChanged
            If e.FilterExpression.Length > 0 Then
                m_FilterLabel.Text = e.FilterExpression
            Else
                If m_FilterLabel IsNot Nothing Then
                    m_FilterLabel.Text = "Currently unfiltered"
                End If
            End If
        End Sub
      
    End Class

    hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 18 Dec 2010 Link to this post

    Thank you so much for a solution, it works perfectly.
  5. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 13 Apr 2011 Link to this post

    I'm trying this with 2011Q1 but the status strip first covers the grid, and gets invisible after a refesh. of the grid control.
    I would like to have the status strip dock to the bottom, and the grid's table just in the space above it.

    Regards
    Erwin
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Apr 2011 Link to this post

    Hi Erwin,

    Hope you're well. I can see what you mean by it cuts it off at the bottom, though it just seems to be acting like a status bar at the bottom of the form, which doesn't seem to be an issue as far as I can see at the moment. I also cannot get the bar to disappear when anything is refreshed in the latest version of the controls. All seems to work fine.

    Can you post a small sample to replicate the problem? If you like, I can add a quick video to show it working here.
    Thanks
    Richard
  7. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 14 Apr 2011 Link to this post

    Hi Richard,

    thanks for the message. It's not a big issue, I just saw this message and tried it out. In order to place the status bar below the grid and covering it, I tried various stuff and only then did I get the issue of the status bar disappearing.

    In my app, until now I use a custom control that contains the grid and has some space below for status messages, buttons etc. This works well, but is a little bit awkward since the custom control has to make the grid public for maximum flexibility. And you then have to access its properties through something like

    myControl.Grid.TableElement.....

    directly deriving from the grid and add a statusbar seemed more elegant than using a container with the grid and the status bar in it.

    Regards
    Erwin
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 15 Apr 2011 Link to this post

    Hi Erwin,

    Ok, well if I can help in any way just let me know. I guess one could also just use a status bar on the form itself as in a regular way. If you have time at some point to post your own solution too, I'd be interested to see it.

    Let me know if I can help though
    thanks
    Richard
  9. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 15 Apr 2011 Link to this post

    Of course, Richard - but my app has about 25 grids that need to display status information.

    I usually display number of rows in the dataset, number of visible rows in the grid and the time it took to load from the database
    so that the user has more feedback about filtered rows and about db performance.
    Plus I do show a button that lets the user clear all filters if any are set. (this may become obsolete with newer versions, but the filter UI used to be quite confusing in older versions).

    Regards
    Erwin
  10. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 18 Apr 2011 Link to this post

    Hello guys, 

    Thank you for this useful discussion. I think that other users might benefit from a code library regarding this subject. 

    Here is another approach for arranging the status strip. Please let me know how it works for you:
    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls
     
    Public Class Form1
     
        Private m_FilterCancelButton As RadButtonElement
        Private m_FilterLabel As RadLabelElement
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.RadGridView1.EnableFiltering = True
            Me.RadGridView1.ShowFilteringRow = True
     
            Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None
            Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("Name"))
            Me.RadGridView1.Columns.Add(New GridViewDecimalColumn("Value"))
     
            Dim rowInfo As GridViewRowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A1"
            rowInfo.Cells(1).Value = 3
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A2"
            rowInfo.Cells(1).Value = 4
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A3"
            rowInfo.Cells(1).Value = 5
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A4"
            rowInfo.Cells(1).Value = 6
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A2"
            rowInfo.Cells(1).Value = 4
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A3"
            rowInfo.Cells(1).Value = 5
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A4"
            rowInfo.Cells(1).Value = 6
     
     
            Dim statusBar As New RadStatusStrip()
            statusBar.StatusBarElement.GripStyle = ToolStripGripStyle.Hidden
     
            m_FilterCancelButton = New RadButtonElement()
            m_FilterCancelButton.Text = "-"
            AddHandler m_FilterCancelButton.Click, AddressOf FilterCancelButton_Click
     
            m_FilterLabel = New RadLabelElement()
            m_FilterLabel.Text = " Currently Unfiltered"
     
            statusBar.Items.Add(m_FilterCancelButton)
            statusBar.Items.Add(m_FilterLabel)
     
            Dim hostItem As New RadHostItem(statusBar)
            hostItem.MinSize = New Size(0, 25)
            Me.RadGridView1.GridViewElement.Panel.Children.Insert(1, hostItem)
            Telerik.WinControls.Layouts.DockLayoutPanel.SetDock(hostItem, Telerik.WinControls.Layouts.Dock.Bottom)
     
        End Sub
     
        Private Sub FilterCancelButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            Me.RadGridView1.FilterDescriptors.Clear()
        End Sub
     
        Private Sub RadGridView1_FilterExpressionChanged(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.FilterExpressionChangedEventArgs) Handles RadGridView1.FilterExpressionChanged
            If e.FilterExpression.Length > 0 Then
                m_FilterLabel.Text = e.FilterExpression
            Else
                If m_FilterLabel IsNot Nothing Then
                    m_FilterLabel.Text = "Currently unfiltered"
                End If
            End If
        End Sub
    End Class

    I am looking forward to your reply. 

    All the best,
    Stefan
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  11. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 21 Apr 2011 Link to this post

    Hi Stefan,

    Thanks for the amendment. I will get this submitted as a Code Library project in both VB and C#. For reference though, the click event of the button element doesn't seem to fire when docked in this way. Instead I seem to need to use the MouseDown event.

    Regards,
    Richard
  12. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 26 Apr 2011 Link to this post

    Hello Richard, 

    Thank you for submitting the Code Library article. 

    In regards to the Click event, I will add this to our issue tracking system and we will review it for a future release.
     
    Greetings,
    Stefan
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  13. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 26 Apr 2011 Link to this post

    Thanks for the update Stefan.
    For anyone looking to download this in both CS and VB, the Code Library article is available here

    Regards,
    Richard
Back to Top
UI for WinForms is Visual Studio 2017 Ready