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

Keep selected item after a post

3 Answers 160 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Bram
Top achievements
Rank 1
Bram asked on 04 Apr 2013, 01:14 PM
I've created a panelbar in the Layout:

@(Html.Kendo().Splitter()
            .Name("mainsplitter") //The name of the splitter is mandatory. It specifies the "id" attribute of the widget.
            .Panes(panes =>
            {
                panes.Add().Content(@<text>@Html.Action("_Panelbar")</text>)
                            .Resizable(true)
                            .Size("20%");
                panes.Add().Content(@<text>
                            <section class="content-wrapper main-content clear-fix">
                                @RenderBody()
                            </section>
                            </text>); //Add pane
            })
            )
And a rendersection for the main content, it all goes well, but when I
change the main content Model, the panelbar jumps to the first item.
When I return only the ViewBag, and no Model, the panelbar is keeping
the selected item.
What have I to do for keep always the selected item ?

And in the _PanelbarView:

@model CPMPlanning.Models.CPMModelViewPanel

@( Html.Kendo().PanelBar()
    .Name("PanelBar")  
    .SelectedIndex(Model.ObjectIDSelected)
    .ExpandMode(PanelBarExpandMode.Single)
    .BindTo(Model.ObjectTypes, mappings =>
    {
        mappings.For<CPMPlanning.Models.ObjectTypeView>(binding => binding
                .ItemDataBound((item, objecttype) =>
                {
                    item.Text = objecttype.ObjectTypeDesc;

                })
                .Children(o => o.Objects));
        mappings.For<CPMPlanning.Models.ObjectView>(binding => binding
                .ItemDataBound((item, obj) =>
                {
                    item.Text = obj.ObjectCode;
                    item.Url = Url.Action("Index", "CPMModel", new { id = obj.ObjectID });
                })
            );
    })
)

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Apr 2013, 11:25 AM
Hi,

I am not sure if I understand correctly the exact scenario. Could you clarify how are you changing the model and how is the "ObjectIDSelected" value determined?

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bram
Top achievements
Rank 1
answered on 09 Apr 2013, 10:23 AM
Sorry, The ObjectID selected is not used anymore, it was just testing..
The problem is: First, I had this panelbar as a partial view in the index page, but for reasons I've replaced it to the Layout structure with a splitter, but now the " automatic selecteditem" is not working anymore.. If you put the panelbar back in the index, and even after a GET, the panelbar is select automatic the previous selected item (That's what I want).

_Layout:
       @(Html.Kendo().Splitter()
            .Name("mainsplitter") //The name of the splitter is mandatory. It specifies the "id" attribute of the widget.
            .Panes(panes =>
            {
                panes.Add().Content(@<text>@Html.Action("_Panelbar")</text>)
                            .Resizable(true)
                            .Size("20%");
                panes.Add().Content(@<text>
                            <section class="content-wrapper main-content clear-fix">
                                @RenderBody()
                            </section>
                            </text>); //Add pane
            })
            )
0
Bram
Top achievements
Rank 1
answered on 09 Apr 2013, 01:06 PM
Hi I solved it by giving " expanded" and " selected" in the view, and then:

@( Html.Kendo().PanelBar()
    .Name("PanelBar")  
    //.SelectedIndex(Model.ObjectDescSelected)
    .ExpandMode(PanelBarExpandMode.Single)
    .BindTo(Model.ObjectTypes, mappings =>
    {
        mappings.For<CPMPlanning.Models.ObjectTypeView>(binding => binding
                .ItemDataBound((item, objecttype) =>
                {
                    item.Expanded = objecttype.IsExpanded;
                    item.Text = objecttype.ObjectTypeDesc;
                })
                .Children(o => o.Objects));
        mappings.For<CPMPlanning.Models.ObjectView>(binding => binding
                .ItemDataBound((item, obj) =>
                {
                    item.Selected = obj.IsSelected;
                    item.Text = obj.ObjectCode;
                    item.Url = Url.Action("Index", "CPMModel", new { id = obj.ObjectID });
                })
            );
    })
)

Tags
PanelBar
Asked by
Bram
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Bram
Top achievements
Rank 1
Share this question
or