mar10 / dynatree

Automatically exported from code.google.com/p/dynatree
92 stars 37 forks source link

New nodes always collapsed after reload #501

Closed deflexor closed 8 years ago

deflexor commented 8 years ago

I have tree that gets data via ajax json. When i call tree.reload() and new children come from server, they always collapsed, not only they but also parent nodes in which they appeared. Any help how to change this behaviour ? I tried autoCollapse option and also tried adding expand: true to json data, but without effect. I use latest version of dynatree: 1.2.8

mar10 commented 8 years ago

Could set up a sample, jsFiddle, or plunkr that reproduces this?

deflexor commented 8 years ago

Is it possible to emulate json backend for dynatree with jsFiddle ? I tried (http://jsfiddle.net/xj5au/165/), but with no luck.

deflexor commented 8 years ago

Here is working Plunkr: https://plnkr.co/edit/XDmdwox345o1Azb1E1y9?p=preview

mar10 commented 8 years ago

Does it work for you if you set 'persist: false'?

deflexor commented 8 years ago

Not quite, for example one wants to close "Folder 2", press "Reload tree" button, and after tree reload wants to see "Folder 2" closed and other folders open. With 'persist: false' this is not the case.

mar10 commented 8 years ago

You could try to pass explicit keys in the json data, to make persistance work

deflexor commented 8 years ago

Thank you, I updated plunkr code and "Folder 2" now stays expanded, but other nodes still doesn't respect expand: true

mar10 commented 8 years ago

(I did not see any changes in the Plunkr, but anyway:)

  1. Persistance requires that all node have an explicit unique key.
  2. Initial status is read from cookies, if persistence is active and cookies are already present. Otherwise the status is read from the data attributes and then persisted.

This means, that if persistence is on, it controls the expansion state: All nodes that have their key stored in the cookie are expanded. All others are collapsed.

The json status is ignored in this case.

deflexor commented 8 years ago

Is it possible to somehow change this bahaviour ? The fix should be easy as it goes.

mar10 commented 8 years ago

It's not a bug. If persistence is on and cookies have been set, this determines the status. Otherwise, json determines the status.

Dynatree is feature frozen since 2014, so I don't plan to add improvements. Maybe you want to have a look at fancytree, which might be easier to customize.