Expand and Collapse All Nodes in TreeList

3 posts, 1 answers
  1. Kevin
    Kevin avatar
    12 posts
    Member since:
    Jun 2014

    Posted 19 Oct 2018 Link to this post

    What is the best and most efficient way to expand and collapse all nodes for a given TreeList?  I'm currently using the following code where fp-grid is the root div element of my kendoTreeList.  It works.  But it's very slow!  Is there a better and more efficient way to do this?
    var treeList = jQuery('#fp-grid').data("kendoTreeList");
    if (treeList) {
      jQuery('#fp-grid tbody>tr').each(function (index) {
        if (treeExpand) {
          treeList.expand(jQuery(this));
        } else {
          treeList.collapse(jQuery(this));
        }
      });
    }
  2. Answer
    Georgi
    Admin
    Georgi avatar
    671 posts

    Posted 23 Oct 2018 Link to this post

    Hi Kevin,

    Another possible solution is to toggle the dataSource.schema.model.expanded property and update the dataSource via the setDataSource method.

    e.g.

    var treelist =   $("#treelist").data('kendoTreeList');
    treelist.options.dataSource.schema.model.expanded = !treelist.options.dataSource.schema.model.expanded
     
    treelist.setDataSource( treelist.options.dataSource)

    Below you will find a small sample which demonstrates the above approach:



    Regards,
    Georgi
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Kevin
    Kevin avatar
    12 posts
    Member since:
    Jun 2014

    Posted 23 Oct 2018 Link to this post

    This is much faster!  Thank you!
Back to Top