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

Set Selected Color for Parent Item

5 Answers 118 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Telerikuser
Top achievements
Rank 1
Telerikuser asked on 01 Mar 2010, 07:42 PM
How would I set a parent item to be selected when a child is selected? I want to achieve this in Client Side.

Any help is appreciated.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Mar 2010, 11:39 AM
Hello,

You can try the following client code in order to select the parent item of clicked menuitem.

Javascript:
 
    var parent; 
    function OnClientItemClicked(sender, args) { 
        parent = args.get_item().get_parent();        
        if (parent.get_parent()!= null
        { 
             setTimeout('parent.set_selected(true);', 200); 
        } 
    } 
[Attach OnClientItemClicked event to RadMenu]

-Shinu.
0
Telerikuser
Top achievements
Rank 1
answered on 03 Mar 2010, 05:49 PM
Thanks. It works. However I want to have bothe parent and child to be selected is it possible? Similar to the HighlightPath in server side.

0
Peter
Telerik team
answered on 08 Mar 2010, 01:29 PM
Hello subi,

Please, try the following code:

<script type="text/javascript">
       function OnClientItemClicked(sender, args) {
           //clear previously selected path
           for (var i = 0; i < sender.get_allItems().length; i++) {
               sender.get_allItems()[i].set_cssClass('');
           }
             
           highLightPath(args.get_item());
             
       }
       function highLightPath(menuItem) 
       {
           menuItem.set_cssClass("rmFocused");
           var parent = menuItem.get_parent();
           if (parent.get_parent() != null) {
               highLightPath(parent);
           }
       }
   </script>


Best wishes,
Peter
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
Telerikuser
Top achievements
Rank 1
answered on 09 Mar 2010, 12:06 AM
Thanks for the code. This code works only if I have clickonopen, if I have mouse over open for submenus it is not selecting the parent item. Any help is appreciated.
0
Veselin Vasilev
Telerik team
answered on 11 Mar 2010, 02:23 PM
Hi ,

Actually the above code will work when you click the item. It is not necessary to enable the ClickToOpen property.

If you need to run that code on mouse over - then use the OnClientMouseOver event instead of OnClientItemClicked.

Kind regards,
Veskoni
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.
Tags
Menu
Asked by
Telerikuser
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Telerikuser
Top achievements
Rank 1
Peter
Telerik team
Veselin Vasilev
Telerik team
Share this question
or