ContextMenu with nested grid

4 posts, 1 answers
  1. David
    David avatar
    81 posts
    Member since:
    May 2011

    Posted 13 Jun 2011 Link to this post

    Hi,

    Is it possible to attach a context menu to a nested grid ? I currently have a radGrid with a nestedGrid and I use the following code to attach a menuContext

    function RowContextMenu(sender, eventArgs) {
        var menu;
        var ownerTable = eventArgs.get_tableView();
     
        if (ownerTable.get_name() == "Grid") {
            menu = $find("<%=RadContextMenuUser.ClientID %>");
        }
        else if (ownerTable.get_name() == "NestedGrid") {
            menu = $find("<%=RadContextMenuUsersRole.ClientID %>");
        }

        var evt = eventArgs.get_domEvent();
     
        if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") {
        return;
        }
     
        var index = eventArgs.get_itemIndexHierarchical();
        document.getElementById("radGridClickedRowIndex").value = index; 
        document.getElementById("radGridClickedTableId").value = ownerTable._data.UniqueID;
     
        sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);

    For the "parent" grid, it works really great, but it doesn't work for the nestedGrid. In fact, I have the following error : 
    Cannot call method 'get_element' of undefined.  

    So, anyone may help me please ?

  2. David
    David avatar
    81 posts
    Member since:
    May 2011

    Posted 13 Jun 2011 Link to this post

    Hi,

    Finally, try this and it work :

    var gridIndex = index.split(":", 1);
    index = index.split("_");
    sender.get_masterTableView().selectItem(sender.get_detailTables()[gridIndex].get_dataItems()[index[1]].get_element(), true);


    Edit : In fact, it seem it doesn't work that  well. In fact, in will explain again my problem, cause I realized I really wasn't clear. What I want is, when I right click on a item on the nested grid (or detail table), the item become selected and a context menu pop up. I know how to attach the context menu to the item of the nested grid, but I don't quite know how to selected this item. The code I put in this post doesn't work well, cause it doesn't un-select the previous selected item. So, my nested grid, even if AllowMultiRowSelection is set to false, allow to selected many item by this way. So, may someone help me please.

    David Lefaivre
  3. Answer
    Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 16 Jun 2011 Link to this post

    Hello David,

    You can clear the selected items before selecting a new one. I confirm it is possible to select more than one item via the client-side API.
    var masterTable = $find('<%= RadGrid1.ClientID %>').get_masterTableView();
    masterTable.clearSelectedItems();

    Kind regards,
    Daniel
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  4. David
    David avatar
    81 posts
    Member since:
    May 2011

    Posted 20 Jun 2011 Link to this post

    Thank you, it work.

    But, in fact, it wasn't get_masterTableView(), but get_detailTables(). 
Back to Top