TreeTable - Serialize all Data to store in document db

I am struggling to serialize and deserialize treetable data.

I need to serialize the data in the treetable so that when I load it the treetable will be correctly created with all of the parent child relationships intact. I also need to ensure that the treetable has the same row structure (one row before another or after another as it was created by the user).

This is what I am sending to my save api route:

			table.data.each(function(data_row){
				tableDataArray.push(data_row);
			});
			//var tableData = $$(tblGridID).data.pull;
			var tableDataJson = JSON.stringify(tableDataArray);

tableDataJson contains all of the rows in a javascript array stringify’d to a json string

Loading the same data produces a treetable with all of the rows but the hierarchy is missing and the row order is wrong.

Here is the data serialized using above code:

[{“id”:201,“client_id”:“154”,“parentid”:“0”,“status”:“u”,“action”:“Row 1”,“has_subitems”:1,“due”:"","$parent":0,"$level":1,"$count":1,“open”:true},{“id”:“207”,“parentid”:201,“status”:“c”,“action”:“Row 1 SubItem”,“due”:"","$count":0,"$level":2,"$parent":201},{“id”:“202”,“parentid”:0,“status”:“c”,“action”:“Below Row 1”,“due”:“10/22/2014”,"$count":0,"$level":1,"$parent":0},{“id”:“203”,“parentid”:201,“status”:“c”,“action”:“Row 2”,“due”:“10/25/2014”,"$count":0,"$level":1,"$parent":0},{“id”:“204”,“parentid”:201,“status”:“c”,“action”:“Below Row 2”,“due”:"","$count":0,"$level":1,"$parent":0},{“id”:“205”,“parentid”:201,“status”:“c”,“action”:“Row 3”,“due”:"","$count":0,"$level":1,"$parent":0},{“id”:“206”,“parentid”:0,“status”:“c”,“action”:“Row 4”,“due”:"","$count":0,"$level":1,"$parent":0}]

Can anyone tell me what I am doing wrong or what I could do better to make this work?
I need to save each treetable set of data as a json doc and deserialize it on load

Any help to be offered would be great!

Thanks!

Hello,

Try using the tree’s serialize method.

Check the snippet - row order and tree state are preserved: http://webix.com/snippet/e515ca40

Exactly what I was looking for - I must have been blind to not have seen that!
Thanks so much Helga!