jsTree Refresh - Keep Nodes Open

2,127 views
Skip to first unread message

Trevor Pope

unread,
Jan 27, 2014, 4:04:22 AM1/27/14
to jst...@googlegroups.com
Hi,

I'm using jsTree 3 Beta 4 with the State plugin, when refreshing the tree the State plugin will re-open nodes that were selected but will not keep open nodes that were just open.

Please can you point me in the direction of how can I make this happen?

Many thanks

Trev

Ivan Bozhanov

unread,
Jan 27, 2014, 4:23:52 AM1/27/14
to jst...@googlegroups.com
Are your IDs OK? I mean - are they persistent - make sure you always have node IDs. Other than that - it should work. Maybe you have more than one instance of a tree on the page? In that case you must configure the "key" option of the state plugin.
Please show me your code and data so that I can reproduce and help further.

Best regards,
Ivan

Trevor Pope

unread,
Jan 27, 2014, 8:01:15 AM1/27/14
to jst...@googlegroups.com
Thank you for coming back to me.

<script type="text/javascript" src="Script/jstree.js"></script>
    <script type="text/javascript" src="Script/jstree.search.js"></script>
    <script type="text/javascript" src="Script/jstree.state.js"></script>
    <script language="javascript" type="text/javascript">
        $(function() {
$('#jstree_div').jstree({
                'core': {
                    'data': {
                        'method': 'GET',
                        'type': 'json',
                        'url': '/Json/ING-Json.json'
                    },
                    'themes': {
                        'theme': 'default',
                        'responsive': false
                    }
                },
                "plugins": [ "state", "search", "wholerow", "ui" ],
            });
});
    </script>

<div id="jstree_demo_div">
    </div>

The state plugin does remember which node(s) was selected and will re-open any parent nodes to show it the selected ones, but I was hoping it would keep open every node that had been opened before a refresh, not just selected ones?

Trevor Pope

unread,
Jan 27, 2014, 8:02:12 AM1/27/14
to jst...@googlegroups.com
Please ignore the fact that the DIV has an ID of jstree_demo_div

It is actually jstree_div in the page


On Monday, 27 January 2014 09:04:22 UTC, Trevor Pope wrote:

Trevor Pope

unread,
Jan 27, 2014, 8:05:11 AM1/27/14
to jst...@googlegroups.com
Here is the JSON:

[
    {
        "id": "FujitsuDatacentres",
        "text": "FujitsuDatacentres",
        "icon": "Images/mnup.gif",
        "children": [
            {
                "id": "SDC01",
                "text": "SDC01",
                "icon": "Images/mnup.gif",
                "children": [
                    {
                        "id": "SiteOK",
                        "text": "Site-OK",
                        "icon": "Images/ifok.gif",
                        "a_attr": {
                            "href": "",
                            "target": "main",
                            "title": "OK"
                        }
                    }
                ]
            },
            {
                "id": "STE10",
                "text": "STE10",
                "icon": "Images/mnup.gif",
                "children": [
                    {
                        "id": "SiteDown",
                        "text": "Site-Down",
                        "icon": "Images/ifun.gif",
                        "a_attr": {
                            "href": "",
                            "target": "main",
                            "title": "UNMANAGED"
                        }
                    }
                ]
            },
            {
                "id": "TEST",
                "text": "TEST",
                "icon": "Images/mnup.gif",
                "children": [
                    {
                        "id": "SiteOverload",
                        "text": "Site-Overload",
                        "icon": "Images/ifok.gif",
                        "a_attr": {
                            "href": "",
                            "target": "main",
                            "title": "OK"
                        }
                    }
                ]
            }
        ]
    },
    {
        "id": "BGPTEST",
        "text": "BGP-TEST",
        "icon": "Images/mndn.gif",
        "children": [
            {
                "id": "PEERUP",
                "text": "PEER-UP",
                "icon": "Images/ifok.gif",
                "a_attr": {
                    "href": "",
                    "target": "main",
                    "title": "OK"
                }
            },
            {
                "id": "PEERDOWN",
                "text": "PEER-DOWN",
                "icon": "Images/ifdn.gif",
                "a_attr": {
                    "href": "",
                    "target": "main",
                    "title": "BGPDOWN"
                }
            }
        ]
    }
]


Ivan Bozhanov

unread,
Jan 27, 2014, 12:15:47 PM1/27/14
to jst...@googlegroups.com
Thank you - that was a bug - I just pushed a fix to github - take the latest source.

Best regards,
Ivan

PS. Keep in mind all IDs should be unique.

Trevor Pope

unread,
Jan 27, 2014, 3:57:29 PM1/27/14
to jst...@googlegroups.com
That sorted the problem - you are a star Ivan, I thank you very much, much appreciated!!
Reply all
Reply to author
Forward
0 new messages