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

Grid context menu

8 Answers 210 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rwozniak
Top achievements
Rank 1
rwozniak asked on 03 Jul 2008, 03:11 PM

I have a RadGrid with an associated RadContextMenu. When I right-click a row on the grid and click one of the context menu items I need to get at the selected row in the context menu's event handlers. However, I found that the SelectedItems collection is empty.

I was able to work around this by adding an OnRowContextMenu handler, with code like this:

function Grid_OnRowContextMenu(sender, args)
{
    var index = args.get_itemIndexHierarchical();
    var row = sender.MasterTableView.get_dataItems()[index];
    row.set_selected();
}

This partially works, but it seems like there should be an easier way to do this. For one, it doesn't deselect other selected rows. Right now I have to add this client-side handler to every single one of my grids. It seems like there should be some sort of property on the grid that enables row selection on right click.

One other problem I have is that I do not want the context menu to show when the grid has no rows. With the old RadGrid I was able to check the row's ItemType property. If it was "NoRecordsItem", I would not show the context menu.

8 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 07 Jul 2008, 10:17 AM
Hi rwozniak,

There is no internal mechanism which to select a grid row automatically on right-click, however you can select the relevant record explicitly either with the approach you already discovered or as demonstrated in this integration example:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Controls/Examples/Integration/GridAndMenu/DefaultCS.aspx?product=grid

Concerning your question about the context menu display when there are no records available in the grid:
Consider detecting whether the right-clicked row has data key value available (inside the OnRowContextMenu client event handler) and if such value is not present, avoid calling the show() method of the context menu.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
rwozniak
Top achievements
Rank 1
answered on 07 Jul 2008, 01:47 PM
Thanks for the response.

Given the fact that this is a common need, I highly recommend that you at least add this support to the RadGrid, or better yet, the RadGrid should really have a ContentMenu collection, like the RadTreeView.

What it really needs is the ability to associate a context menu to a grid row, and to associate one with the grid itself. In other words, the row-level context menu would show when the user right clicks on a grid row, and might be used for such commands as Cut and Copy. The non-row-level one should appear when right-clicking in the empty area below the last grid row (assuming that the grid has some white area below it). This could be used for such commands that do not apply to any particular grid row...like Paste.

0
Rosen
Telerik team
answered on 08 Jul 2008, 02:40 PM
Hello rwozniak,

Thank you for the suggestion.

I will forward your request to our development department for further consideration. If this appears to be a common request and an attainable enhancement, you may see it included in a future version of the product.

Meanwhile you may consider using the solutions provided by my colleague.

Best regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
rwozniak
Top achievements
Rank 1
answered on 11 Jul 2008, 07:09 PM
Regarding the suggestion to not call show() if there is no data key present, the only problem is that I am not calling show().

Instead, I have associated the context menu with the grid by setting the grid as a ContextMenuControlTarget.
0
Kenny
Top achievements
Rank 1
answered on 15 Aug 2008, 07:45 PM
I need a Grid-specific context menu that performs similar thing as well. Having the menu built-in would be great.

Thanks,
Kenny
0
Christian
Top achievements
Rank 1
answered on 20 Sep 2008, 04:50 PM
I second the notion to have built-in support for context menus in radGrid since this is somewhat hard to do when using nested grids.
0
rwozniak
Top achievements
Rank 1
answered on 03 Oct 2008, 09:19 AM
By the way the RadGrid should support two levels of context menu. One would be a row-level context menu. This is one that might have items like Edit and Delete. Operations that a user would need to perform on specific records in the grid.

The other is a grid-level context menu. In other words, one that would appear when the user right-clicks in the empty area below the last record in the grid. This is where you would put grid-level items like Paste.

If I wanted to Copy from one grid and Paste into another, I would expect the behavior to be like Windows Explorer. I would right-click on a row in the first grid and select Copy. I would then right-click in an open area (not on a row) in the second grid and select Paste.

This is a very common user interface need, certainly one that I need to implement in the product that I am building with your control set, so I hope that this support will be coming soon in RadGrid. Although I have been able to come up with a less than perfect solution for the row-level context menu (by writing some custom JavaScript), I have yet to find a way to pull off the grid-level (Paste) context menu, and have temporarily had to rely on a Paste button in my toolbar.

Thanks,
Ross
0
Rosen
Telerik team
answered on 03 Oct 2008, 01:04 PM
Hi rwozniak,

Thanks for the additional feedback and thoughts shared.

All the best,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
rwozniak
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
rwozniak
Top achievements
Rank 1
Rosen
Telerik team
Kenny
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Share this question
or