RadMenu as RadGrid filtering menu

Thread is closed for posting
4 posts, 1 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 05 Jul 2007 Link to this post

    Requirements

    RadControls version

    Q1 2007 SP1     
    .NET version .NET 2.0
    Visual Studio version

    2005
    programming language

    C#
    browser support

    all browsers supported by RadControls


     
    PROJECT DESCRIPTION
    This project shows how to configure RadGrid to use RadMenu as filtering menu. The basic steps are:
    • Wire ItemCreated event and check if e.Item is GridFilteringItem
    • Hide the current filter image and create RadMenu
    • Add items to RadMenu - first add "NoFilter" item and the loop through GridKnownFunction enum to add item to the menu for each member. Check if the column is of type integer and skip irrelevant functions
    • Wire ItemClick event of RadMenu to fire filtering command when an item in RadMenu is clicked.
    Below is the codebehind:

        protected void RadGrid1_ItemCreated(object sender, Telerik.WebControls.GridItemEventArgs e) 
        { 
            if (e.Item is GridFilteringItem) 
            { 
                foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns) 
                { 
                    if (!column.Visible) 
                        continue
     
                    TextBox FilterTextBox = (TextBox)((GridFilteringItem)e.Item)[column.UniqueName].Controls[0]; 
                    FilterTextBox.Style["float"] = "left"
                    Image FilterImage = (Image)((GridFilteringItem)e.Item)[column.UniqueName].Controls[1]; 
                    FilterImage.Visible = false
     
                    RadMenu RadMenu1 = new RadMenu(); 
                    RadMenu1.Style["border"] = "0px;"
                    RadMenu1.Items.Add(new RadMenuItem("")); 
                    RadMenu1.Items[0].ImageUrl = "~/Filter.gif"
                    RadMenu1.Items[0].Attributes["onclick"] = "return false;"
     
                    RadMenuItem RadMenuItem1 = new RadMenuItem("NoFilter"); 
                    RadMenuItem1.Value = column.UniqueName; 
                    RadMenu1.Items[0].Items.Add(RadMenuItem1); 
                    RadMenuItem separator = new RadMenuItem(); 
                    separator.IsSeparator = true
                    RadMenu1.Items[0].Items.Add(separator); 
     
                    foreach (string function in Enum.GetNames(typeof(GridKnownFunction))) 
                    { 
                        if (function == "NoFilter" || function == "Custom" || (column.DataType == Type.GetType("System.Int32") && 
                        ( 
                            function == "Contains" || 
                            function == "DoesNotContain" || 
                            function == "StartsWith" || 
                            function == "EndsWith" || 
                            function == "IsEmpty" || 
                            function == "NotIsEmpty" 
                       ))) 
                            continue
                        RadMenuItem RadMenuItem2 = new RadMenuItem(function); 
                        RadMenuItem2.Value = column.UniqueName; 
                        RadMenu1.Items[0].Items.Add(RadMenuItem2); 
                    } 
     
                    RadMenu1.FindItemByText(column.CurrentFilterFunction.ToString()).Font.Bold = true
     
                    RadMenu1.ItemClick += new RadMenuEventHandler(RadMenu1_ItemClick); 
     
                    ((GridFilteringItem)e.Item)[column.UniqueName].Controls.Add(RadMenu1); 
                } 
            } 
        } 
     
        void RadMenu1_ItemClick(object sender, RadMenuEventArgs e) 
        { 
            string functionName = e.Item.Text; 
            string columnUniqueName = e.Item.Value; 
     
            RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0].FireCommandEvent("Filter"new Pair(functionName, columnUniqueName)); 
     
        } 

    You can also find the complete project\ attached.
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 07 Apr 2008 Link to this post

    Hi guys,

    This is just to inform you that RadGrid Prometheus incorporates RadMenu as built-in filtering menu and you do not need any additional code logic to attain the functionality presented below with the classic versions of the controls:

    http://www.telerik.com/help/radcontrols/prometheus/?grdWhatsNew.html

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. ben.grossman
    ben.grossman avatar
    22 posts
    Member since:
    Jul 2007

    Posted 03 Jul 2008 Link to this post

    This doesn't work in firefox 3.0.  I compiled this project on my machine and the menu's work fine in IE but they don't work right in firefox 3.0.  Is there some kind of workaround so I can obtain this functionality in both? 
    Thank you in advance.
  4. Answer
    Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 04 Jul 2008 Link to this post

    Hi ben.grossman,

    I tested the online demos of RadGrid (residing under the Filtering category) and they behaved as expected under FireFox 3.0. Can you please verify that on your machine?

    If the problem persists and you are unable to address it yourself, I will appreciate if you prepare a stripped working version of your project, illustrating the abnormality, and send it enclosed to a formal support ticket. We will test it locally and will get back to you with our findings.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top