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

RadGrid HeaderContextMenu ItemCreated

1 Answer 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Algo
Top achievements
Rank 1
Algo asked on 26 Sep 2013, 06:06 PM
Hello,

I would like to know if it is possible to cancel an item being created in the grid's header context menu.

Here is my temp solution (that works) : 

grid.HeaderContextMenu.ItemCreated += (o, e) =>
{
    if (some_condition)
    {
        e.Item.Owner.Items.Remove(e.Item);
    }
};

I am looking for a better way to do this. I would love to be able to cancel the item from being created at all, rather than letting it create and then removing it.

Thank you

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 01 Oct 2013, 10:37 AM
Hi Louis-Joel,

You can try the following javascript in OnHeaderMenuShowing event to hide custom HeaderContextMenu for a  specific column.
function OnHeaderMenuShowing(sender, eventArgs)
{
   if (eventArgs.get_gridColumn().get_uniqueName() == "ColumnUniquename")
    {
  //hide the Clear sorting option from the header context menu
    eventArgs.get_menu().get_items().getItem(2).get_element().style.display = "none";
    }
}

You can also have a look at this help topic in the section: Add items to HeaderContextMenu. You can use the similar approach to access the HeaderContextMenu in the OnPreRenderComplete event and there apply the necessary modifications to the items.

Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Algo
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or