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

[Solved] Expand selected item childs on page load

2 Answers 79 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.
Mattias
Top achievements
Rank 1
Mattias asked on 21 Oct 2011, 08:39 AM
Hi,
I want to expand the selected item childs on page load, is that possible?
It seems that the first level items already have this behavior, but not second or third hierarchy items and so on.
@(Html.Telerik().PanelBar()
            .Name("ArticleGroupSubMenu")
            .HtmlAttributes(new { style = "width: 200px;" })
            .BindTo(Model.GetChildMenu(), mappings =>
            {
                mappings.For<ArticleGroupEditViewModel>(binding => binding
                        .ItemDataBound((item, group) =>
                        {
                            item.Text = group.Text;
                            item.Url = group.Url;
                        })
                        .Children(group => group.Childs));
                mappings.For<ArticleGroupEditViewModel>(binding => binding
                        .ItemDataBound((item, group) =>
                        {
                            item.Text = group.Text;
                            item.Url = group.Url;
                        }));
            })
            .ExpandMode(PanelBarExpandMode.Multiple)
            .ExpandAll(true)
            .HighlightPath(true)
        )

Regards,
Mattias

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 21 Oct 2011, 09:13 AM
Hi Mattias,

You can expand all PanelBar child items by subscribing to the component's OnLoad event and executing:

function ExpandSubItems(e)
{
    var panelBar = $(this).data("tPanelBar");
    var items = $("li.t-item li.t-item", this);
    panelBar.expand(items);
}

Alternatively, you can expand only selected child items, like this:

function ExpandSubItems(e)
{
    var panelBar = $(this).data("tPanelBar");
    var items = $("li.t-item li.t-state-selected", this);
    panelBar.expand(items);
}


Kind regards,
Dimo
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Mattias
Top achievements
Rank 1
answered on 21 Oct 2011, 10:22 AM
Thanx Dimo,
Your code didn't quite work so I I had to modify it a bit! :)

function ExpandSubItems(e)
{
       var panelBar = $(this).data("tPanelBar");
       var selectedlink = $("li.t-item a.t-state-selected", this);
       var li = selectedlink.parent();
       panelBar.expand(li);
}

/Mattias
Tags
PanelBar
Asked by
Mattias
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Mattias
Top achievements
Rank 1
Share this question
or