PDA

View Full Version : How to add move event to Tree node



mikemo85
13 Mar 2012, 5:39 AM
I want to add the Move event to all Tree nodes and would like to know the code to do such. Everytime I move a node I need to update the node's parent id in the database by making an ajax call. How can I achieve this?

vietits
13 Mar 2012, 5:58 AM
How do you move a tree node?

chramer
13 Mar 2012, 6:06 AM
set

autoSync : true
in the tree store, and it will make requests every time you move the nodes!

chramer
13 Mar 2012, 6:10 AM
i assumed drag & drop!

mikemo85
13 Mar 2012, 7:30 AM
Yes. I want to add a Move event listener to the Tree node so I can perform specific function a node is dragged from one location to another.

vietits
13 Mar 2012, 2:59 PM
If so, one of the way is set autoSync to true for the store attached with the tree as Chramer mentioned above. This way, each time you move a node your store will automatically generate an update request to server-side script.

In case autoSync set to fault, you need to catch the 'drop' event from the tree and call the <store>.sync() to update manually.

mikemo85
13 Mar 2012, 11:25 PM
What do you mean "...each time you move a node your store will automatically generate an update request to server-side script"? How do I make the call to my own server-side method after the drop event has been executed?

vietits
13 Mar 2012, 11:42 PM
As I said, if you config the tree store with autoSync set to true then each time you drag and drop a node to a new position, the store will automatically call your server-side script to update the change.

If you do not want to use this feature (autoSync: false) then you should call <store>.sync() to do the updating manually.

You specify the url for reading/creating/updating/destroying by setting the api config of store proxy. See here Ext.data.proxy.Ajax-cfg-api (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Ajax-cfg-api)