right click hyperlink, no browser menu

4 posts, 0 answers
  1. Christian
    Christian avatar
    64 posts
    Member since:
    Apr 2008

    Posted 25 Mar 2011 Link to this post

    Ajax 2010.3.1317.35

    I have a radgrid with some hyperlink columns, and a contextmenu atteched. is there any way to keep the browser menu when right clicking on hyperlinks, keeping the contextmenu on "other" row right click renderings?

    here´s my grid code if its to any help.

    <telerik:RadGrid ID="grCaseList" runat="server" Skin="Windows7" 
        AllowPaging="True" AllowSorting="True" GridLines="None" ShowGroupPanel="True" 
            Width="100%" AutoGenerateColumns="False" 
            onitemdatabound="grCaseList_ItemDataBound">
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Windows7"></HeaderContextMenu>
      
        <MasterTableView EnableColumnsViewState="true" GroupsDefaultExpanded="false" GroupLoadMode="Client" >
          
            <CommandItemSettings ExportToPdfText="Export to Pdf" >
            </CommandItemSettings>
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridHyperLinkColumn DataTextField="cs_id" DataType="System.Int32" 
                    FilterControlAltText="Filter cs_id column" HeaderText="ID" 
                    UniqueName="cs_id" DataNavigateUrlFields="caseUrl" Groupable="False">
                </telerik:GridHyperLinkColumn>
                <telerik:GridHyperLinkColumn DataTextField="cs_header" 
                    FilterControlAltText="Filter cs_header column" HeaderText="Rubrik" 
                    UniqueName="cs_header" DataNavigateUrlFields="caseUrl" Groupable="False">
                </telerik:GridHyperLinkColumn>
                <telerik:GridHyperLinkColumn DataTextField="nt_us_name" 
                    FilterControlAltText="Filter nt_us_name column" HeaderText="Senast ändrad av" 
                    UniqueName="nt_us_name">
                </telerik:GridHyperLinkColumn>
                <telerik:GridDateTimeColumn DataField="cs_timePosted" 
                    FilterControlAltText="Filter cs_timePosted column" HeaderText="Inlagt" 
                    UniqueName="cs_timePosted" DataFormatString="{0:yy-MM-dd hh:mm}">
                </telerik:GridDateTimeColumn>
                <telerik:GridDateTimeColumn DataField="cs_timePlanned" 
                    DataType="System.DateTime" FilterControlAltText="Filter cs_timePlanned column" 
                    HeaderText="Planerat" UniqueName="cs_timePlanned" DataFormatString="{0:yy-MM-dd}">
                </telerik:GridDateTimeColumn>
                <telerik:GridDateTimeColumn DataField="cs_timeClosed" 
                    FilterControlAltText="Filter cs_timeClosed column" HeaderText="Avslutat" 
                    UniqueName="cs_timeClosed" DataFormatString="{0:yy-MM-dd hh:mm}">
                </telerik:GridDateTimeColumn>
                <telerik:GridBoundColumn DataField="cs_fromIP" 
                    FilterControlAltText="Filter cs_fromIP column" HeaderText="IP" 
                    UniqueName="cs_fromIP">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="cs_fritext" 
                    FilterControlAltText="Filter cs_fritext column" HeaderText="Fritext" 
                    UniqueName="cs_fritext">
                </telerik:GridBoundColumn>
                <telerik:GridHyperLinkColumn DataTextField="cs_fromComputerName" 
                    FilterControlAltText="Filter cs_fromComputerName column" HeaderText="Dator" 
                    UniqueName="cs_fromComputerName">
                </telerik:GridHyperLinkColumn>
                <telerik:GridBoundColumn DataField="st_name" 
                    FilterControlAltText="Filter st_name column" HeaderText="Status" 
                    UniqueName="st_name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ty_name" 
                    FilterControlAltText="Filter ty_name column" HeaderText="Typ" 
                    UniqueName="ty_name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="prio" 
                    FilterControlAltText="Filter prio column" HeaderText="Prio" UniqueName="prio">
                </telerik:GridBoundColumn>
                <telerik:GridDateTimeColumn DataField="nt_timePosted" 
                    FilterControlAltText="Filter nt_timePosted column" HeaderText="Uppdaterad" 
                    UniqueName="nt_timePosted" DataFormatString="{0:yy-MM-dd hh:mm}">
                </telerik:GridDateTimeColumn>
                <telerik:GridHyperLinkColumn DataTextField="cs_us_name" 
                    FilterControlAltText="Filter cs_us_name column" HeaderText="Inlagt av" 
                    UniqueName="cs_us_name">
                </telerik:GridHyperLinkColumn>
                <telerik:GridHyperLinkColumn DataTextField="adm_ad_username" 
                    FilterControlAltText="Filter adm_ad_username column" HeaderText="Ansvarig" 
                    UniqueName="adm_ad_username">
                </telerik:GridHyperLinkColumn>
                <telerik:GridBoundColumn DataField="maxRead" 
                    FilterControlAltText="Filter maxRead column" HeaderText="maxRead" 
                    UniqueName="maxRead" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="maxNote" 
                    FilterControlAltText="Filter maxNote column" HeaderText="maxNote" 
                    UniqueName="maxNote" Visible="False">
                </telerik:GridBoundColumn>
            </Columns>
      
    <EditFormSettings>
    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
    </EditFormSettings>
      
        </MasterTableView>
        <ClientSettings AllowDragToGroup="True">
            <Resizing AllowColumnResize="True"></Resizing>
            <ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>
        <Selecting AllowRowSelect="true" />
      
        </ClientSettings>
      
    <FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>
      
        <input type="hidden" id="radGridClickedRowIndex" name="radGridClickedRowIndex" />
      
        <telerik:RadContextMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick"
            EnableRoundedCorners="true" EnableShadows="true" Skin="Windows7">
            <Items>
                <telerik:RadMenuItem Text="Öppna ärende" />
                <telerik:RadMenuItem Text="Avsluta ärende" />
                <telerik:RadMenuItem Text="Ta bort ärende" />
            </Items>
        </telerik:RadContextMenu>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Mar 2011 Link to this post

    Hello Christian,

    You can cancel the RowContextMenu based on the column (if its HyperLinkColumn). Sample code is given below.
    Java Script:
    <script type="text/javascript">
        function RowContextMenu(sender, eventArgs) {
            var menu = $find("<%=RadMenu1.ClientID %>");
            var evt = eventArgs.get_domEvent();
            var index = eventArgs.get_itemIndexHierarchical();
            var masterTable = sender.get_masterTableView();
            var cellIndex = evt.target.cellIndex;
            var column = masterTable.get_columns()[cellIndex];
            var uniqueName = column.get_uniqueName();
           if (uniqueName == "cs_id") {
                eventArgs.set_cancel(true);
            }
            else {
                if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") {
                    return;
                }
     
                document.getElementById("radGridClickedRowIndex").value = index;
     
                sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
     
                menu.show(evt);
     
                evt.cancelBubble = true;
                evt.returnValue = false;
     
                if (evt.stopPropagation) {
                    evt.stopPropagation();
                    evt.preventDefault();
                }
            }
        }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Christian
    Christian avatar
    64 posts
    Member since:
    Apr 2008

    Posted 25 Mar 2011 Link to this post

    almost, the evt.target.cellIndex is returned undefined.

    this means that i get a script error where column.get_uniqueName is being run, but the script is canceled and i see the browser menu (IE9).


    function RowContextMenu(sender, eventArgs)
    {
        var menu = $find("ctl00_phContent_RadMenu1");
        var evt = eventArgs.get_domEvent();
        var index = eventArgs.get_itemIndexHierarchical();
        var masterTable = sender.get_masterTableView();
        var cellIndex = evt.target.cellIndex;
        var column = masterTable.get_columns()[cellIndex];
        var uniqueName = column.get_uniqueName();
         
        if(uniqueName == "cs_id"
        {
            eventArgs.set_cancel(true);
        }
        if(uniqueName == "cs_header"
        {
            eventArgs.set_cancel(true);
        }
      
        if(evt.target.tagName == "INPUT" || evt.target.tagName == "A"
        
          return;
        
          
        var index = eventArgs.get_itemIndexHierarchical();
        document.getElementById("radGridClickedRowIndex").value = index;
          
        sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
          
        menu.show(evt);
          
        evt.cancelBubble = true;
        evt.returnValue = false;
      
        if (evt.stopPropagation)
        {
           evt.stopPropagation();
           evt.preventDefault();
        }
    }
  5. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 31 Mar 2011 Link to this post

    Hi Christian,

    If the issue persists, I would advise you to put your code into a sample runnable project and send it in a formal support ticket, so we can debug it locally and see what causes the javascript error.

    Regards,
    Tsvetina
    the Telerik team
Back to Top