Save and restore treetable state

I use this documentation for save and restore treetable state:

https://docs.webix.com/desktop__datastate_state.html

In my situation it doesn’t work , maybe because I reload treetable from server ?

  1. I load treetable from server (nodes closed)

  2. I open parent nodes buy clicks

  3. I save the treetable state

  4. I reload treetable from server (node closed)

  5. I restore treetable last state

When I look in firebug, the treetable data saved with open nodes in local storage are ok but the nodes are always closed in view

Hello @romain ,
To restore the state, use ready handler or call the setState after component initialization:

 ready:function(){
  	var state = webix.storage.local.get("requirements_content_treetable_state");
    if (state)
       $$("treetable").setState(state); 
  }

Please check the next snippet:
https://snippet.webix.com/qa8mgzur

Thanks , but it doesn’t work for me where data are reload from server.

I have a function that reload my tree when I make a modification.

The server doesn’t know what nodes had opened in front.

This function save the state, clear the tree and reload data from server.

I tried to set the state saved (data saved are ok in local storage) with event “onAfterLoad” , but it doesn’t work too, the nodes are always closed even if the state saved has : open: Array(3) [ “1”, “2”, “3” ]

function treeListsReload() {
            var state = $$("listsTreeTable").getState();
            webix.storage.local.put("list_state", state);
            console.log(state);
            utils.loadBListsTreeFromDb($$("listsTreeTable")); //clear treetable and reload from server
        }
}

$$("listsTreeTable").attachEvent(
                    "onAfterLoad", function () {
                        var state = webix.storage.local.get("list_state");
                        if (state){
                            console.log('stateAfterLoad',state);
                            $$("listsTreeTable").setState(state);
                        }
                    }
                );

Any ideas ?

Hi @romain,
Unfortunately, I wasn’t able to reproduce this issue under the described scenario, e.g.: Code Snippet. If at all possible, could you please providean isolated example where the issue can be seen?

It is ok :slight_smile: After a lot of tests , I understood why for me it didn’t work , it wasn’t simple because my view contains a lot of interactions (6000 lines of code …), I have a event “onAfterFilter” and in this event I used the method “closeAll” for nodes and when tree is reload , the event is triggered … Thanks for example :wink:

Hello , is it possible to restore just some properties for datatable ?

For example I don’t want to restore “filter” object of my datatable.

Thanks

try this

function restore_state() {
  var state = webix.storage.local.get("state");
  if (state){
    delete state.filter;
    $$("grid").setState(state);
  }
};

up ?

Perfect , thanks