DataTree State Object: Session, JavaScript Programming Example of DataTree State Object: Session

DataTree State Object: Session, JavaScript Programming Example of DataTree State Object: Session

Do you want a tree to look the exact way you left it when you enter a web app next time? Get our programming example to tackle the problem. Press "save state" before leaving a web page, and a tree state survives till the next session. Feel free to use our coding samples and enjoy the benefits.

JS Code

var tree = {
  view:"tree",
  id:"tree",
  data:tree_data,
  select: true,
  height:300,
  ready:function(){
    var state = webix.storage.local.get("state");
    if (state)
      this.setState(state);
  }
};

function save_state(){
  webix.storage.local.put("state", $$("tree").getState());
};

var buttons = {
  rows:[
    { view:"button", width:100, value:"Save state", click:save_state }
  ]
};

webix.ready(function(){
  webix.ui({
    padding:10, rows:[
      {
        height:70,
        template:"<b>DataTree state object</b><br><br>"+
        'Click "Save state", collapse/expand and select items, and then refresh the page.'
      },
      tree,
      buttons
    ]
  });
  webix.attachEvent('unload', function(){
    var state = webix.storage.local.get("state");
    if (state)
      $$("tree").setState(state);
  });
});

Want to stop worrying about restoring tree state and other stuff related to DataTree?