Binding Expanded of treeview (mvc)

7 posts, 1 answers
  1. Justin Lee
    Justin Lee avatar
    149 posts
    Member since:
    Dec 2009

    Posted 27 Apr Link to this post

    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)
         );
       })
     )

  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 29 Apr Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Justin Lee
    Justin Lee avatar
    149 posts
    Member since:
    Dec 2009

    Posted 15 Nov Link to this post

    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.)

  5. Justin Lee
    Justin Lee avatar
    149 posts
    Member since:
    Dec 2009

    Posted 15 Nov Link to this post

    Correction - the version we are using (where is it not working) is:  R3 2016 SP1
  6. Answer
    Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    278 posts

    Posted 17 Nov Link to this post

    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.
  7. Justin Lee
    Justin Lee avatar
    149 posts
    Member since:
    Dec 2009

    Posted 17 Nov in reply to Veselin Tsvetanov Link to this post

    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!

  8. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    278 posts

    Posted 21 Nov Link to this post

    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.
Back to Top
Kendo UI is VS 2017 Ready