Custom GridView Filter Popup

6 posts, 1 answers
  1. Hugo Furth
    Hugo Furth avatar
    31 posts
    Member since:
    Dec 2008

    Posted 26 May 2014 Link to this post

    Hi All -

    I looked thru the forum but could find an example of what I need to do. And that is

    empty the filter popup and populate it with my own entries.

    For simplicity I only need 3 fields. The underlying column will contain only "A", "B", or blank/null so I would like the popup 
    to contain only those values. Even if the column could contain "C" or "D", I don't want to filter on that.

    I know this can't be too difficult but I was unable to find an example and the code I wrote didn't work properly.

    Any help appreciated.
    Regards,
    Hugo
  2. Hugo Furth
    Hugo Furth avatar
    31 posts
    Member since:
    Dec 2008

    Posted 26 May 2014 Link to this post

    Forgot.....also need an "All" selection.

    Thx,
    Hugo
  3. Answer
    Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 28 May 2014 Link to this post

    Hi Hugo,

    Thank you for writing.

    The FilterPopupInitialized event can be used for both, to remove any items you want and to change the items in the treeview:
    void radGridView1_FilterPopupInitialized(object sender, Telerik.WinControls.UI.FilterPopupInitializedEventArgs e)
    {
        RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
        if (popup != null)
        {
            popup.MenuElement.Items.RemoveAt(0);
            popup.MenuElement.Items.RemoveAt(0);
             
            popup.MenuTreeElement.DistinctListValues.Add("<empty>", "");
            popup.MenuTreeElement.DistinctListValues.Remove("C");
            popup.MenuTreeElement.DistinctListValues.Remove("D");
        }
    }

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  4. Hugo Furth
    Hugo Furth avatar
    31 posts
    Member since:
    Dec 2008

    Posted 08 Jun 2014 Link to this post

    Your answer greatly appreciated.

    Hugo
  5. Alec
    Alec avatar
    3 posts
    Member since:
    Apr 2017

    Posted 23 Apr in reply to Dimitar Link to this post

    Hi Dimitar,

    I know that this is an old issue, but I am trying the same thing now, and I have been able to use this technique to add values to the filter popup menu tree element distinct list, but when I try to filter on those elements, I get no value passed.  Do I need to do something to get the filter to work for these added list values?

    Thanks,

    Alec

  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3898 posts

    Posted 28 Apr Link to this post

    Hello, Alec,

    Following the provided code snippet, I have prepared a sample project to test the behavior on my end with the latest version. You can find below the default filter popup:

    After handling the FilterPopupInitialized event, the below result is accomplished:

            public RadForm1()
            {
                InitializeComponent();
    
                this.radGridView1.Columns.Add("Name");
                this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    
                this.radGridView1.Rows.Add("A");
                this.radGridView1.Rows.Add("B");
                this.radGridView1.Rows.Add("C");
                this.radGridView1.Rows.Add("D");
    
                this.radGridView1.EnableFiltering = true;
                this.radGridView1.ShowHeaderCellButtons = true;
                this.radGridView1.ShowFilteringRow = false;
    
                this.radGridView1.FilterPopupInitialized+=radGridView1_FilterPopupInitialized;
            }
    
            private void radGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
            {
                RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
                if (popup != null)
                {
                    popup.MenuElement.Items.RemoveAt(0);
                    popup.MenuElement.Items.RemoveAt(0);
    
                    popup.MenuTreeElement.DistinctListValues.Add("<empty>", "");
                    popup.MenuTreeElement.DistinctListValues.Remove("C");
                    popup.MenuTreeElement.DistinctListValues.Remove("D");
                }
            }

    If you uncheck some of the nodes, the filtering seems to work as expected:

    I have attached my sample project. Could you please specify the exact steps how to reproduce the problem? Thank you in advance for your cooperation.

    I am looking forward to your reply.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top