Change Treetable data to datatable with parent

Hello webix team,

I inspired by this example from codepen on webix-databoom http://codepen.io/vladislav2/pen/KpYpJw?editors=001

That example show a fully functional tree list on the left side of the app. I tried to build similar with treetable here http://webix.com/snippet/88fdfb62 . In that example I drag and drop one item on another to make it it’s child. But after I press the connect button again to reconnect, the item will back to its place.

Then I found out that databoom do not support hierarchy-al data. So that example actually make the tree have more id called “parent” as shown in the database here https://samples.databoom.space/api1/sandboxdb/collections/departments

I found out their code here http://databoom.space/databoom.webix.js but still don’t understand what they did.

Please help. A hint would be appreciated too. Thank you…

So I just found out that to save hierarchy-al data I still shoul use the datatable with parent id or other method just like here https://docs.mongodb.org/manual/tutorial/model-tree-structures/

Well that was surprising though. so the job is to translate that datatable to webix data format.

So I found this interesting code

`
function organizetree(a) {
    var r = [];
    var c = {};
    for (var i = 0; i < a.length; i++) {
        c[a[i].id] = a[i];
        if (!a[i].data)
            a[i].data = [];
        if (!a[i].parent)
            r.push(a[i])
        else if (a[i].parent === '0') {
            a[i].parent = undefined;
            r.push(a[i])
        }
    }
    for (var i = 0; i < a.length; i++) {
        if (a[i].parent) {
            var e = c[a[i].parent];
            if(e)
                e.data.push(a[i])
        }
    }

    return r;
}
`

It should be used to translate the code into the webix format. So I guess I have to modify some the odata configuration first.

But I still haven’t figured out how to translate back webix format back to table.

Hello,

But I still haven’t figured out how to translate back webix format back to table.

There is no need to translate all the data. DataProcessor sends requests with information about modified item ( “save” method of proxy object).