Grid context menu

9 posts, 0 answers
  1. rwozniak
    rwozniak avatar
    47 posts
    Member since:
    Oct 2007

    Posted 03 Jul 2008 Link to this post

    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.

  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 07 Jul 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. rwozniak
    rwozniak avatar
    47 posts
    Member since:
    Oct 2007

    Posted 07 Jul 2008 Link to this post

    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.

  5. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 08 Jul 2008 Link to this post

    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
  6. rwozniak
    rwozniak avatar
    47 posts
    Member since:
    Oct 2007

    Posted 11 Jul 2008 Link to this post

    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.
  7. Kenny
    Kenny avatar
    1 posts
    Member since:
    Aug 2008

    Posted 15 Aug 2008 Link to this post

    I need a Grid-specific context menu that performs similar thing as well. Having the menu built-in would be great.

    Thanks,
    Kenny
  8. Christian
    Christian avatar
    64 posts
    Member since:
    Apr 2008

    Posted 20 Sep 2008 Link to this post

    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.
  9. rwozniak
    rwozniak avatar
    47 posts
    Member since:
    Oct 2007

    Posted 03 Oct 2008 Link to this post

    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
  10. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 03 Oct 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017