Set Selected Color for Parent Item

6 posts, 0 answers
  1. Telerikuser
    Telerikuser avatar
    35 posts
    Member since:
    May 2009

    Posted 01 Mar 2010 Link to this post

    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.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Mar 2010 Link to this post

    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.
  3. Telerikuser
    Telerikuser avatar
    35 posts
    Member since:
    May 2009

    Posted 03 Mar 2010 Link to this post

    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.

  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 08 Mar 2010 Link to this post

    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.
  5. Telerikuser
    Telerikuser avatar
    35 posts
    Member since:
    May 2009

    Posted 08 Mar 2010 Link to this post

    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.
  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 11 Mar 2010 Link to this post

    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.
Back to Top