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

Show HeaderContextFilterMenu on click

1 Answer 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chuck
Top achievements
Rank 1
Chuck asked on 11 Jun 2013, 07:07 PM
Hello everyone,

I am trying to show the HeaderContextFilterMenu every time an image is clicked in the header of a RadGrid control.

I'm using this example as a reference.
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/headercontextfiltermenu/defaultcs.aspx


I am handling the image clicks in jQuery like so...

        //images have a class of .showFilter
        $(".showFilter").live('click', function (event, handler) {
            var mouseEvent = event.originalEvent;  
            showFilter(this, mouseEvent)
        });

    ...getting the Radrid header object in jQuery and then calling the _initHeaderContextMenu() to show the menu.

     function showFilter(imageLink, event)
     {
        var header = imageLink.parentElement.control;
        var sysEvent = new Sys.UI.DomEvent(event);
        header._initHeaderContextMenu(sysEvent, undefined, 75, 20);
     }

    This does show the HeaderContextMenu for the proper column header.

    The problem is that the menu immediately closes.

I suspect this is because I am not capturing the same event as a right click on the header but instead manufacturing a Sys.UI.DomEvent based off the image click event.

Can anyone help me out with this?

  Thanks,
    Chuck



1 Answer, 1 is accepted

Sort by
0
Chuck
Top achievements
Rank 1
answered on 12 Jun 2013, 03:46 PM
I was able to get this to work by coming at it from a slightly different direction.

In the PreRender event for the RadGrid I dynamically added an ImageButton to the header that calls the javascript function like so...

    protected void rgPreRender(object sender, EventArgs e)
    {
        RadGrid rg = (RadGrid)sender;
        GridHeaderItem rGridHeaderItem = (GridHeaderItem)rg.MasterTableView.GetItems(GridItemType.Header)[0];

        ImageButton img = new ImageButton();
        img.ImageUrl = "../Images/Edit.gif";
        img.CssClass = "showFilter";
        img.ToolTip = "Click to sort and filter";
        img.OnClientClick = "showContextMenu(event)";

        rGridHeaderItem["ColumnName"].Controls.Add(img);      
    }

Then added the javascript function to manually show the HeaderContextMenu...

function showContextMenu(ev) {
        var header = ev.currentTarget.parentElement.control;
        header.showHeaderMenu(ev, 75, 20);
}


Hope this helps someone in the future.

-Chuck
Tags
Grid
Asked by
Chuck
Top achievements
Rank 1
Answers by
Chuck
Top achievements
Rank 1
Share this question
or