Save jstree and node orders

1,607 views
Skip to first unread message

Sergej

unread,
Jan 23, 2010, 8:22:55 AM1/23/10
to jsTree
Hi,

i'm saving my tree in sql db but i'm not really satisfied about my
solution. Actions like rename and delete are ajax requests and make a
direct update in db. Changes in structure and node create have to be
saved by button. After pushing the save button the following happens:
Clear db tree and set auto_increment = 1 and run through the json. The
problem is, if i want to save some other properties which concern the
tree like url or template etc i have to make a second "backup table"
where the properties are saved a second time because every structure
change cause a tree delete.

I thought about changing every node id after changing structure and
update the tree db.

example: i load the following tree from db

1
----- 2
----- 3
----- 4

i add a new node and give id 5:
1
----- 2
----- 5
----- 3
----- 4

Now the tree ids have to be ordered and then saved to db.

The point is, one way is to make the order by auto increment (deletes
the whole tree and build it again) or to try holding the order in the
jstree and just make updates.

The problem is i have to make ajax request after every drag and drop
to preserve the structure. The over point is i have to do the same if
i create a new node.

Someone have probably some proposals how i fix my problem or has
probably the same problem.

John Arrowwood

unread,
Jan 23, 2010, 10:31:17 AM1/23/10
to jst...@googlegroups.com
I have the same basic issue:  I have to tap into every event and make an update to my backing data structure.  That's just what you need to do. 

You CAN save the whole tree every time, but that is ridiculously expensive from a performance standpoint, especially if you have a large tree.  And it's not really the right way to do it.

Question is, why do you need to change node ID's?  The callback indicates where in the tree it was created (right?) so why not update an 'order' column in the database, so that when you need to display the tree again, and in the right order, you just sort by the order field.  You don't have to change the node ID's.


--
You received this message because you are subscribed to the Google Groups "jsTree" group.
To post to this group, send email to jst...@googlegroups.com.
To unsubscribe from this group, send email to jstree+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jstree?hl=en.




--
John Arrowwood
John (at) Irie (dash) Inc (dot) com
John (at) Arrowwood Photography (dot) com
John (at) Hanlons Razor (dot) com
--
http://www.irie-inc.com/
http://arrowwood.blogspot.com/

Chris

unread,
Jan 23, 2010, 2:26:19 PM1/23/10
to jst...@googlegroups.com
I handle this sort of thing by setting flags on modified items (using the tree events) rather than doing instant updates on delete etc. When the 'save' button is clicked I send back the modified nodes with data describing the modification. 

For example:
IsDeleted - delete node
IsMoved - update node parent id and order
IsRenamed - update node title
IsNew - create new node 

Chris Carey

Sergej

unread,
Jan 29, 2010, 10:38:28 AM1/29/10
to jsTree
I added a sort attr (sort="") and very tree layer has own sort. After
moving a node i run through the nodes with same parent id and set new
order. Then im saving the new order in DB using Ajax. Now i have to
change the oncreate event. The created node have to become an id,
overwise the rename won't find a node in sql db. Every action causes a
ajax request, thats not really what i want but i think there is no
better option.

Yes Chris, i've tried that before too but i don't like to work with
flags, the code becomes difficult to read for over developer.

On 23 Jan., 16:31, John Arrowwood <jarro...@gmail.com> wrote:
> I have the same basic issue:  I have to tap into every event and make an
> update to my backing data structure.  That's just what you need to do.
>
> You CAN save the whole tree every time, but that is ridiculously expensive
> from a performance standpoint, especially if you have a large tree.  And
> it's not really the right way to do it.
>
> Question is, why do you need to change node ID's?  The callback indicates
> where in the tree it was created (right?) so why not update an 'order'
> column in the database, so that when you need to display the tree again, and
> in the right order, you just sort by the order field.  You don't have to
> change the node ID's.
>

> > jstree+un...@googlegroups.com<jstree%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages