9

Adding the state plugin in Jstree is still not saving the state of the tree between page refresh or after clicking link and going back to previous page

$('#myGrid').jstree({
    "types": {
       "key": {
           "icon": "Content/Images/skey.png"
       },
       "value": {
           "icon": "Content/Images/sValue.png"
       }
    },
    "state": { "key": "myTree" },
    "search": { },
    "core": {
        "check_callback":true,
        "data": [@Html.Raw(Model.JsonData)]
    },
    "plugins": ["state", "types", "search"]

thank you,

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Amda
  • 91
  • 1
  • 3

2 Answers2

0

use set state property from the documentation...

Premshankar Tiwari
  • 3,006
  • 3
  • 24
  • 30
  • I tried `var jsTree = $('#myGrid').jstree(true); jsTree.save_state();` but it didn't help – Amda Jan 31 '14 at 15:38
0

This works good for me on current version 3.08. Though I use ajax to get json data via a controller (asp.net mvc or web api) based on id, and not fetching raw html on load. I would recommend this if you can, it's cleaner and supports lazy loading. On my setup jstree opens one node after the other until it reaches the last node I opened.

It does not play that well though if I open more than one branch of nodes.

The important thing would be that your nodes has unique id properties. Check also localStorage and see if anything is stored there.

atlmag
  • 71
  • 1
  • 4