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

[Solved] PanelBar Links?

3 Answers 58 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brian
Top achievements
Rank 1
Brian asked on 08 Jul 2011, 09:59 PM
I have code like this:

@{ Html.Telerik().PanelBar()
                   .Name("BrowsePanelBar")
                   .ExpandMode(PanelBarExpandMode.Single)
                   .Items(parent =>
                   {
                       parent.Add()
                           .Text("Books")
                           .Action("Index","Books")
                           .Content(
    @<text>
    <div class="divBrowseDetails">
        <ul class="ulBrowseCat">
            <li><a href="#">Books</a></li>
            <li><a href="#">EBooks</a></li>
            <li><a href="#">Series</a></li>
            <li><a href="#">New Arrivals</a></li>
            <li><a href="#">Top Sellers</a></li>
        </ul>
    </div>
    </text>)
                            .Expanded(true);
                       parent.Add()
                           .Text("Bibles")
                           .Action("Index", "Bibles")
                           .Content(
    @<text>
    <div class="divBrowseDetails">
        <ul class="ulBrowseCat">
            <li><a href="#">Bibles</a></li>
            <li><a href="#">New Arrivals</a></li>
            <li><a href="#">Top Sellers</a></li>
            <li><a href="#">Bible Finder</a></li>
            <li><a href="#">Bible Translation Guide</a></li>
        </ul>
    </div>
    </text>);
                   })
                .Render();
}

Now, I thought that by adding the Action method onto the parent items, I would be able to use those parent items as links as well as click on their arrows to expand/collapse the section.  But, no matter where I click on the parent bar, it only expands/collapses.  Is there a way to use it as a link also?

Thanks

3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 11 Jul 2011, 12:28 PM
Hello Brian,

The panelbar expands/collapses automatically when you have child nodes or a child template (like in your case). If the root links navigated, there wouldn't be a way to expand the groups except manually (from the server). Enabling the navigation through the root links can be achieved as follows:

$("#PanelBar").bind("expand", function(e) {
    var link = $(e.item).find(">a");
 
    if (link.length) {
        // prevent expanding, since the browser will be redirected
        e.preventDefault();
        // redirect
        window.location.href = link.attr("href");
    }
});

Regards,
Alex Gyoshev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Brian
Top achievements
Rank 1
answered on 11 Jul 2011, 04:37 PM
That's almost what I need.

What I was hoping is that if you clicked on the root nodes description (in my case the word "Books" or the word "Bibles") it would navigate to the appropriate url.  But, if you clicked on the bar itself or the arrow at the end, it would expand/collapse.

Is there a nifty javascript way to do that?

Thanks!
0
Alex Gyoshev
Telerik team
answered on 13 Jul 2011, 09:50 AM
Hello Brian,

There always is!

  1. Style the expand/collapse arrows:
    .t-panelbar-expand, .t-panelbar-collapse {
        border: 1px solid #A7BAC5; /* or another color, depending on the skin */
        border-radius: 3px;
    }
  2. Add the following JavaScript to make the arrows expand/collapse the items:
    $(".t-panelbar-expand, .t-panelbar-collapse").bind("click", function(e) {
        e.preventDefault();
        var arrow = $(this),
            item = arrow.closest('.t-item');
        item.closest(".t-panelbar").data("tPanelBar")._toggleItem(item, item.find('>.t-group').is(":visible"));
    });
Regards,
Alex Gyoshev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
PanelBar
Asked by
Brian
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Brian
Top achievements
Rank 1
Share this question
or