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

Tooltips for dynamic menu items?

2 Answers 98 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Greg Chung
Top achievements
Rank 1
Greg Chung asked on 20 Jun 2008, 04:14 PM
I'm experimenting with the dynamic menus via web service, and they're pretty slick.  However, I can't figure out how to set the tooltips.  For a static menu, I can assign the ToolTip attrib on the RadMenuItem.  I don't know how to handle this for dynamic items.  I tried to add "ToolTip" to the attributes in the items returned by the web service.  This by itself didn't work, and I don't know how I can assign the tooltips from the item creating/populating JS events?

If someone has an example of tooltips on the dynamic items, it would be very much appreciated!

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 23 Jun 2008, 02:56 PM
Hi Greg Chung,

Indeed setting the ToolTip is not currently supported out of the box. However you ca easily use the Value or Attributes property to send the tooltip (from the web service method). Then you can use the OnClientItemPopulated event to set the Tooltip for the dynamically added items.

Here is a simple code sample:

The WebService method:

public RadMenuItemData[] GetMenuCategories(RadMenuItemData item, object context) 
    { 
        DataTable productCategories = GetProductCategories(item.Value); 
 
        List<RadMenuItemData> result = new List<RadMenuItemData>(); 
 
        foreach (DataRow row in productCategories.Rows) 
        { 
            RadMenuItemData itemData = new RadMenuItemData(); 
            itemData.Text = row["Title"].ToString(); 
            itemData.Value = row["CategoryId"].ToString(); 
            itemData.Attributes["TT"] = row["Title"].ToString() ; 
 
            if (Convert.ToInt32(row["ChildrenCount"]) > 0) 
            { 
                itemData.ExpandMode = MenuItemExpandMode.WebService; 
            } 
 
            result.Add(itemData); 
        } 
 
        return result.ToArray(); 
    } 

The OnClientItemPopulated event handler:

<script type="text/javascript"
function OnClientItemPopulatedHandler(sender, eventArgs) 
    var parent = eventArgs.get_item(); 
    var items = parent.get_items(); 
     
    for (var i = 0; i < items.get_count(); i++) 
    { 
        var child = items.getItem(i); 
        child.get_element().title = child.get_attributes().getAttribute("TT"); 
    } 
</script> 

I hope this helps.

Regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Greg Chung
Top achievements
Rank 1
answered on 24 Jun 2008, 02:01 PM
Thanks!  That works perfectly!
Tags
Menu
Asked by
Greg Chung
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Greg Chung
Top achievements
Rank 1
Share this question
or