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

Binding Expanded of treeview (mvc)

6 Answers 252 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 27 Apr 2016, 04:16 PM

It appears setting the Expanded property in the ItemDataBound event doesn't work. Is that correct?  What options do I have?

For example:  Setting item.Expanded doesn't appear to do anything.  (I verified IsExpanded is true in my models)

@(Html.Kendo().TreeView()
  .Name("TestTree")
  .ExpandAll(false)
  .BindTo(Model.Items, mappings =>
  {
     mappings.For<MyModelClass>(binding =>
       binding.ItemDataBound((item, child) =>
       {
         item.Text = child.Name;
         item.Selected = child.IsSelected;
         item.Expanded = child.IsExpanded;
       })
       .Children(x => x.ChildItems)
     );
   })
 )

6 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 29 Apr 2016, 07:22 AM
Hello Justin,

The ExpandAll(false) call registers a post-processing action that is executed after the call to BindTo. Thus, after binding, all Expanded flags are set to false. To resolve this, remove the call to ExpandAll.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Justin Lee
Top achievements
Rank 1
answered on 15 Nov 2016, 03:00 PM

Hello,

Removing ExpandAll fixed the issue -- until we upgraded to Q3 2016.  Now the binding to Expanded is not working again.
The code above without the call to ExpandAll is not expanding items where item.IsExpanded is true.  (I put a breakpoint on the binding method and verified child.IsExpanded was true.)

0
Justin Lee
Top achievements
Rank 1
answered on 15 Nov 2016, 03:05 PM
Correction - the version we are using (where is it not working) is:  R3 2016 SP1
0
Accepted
Veselin Tsvetanov
Telerik team
answered on 17 Nov 2016, 12:33 PM
Hi Justin,

Attached you will find a simple MVC 5 application, based on your scenario, using the R3 2016 SP1 release. When testing it on our side, the Expanded property of the item is properly mapped from the property of the ViewModel.

May I ask you to specify how to modify this sample so it reproduces the problem observed?

Regards,
Veselin Tsvetanov
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
0
Justin Lee
Top achievements
Rank 1
answered on 17 Nov 2016, 03:20 PM

Hi Veselin,

Thank you for taking the time to create the project.  Our code was setting item.HasChildren = child.ChildItems.Any() in the databinding.  Once I added that to your project, I reproduced the issue.  However, it looks like HasChildren does not need to be set - I assume it is for load on demand trees. (which makes sense)  I removed HasChildren from our page, and it is working as expected.

Thanks!

0
Veselin Tsvetanov
Telerik team
answered on 21 Nov 2016, 08:14 AM
Hi Justin,

Yes, indeed, the item.HasChildren is used when having a load on demand tree, so it knows how to render those nodes that could be expanded and those, that could not.

Regards,
Veselin Tsvetanov
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
Tags
TreeView
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Justin Lee
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Share this question
or