vakata / jstree

jquery tree plugin
http://jstree.com
MIT License
5.15k stars 1.38k forks source link

State is cleared after refreshing #2744

Closed kosnkow closed 1 year ago

kosnkow commented 1 year ago

I am drawing different tree based on user clicked raw so I need to save many states

i am initializing tree as this

$('#keywordTree').jstree({
    'core': {
        'themes': {
            'icons': false
        }
    },
    "plugins": ["state"]
});
treeInit = true;

and after user select the row i bind data like this

    function drewRelationTree(secondaryCode) {
        $('#keywordTree').jstree(true).settings.core.data = relationTree;
        $('#keywordTree').jstree(true).settings.state.key = secondaryCode;
        $('#keywordTree').jstree(true).refresh();
    }

different states work when switching between different rows until i refresh the page. Then when i cling some row the state is cleared.

vakata commented 1 year ago

Keep in mind that the tree is using the default key initially. Also - refresh will not trigger a restore_state - consider calling it manually. You can check the events here: https://github.com/vakata/jstree/blob/master/src/jstree.state.js

kosnkow commented 1 year ago

I endup with sth like this (working version https://stackoverflow.com/questions/77025778/state-is-cleared-after-refreshing) but set timout to 100ms to be sure it is fired after you reset state after refresh. Because I saw jstree will always restore to empty state after refresh. @vakata