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

[Solved] Confused about RadGrid and ContextMenu

7 Answers 165 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 24 Apr 2009, 02:50 PM
I am trying to have a context menu in my grid but have no joy so far...

<telerik:RadContextMenu ID="GridContextMenu" runat="server"
    <Targets> 
        <telerik:ContextMenuControlTarget ControlID="RadGridKids" /> 
        <telerik:ContextMenuControlTarget ControlID="Label1" /> 
    </Targets> 
    <Items> 
        <telerik:RadMenuItem runat="server" Text="Root Stuff"
            <Items> 
                <telerik:RadMenuItem runat="server" Text="Child RadMenuItem 1"
                </telerik:RadMenuItem> 
                <telerik:RadMenuItem runat="server" Text="Child RadMenuItem 2"
                </telerik:RadMenuItem> 
            </Items> 
        </telerik:RadMenuItem> 
        <telerik:RadMenuItem runat="server" Text="Root Item 2"
        </telerik:RadMenuItem> 
    </Items> 
</telerik:RadContextMenu> 
 
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
 
<telerik:RadGrid ID="RadGridKids" runat="server" GridLines="Horizontal" OnItemDataBound="RadGridKids_ItemDataBound" 
    AutoGenerateColumns="False" Height="99%" ShowStatusBar="True" GroupingEnabled="False"
    <MasterTableView CellSpacing="-1"
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
        <Columns> 
            <telerik:GridBoundColumn HeaderText="Node Description" UniqueName="NodeDesc"
            </telerik:GridBoundColumn> 
        </Columns> 
    </MasterTableView> 
    <ClientSettings> 
        <Selecting AllowRowSelect="True" /> 
        <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
        <ClientEvents OnRowContextMenu="GridRowContextMenu" /> 
    </ClientSettings> 
</telerik:RadGrid> 
 

My grid is populated via assigning a DataSource in an Ajax Request.
In the ..._ItemDataBound, I assign a Tooltip to each item.

Before the Grid is populated, the code shows the context menu fine on the label and on the datagrid.
The GridRowContextMenu(...) does not fire which I suppose is normal since there are no rows.

After the grid is populated, the GridRowContextMenu() javascript fires all right but there is no more context menu on the Grid...

Am I supposed to do something when DataBinding the grid?


Thanks


Eric

7 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 24 Apr 2009, 04:57 PM
Hello Eric,

This can occur if the context menu is not updated after the ajax request. Please configure your RadAjaxManager to update the context menu as well.

Regards,
Albert
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
Eric
Top achievements
Rank 1
answered on 27 Apr 2009, 10:59 AM
If you knew how many hair I left on this one!

Many Thanks, that solved it.

Eric
0
Eric
Top achievements
Rank 1
answered on 27 Apr 2009, 02:53 PM
Another question if I may...

Now, I can see my context menu... too much!

How do I prevent it showing on the grid header row?
I can't spot the right event for doing that.


0
Atanas Korchev
Telerik team
answered on 27 Apr 2009, 04:26 PM
Hello Eric,

This is possible but would require some JavaScript. Please check this online example for a running implementation.

All the best,
Albert
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
Eric
Top achievements
Rank 1
answered on 27 Apr 2009, 04:48 PM
Albert,

I already trap the OnRowContextMenu() through javascript but my current problem is that this event does not fire when right clicking on the header rather than a row, so I don't have a hook to prevent the context menu to show when clicking on the header...

Eric
0
Accepted
Atanas Korchev
Telerik team
answered on 28 Apr 2009, 07:35 AM
Hello Eric,

Please check the provided example. It shows how to show the context menu only for the rows. The trick there is that the context menu is shown using javascript not by creating a target for the grid.

All the best,
Albert
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
Eric
Top achievements
Rank 1
answered on 28 Apr 2009, 08:51 AM
Ok, there were so many examples to look at that I missed this bit!

I found a "dirty trick" but it sucks a bit so I'll switch to your advice.
On the ContextMenuShowing event, I spotted that the tagName of the TargetElement is TH for a header and TD for a row...

        function GridCtxtMenuShowing(sender, eventArgs) {  
            if ( eventArgs._targetElement.tagName == "TH" )  
                eventArgs.set_cancel(true);  
        }  
 


Many Thanks.

Eric
Tags
Menu
Asked by
Eric
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Eric
Top achievements
Rank 1
Share this question
or