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

[Solved] Dynamic ContextMenu

3 Answers 171 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Vincent asked on 19 Jun 2009, 10:22 AM
Hi,

I have an ASP.Net Grid with rows in it. Depending on the type of row being right-clicked upon I want to show a different ContextMenu.
The contents of this ContextMenu should be computed server-side. My client-side code is below:

/* this.aspGrid.ClientSettings.ClientEvents.OnRowContextMenu is set to JavaScript like below: */ 
 
function(grid, row) { 
 var menu = $find('contextMenu'); 
 var evt = row.get_domEvent(); 
 if ((!evt.relatedTarget) || (!$telerik.isDescendantOrSelf(menu.get_element(), evt.relatedTarget))) { 
  window.setTimeout(  
    function() { 
      alert(123123); 
      grid.get_masterTableView().fireCommand('showContextmenu', row.get_itemIndexHierarchical());  
      menu.show( evt );  
     },  
     0); 
   } 
 } 

Server side the command showContextmenu creates a new RadMenuItemCollection and assigns this reference to the RadContextMenu. Then this RadContextMenu is updated. However when the menu.show() is called client-side the ContextMenu appears and then immediately disappears.

How can I accomplish dynamic loading of a RadContextMenu on a row in a Grid?


3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 19 Jun 2009, 11:13 AM
Hi Vincent,

Please check our online demo: Ajax Enabled Context Menu in Grid

I hope this will get you started.

Greetings,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Vincent
Top achievements
Rank 1
answered on 19 Jun 2009, 11:40 AM
Hi Veselin,

I've already checked that demo. However in that demo the ContextMenu has static contents. I need some clarifications on how to do a callback to the server and reload the RadMenuItemCollection (where the contents of that collection depend on the row being selected) correctly.

Regards,
Vincent
0
Yana
Telerik team
answered on 24 Jun 2009, 02:43 PM
Hello Vincent,

I've attached a simple page demonstrating the needed approach. Please download it and give it a try.

Best wishes,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Menu
Asked by
Vincent
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Vincent
Top achievements
Rank 1
Yana
Telerik team
Share this question
or