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

How to mark a Treeview node as selected on server?

1 Answer 152 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 03 Oct 2013, 10:00 AM
Hi all
Due to technical reason we have to fully postback our ASP.NET MVC view. This view contains a Kendo TreeView which will be loaded and bound in the view to the model as follow:
@(Html.Kendo().TreeView()
          .Name("EditMenu")
          .DragAndDrop(true)
          .BindTo(ourModel)
      )
ourModel is:
List<Kendo.Mvc.UI.TreeViewItemModel>
It seems that there is no property 'selected' in this TreeViewItemModel class. So my question is: Is it possible to select a TreeView Node on server side? If not what would be a good solution to preserver selected Node during postback?

Thanks for help
Adrian

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Oct 2013, 08:03 AM
Hello Adrian,

Indeed, the Selected property is currently missing and we will include it for the next internal build. For now, in order to set the selected node on the server I can suggest to use the ItemAction callback:

.ItemAction(item =>
{
    if (item.Id == SelectedID)
    {
        item.Selected = true;
    }
})
or explicitly specify the binding:
.BindTo(ourModel, mapping => mapping
    .For<TreeViewItemModel>(binding => binding
        .ItemDataBound((item, node) => {
            item.Selected = node.Id == SelectedID;
            item.Text = node.Text;
            item.Id = node.Id;
            //assign all used properties                       
        })
        .Children(item => item.Items))
)
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Adrian
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or