treejs icon indicating copy to clipboard operation
treejs copied to clipboard

Collapse all on load and then collapse level-by-level

Open DarthSonic opened this issue 2 years ago • 2 comments

closeDepth: 1 will help me to only show the first level of the tree with all collapsed.

If I click on an item it will open, but it opens all childrens not only the next level/children. How can I prevent this?

DarthSonic avatar Nov 15 '22 13:11 DarthSonic

I solved this issue by using the collapseAll() function in the built-in loaded function:

  let newTree = function(data){
    let tree = new Tree('.container', {
    data: data,
    closeDepth: 1,
    loaded: function () {
      this.collapseAll()
      },
      onChange: function () {
      }
    })
  }

ChrBaum avatar Nov 24 '22 14:11 ChrBaum

`function preventChildExpansion() {

$('.treejs-switcher').each(function () {
    var $parent = $(this).closest('.treejs-node');
    if (!$parent.hasClass('treejs-node__close')) {
        $parent.addClass('treejs-node__close');
    }
});

}`

Then, when tree is loaded : loaded: function () { preventChildExpansion(); }

AlexBDXMET avatar Sep 29 '23 14:09 AlexBDXMET