PDA

View Full Version : Passing all nodes in a GridTree back to a PHP script



mcryan
15 Jan 2011, 3:19 PM
Hi all,

I hope someone can help, I've been trying to create a save function for an Ext.ux.TreeGrid with no luck. Currently I have a save button that sends an AJAX request to a PHP script, but I am finding it very difficult to send all of the data contained in the TreeGrid. I assume sending back a JSON array would be the most logical, but I haven't been able to do this.

I have seen elsewhere on the forums examples on how to save a tree, but they are not working for this.

Can anyone point me in the right direction?

Thanks.

Condor
16 Jan 2011, 5:55 AM
What's the data format you want to use transmit the tree data?

mcryan
16 Jan 2011, 6:44 AM
The format that the data comes through to the server? Honestly I am quite easy on this. Passing an array with all of the data would be the easiest, but whatever it comes through as I can do the PHP to handle the rest.

Condor
16 Jan 2011, 7:22 AM
Try something like:

function addNode(node, data) {
var attrs = Ext.apply({}, node.attributes);
if (node.hasChildNodes()) {
attrs.children = [];
for (var i = 0; i < node.childNodes.length; i++) {
addNode(node.childNodes[i], attrs.children);
}
}
data.push(attrs);
return data;
};
var data = addNode(tree.getRootNode(), []);

mcryan
16 Jan 2011, 8:13 AM
Thanks, I actually just had some success as well, finally!

I found a thread that covers the use of a JsonTreeSerializer. By using that I was actually able to pass the full JSON array back to PHP and decode it from that side.

Thanks for all the help!