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

grid with context menu problem

3 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ulrich
Top achievements
Rank 1
Ulrich asked on 06 Jul 2010, 11:17 AM
Hello Telerik Team,

I have the following scenario:

a raddatagrid, using a radajaxmanager, created programmatically, populated in "onneeddata"

a radmenu acting as a context menu, also created programmatically, and populated with (hierarchical) menu items

client-side listener on onrowcontextmenu on the grid, which looks like this:

 function RowContextMenu(sender, eventArgs) { 
            var menu = $find("ctl00_ccp_rgid"); 
            var id = eventArgs.getDataKeyValue("ID"); 
            for (var i = 0; i < menu._children._array.length; i++) { 
                setMenuLink(menu._children._array[i],id); 
            } 
    }  
 
 
        function setMenuLink(menuitem, id) { 
            if (menuitem._linkElement != null) { 
                setID(menuitem._linkElement.href, id); 
                menuitem._linkElement.href = setID(menuitem._linkElement.href, id);        } 
            if (menuitem._children != null && menuitem._children._array != null) { 
                for (var i = 0; i < menuitem._children._array.length; i++) { 
                    setMenuLink(menuitem._children._array[i], id); 
                } 
            } 
        } 

I face two problems

1) When I first right click on a row, only the top level menu items are set with "setMenuLink", because "menuitem._children is null. When I wait for a second and right click a second time, menuitem._children has the correct entries and everything works. How can I change my approach to make this work?
2) If a ajax postback happens (by filtering, grouping, sorting, changing the page etc.) the contextmenu stops working. onrowcontextmenu is triggered, and
var menu = $find("ctl00_ccp_rgid");
even returns the correct menu object, but no menu is drawn on screen, neither is the onclientshowing event triggered. The ContextMenu is created programmatically like this (snippet from the OnInit-Method of the UserControl (a derivate from a radsplitter) hosting both the grid and the context menu):

  if (this.GridController.DataGrid is WebControl) 
            { 
                ContextMenuControlTarget target = new ContextMenuControlTarget(); 
                target.ControlID = (this.GridController.DataGrid as WebControl).ID; 
                (this.GridController.DataGrid as RadGrid).ClientSettings.ClientEvents.OnRowContextMenu = "RowContextMenu"
                RadContextMenu menu = new RadContextMenu(); 
                menu.OnClientShowing = "OnClientShowing"
                menu.ID = "rgid"
    
                ICollection<WebNavigationNode> nodes = (this.Engine as ASPNetTelerikEngine).GetNavigationNodesForRecord(this.Record); 
 
                foreach (WebNavigationNode node in nodes) 
                { 
                    this.addNavigationNode(menu, null, node); 
                } 
                menu.Targets.Add(target); 
                menu.Skin = this.Skin; 
                gridpane.Controls.Add(menu); 
            } 


Any help is greatly appreciated

best regards

Ulrik




3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 09 Jul 2010, 02:54 PM
Hello Ulrich,

Could you please confirm you have added the RadContextMenu as updated control from all controls which are updating the grid?
Try it out and let me know how it goes.

Kind regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ulrich
Top achievements
Rank 1
answered on 15 Jul 2010, 02:18 PM
Hello,

that was indeed a major oversight on my part. After adding the menu to the radajaxmanager, one of the problems was solved.

I still have the proplem that when I loop through the menu items in the "RowContextMenu"-handler on client-side, the first time I loop through them, the children-element is null. I guess I have to call a function to populate the children?

best regards

Ulrik
0
Ulrich
Top achievements
Rank 1
answered on 15 Jul 2010, 02:24 PM
PS: I managed to overcome the problem with this, but I am sure there is a more elegant and correct solution:

function setMenuLink(menuitem, id) {
           if (menuitem._linkElement != null) {
               setID(menuitem._linkElement.href, id);
               menuitem._linkElement.href = setID(menuitem._linkElement.href, id);; //  menuitem._linkElement.href.replace("-42", id);
           }
           menuitem.open(); //HOTFIX
           menuitem.close(); //HOTFIX
           if (menuitem._children != null && menuitem._children._array != null) {
               for (var i = 0; i < menuitem._children._array.length; i++) {
                   setMenuLink(menuitem._children._array[i], id);
               }
           }
       }

best regards

Ulrik
Tags
Grid
Asked by
Ulrich
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Ulrich
Top achievements
Rank 1
Share this question
or