ContextMenu over a specified column in RadGrid

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

    Posted 05 Mar 2008 Link to this post


    Requirements

    RadControls version

    RadContextMenu, RadGrid 
    Telerik.WEB.UI 2007.3.1425

    .NET version

    2.0

    Visual Studio version

    2005

    programming language

    C#, VB

    browser support

    all browsers supported by RadControls


     
  2. PROJECT DESCRIPTION
    This project shows how to open a context menu (RadContextMenu) only if you click on a cell in the first column.
    This is achieved by hooking on the OnRowContextMenu client event of the Grid.

    <ClientSettings> 
         <ClientEvents OnRowContextMenu="RowContextMenu" /> 
         <Selecting AllowRowSelect="true" /> 
    </ClientSettings> 

    Here is the JavaScript function that invokes the context menu:

    <script type="text/javascript">  
    function RowContextMenu(sender, eventArgs)  
    {   
       var menu = $find("<%= RadContextMenu1.ClientID %>");  
         
       var domEvent = eventArgs.get_domEvent();  
       var source = domEvent.target || domEvent.srcElement;  
       var index = eventArgs.get_itemIndexHierarchical();  
         
       var masterTable = sender.get_masterTableView();  
       masterTable.clearSelectedItems();  
       //select the current row  
       masterTable.selectItem(masterTable.get_dataItems()[index].get_element());  
     
       //get the first cell of the row  
       var cell = masterTable.get_dataItems()[index].get_element().cells[0];      
          
       if (source == cell)  
       {     
            menu.show(domEvent);  
       }  
       $telerik.cancelRawEvent(domEvent);  
    }  
    </script> 
  • Back to Top