RadContextMenu: hideColumn[x] Property not supported?

2 posts, 1 answers
  1. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 05 Feb 2010 Link to this post

    This is my first encounter with RadMenu, so I just copied directly from the online example and modified it to fit my column names:

    <telerik:RadContextMenu ID="radContextMenu1" runat="server" Skin="Forest" OnClientItemClicked="ClientItemClicked">  
        <Items> 
            <telerik:RadMenuItem Text="Show Column">  
                <Items> 
                    <telerik:RadMenuItem Text="MDEP" /> 
                    <telerik:RadMenuItem Text="MDEP Description" /> 
                    <telerik:RadMenuItem Text="OA" /> 
                    <telerik:RadMenuItem Text="OA Description" /> 
                    <telerik:RadMenuItem Text="EOR" /> 
                    <telerik:RadMenuItem Text="EOR Description" /> 
                    <telerik:RadMenuItem Text="ASN" /> 
                    <telerik:RadMenuItem Text="ASN Description" /> 
                    <telerik:RadMenuItem Text="APC" /> 
                    <telerik:RadMenuItem Text="APC Description" /> 
                    <telerik:RadMenuItem Text="FY06" /> 
                    <telerik:RadMenuItem Text="FY07" /> 
                    <telerik:RadMenuItem Text="FY08" /> 
                    <telerik:RadMenuItem Text="FY09" /> 
                </Items> 
            </telerik:RadMenuItem>   
            <telerik:RadMenuItem Text="Hide Column" /> 
        </Items>   
        <Targets> 
            <telerik:ContextMenuTagNameTarget TagName="thead" /> 
        </Targets>   
    </telerik:RadContextMenu>  

    The menu pops up on right mouse-click populated with all the menu items.  When I click on a menu item the following javascript is invoked, again copied verbatum from the online example:

    function ClientItemClicked( sender, eventArgs ) {  
        activeTable = $find( "<%= radGrid1.ClientID %>" ).get_masterTableView();  
        colIndex = GetRealCellIndex( activeTable, eventArgs.get_gridColumn().get_element());  
     
        switch( eventArgs.get_item().get_text() ) {  
            case "MDEP" :  
                activeTable.showColumn( 0 );  
                break;  
     
            case "MDEP Description" :  
                activeTable.showColumn( 1 );  
                break;  
     
            case "OA" :  
                activeTable.showColumn( 2 );  
                break;  
     
            case "OA Description" :  
                activeTable.showColumn( 3 );  
                break;  
     
            case "EOR" :  
                activeTable.showColumn( 4 );  
                break;  
     
            case "EOR Description":  
                activeTable.showColumn( 5 );  
                break;  
     
            case "ASN":  
                activeTable.showColumn( 6 );  
                break;  
     
            case "ASN Description":  
                activeTable.showColumn( 7 );  
                break;  
     
            case "APC":  
                activeTable.showColumn( 8 );  
                break;  
     
            case "APC Description":  
                activeTable.showColumn( 9 );  
                break;  
     
            case "FY06":  
                activeTable.showColumn( 10 );  
                break;  
     
            case "FY07":  
                activeTable.showColumn( 11 );  
                break;  
     
            case "FY08":  
                activeTable.showColumn( 12 );  
                break;  
     
            case "FY09":  
                activeTable.showColumn( 13 );  
                break;  
     
            case "Hide Column" :  
                activeTable.hideColumn( colIndex );  
                break;     
     
            default :  
                break;  
        }  

    And no matter what menu item I click on a get a JavaScript "Property Not Supported" error.  The cause of this is apparently

                        colIndex = GetRealCellIndex( activeTable, eventArgs.get_gridColumn().get_element());


    So I commented it out and then all I get is the [undefined] JavaScript error.

    Can someone please give me a clue, because I obviously don't have one?

    Thanks,
    Mark
  2. Answer
    Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 05 Feb 2010 Link to this post

    Oops.  I missed including the ClientEvents node in the ClientSettings parent of the radgrid.

    <ClientEvents OnColumnContextMenu="ColumnContextMenu" /> 

    This sets the table object and the column index:

    var activeTable;  
    var colIndex;  
     
    function ColumnContextMenu( sender, eventArgs ) {  
        activeTable = $find( "<%= radGrid1.ClientID %>" ).get_masterTableView();  
        colIndex = GetRealCellIndex( activeTable, eventArgs.get_gridColumn().get_element());   
    }  
     
    function GetRealCellIndex( tableView, cell ) {  
        for( var i = 0; i < tableView.get_columns().length; i++ ) {  
     
            if( tableView.get_columns()[ i ].get_element() == cell ) {  
                return i;  
            }  
        }  

    and the table object and column index should not be define in ClientItemClicked().

    It works as advertised now.

    Cheers!
    Mark
Back to Top