Jan 27 2008

CakePHP and EXTJS tree

Category: CakePHPpaomic @ 12:11 pm

Hi all!

I had to insert a tree in order to edit the structure of a menu. I found out that extjs tree are great! It lets you add a tree with dynamic content and move node from the root to leafs. So I tried integrating it, it’s really easy.

I added a js function to the tree javascript (from the reorder example in the extjs package)

function getTreeContents(tree) {
return getNodeContents(tree.root,true);
}

function getNodeContents(node) {
var s = ”;
if(node.childNodes.length > 0)
{
for(var i=0; i<node.childNodes.length; i++) {
s+= node.id+’-'+node.childNodes[i].id +’|';
s += getNodeContents( node.childNodes[i],false);
}
}
return s;
}

This returns a list of parentid-childid which, everytime the tree is changed, I add to a hidden textbox. Then I get the value of this textbox in the controller code, parse it and update all the nodes according to passed values.

That’s it!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • description
  • ThisNext
  • MisterWong
  • Wists
  • blinkbits
  • BlinkList
  • blogmarks
  • BlogMemes
  • blogtercimlap
  • Blue Dot
  • description
  • Bumpzee
  • co.mments
  • De.lirio.us
  • Fark
  • feedmelinks
  • Fleck
  • Furl
  • Gwar
  • kick.ie
  • Linkter
  • Ma.gnolia
  • MyShare
  • Netscape
  • NewsVine
  • Scoopeo
  • Simpy
  • Slashdot
  • Smarking
  • Spurl
  • StumbleUpon
  • Taggly
  • Technorati
  • Webride
  • YahooMyWeb
Post Tagged:

Leave a Reply