This extension is ...
a widget for the jsTree, a CTreeView enhancement.
Download the jstree component from their website (http://www.jstree.com) and extract it under protected/extensions/jsTree.
Then download the release file and extract it in the protected/extensions
Though I developed this extension to diaply a treeview of a nestedset model, I'd rather using the jqGrid extension these days. If you just want to display a simple tree and want a few simple functions to manage your tree, this extension might work. But if you want more complex functions to manage your tree, consider using the jqGrid.
protected/extensions/jsTreeprotected/extensionsSee the following code example:
You should prepare hierarchical data. It might be an html view or a database table model.
class TreeController extends CController { public function actionTree1() { $this->render('tree1',array()); } }
<div id="demo1"> <ul> <li id="phtml_1" class="open"><a href="#">Root node 1</a> <ul> <li id="phtml_2"><a href="#" style="background-image:url('../media/images/ok.png');">Custom icon</a></li> <li id="phtml_3"><a href="#">Child node 2</a></li> <li id="phtml_4"><a href="#">Some other child node 111</a></li> </ul> </li> <li id="phtml_5"><a href="#">Root node 2</a></li> </ul> </div> <php? $this->Widget('application.extensions.jsTree.CjsTree', array( 'htmlOptions'=>array('id'=>'demo1'), )); ?>
This extension works well with the nestedset extension.
class Tree extends CActiveRecord { public function behaviors(){ return array( 'Treebehavior' => array( 'class' => 'application.extensions.nestedset.Treebehavior', ) ); } }
class TreeController extends CController { protected function formatData($tree) { if($tree->getChildNodes()) return array('text'=>CHtml::link($tree->name,"#"),'id'=>$tree->id,'expanded'=>true); else return array('text'=>CHtml::link($tree->name,"#"),'id'=>$tree->id); } public function actionTree2() { $data=array(); $treeList1=tree::model()->findAll(); foreach ($treeList1 as $i=>$model) { $data[$i]=$this->formatData($model); $treeList2=$model->getChildNodes(); foreach ($treeList2 as $j=>$submodel) { $data[$i]['children'][]=$this->formatData($submodel); }; }; $this->render('tree2',array('data'=>$data)); } }
$this->Widget('application.extensions.jsTree.CjsTree', array( 'data'=>$data, ));
Of course, you can use many jsTree options as follows:
$this->Widget('application.extensions.jsTree.CjsTree', array( 'data'=>$data, 'ui'=>array('theme_name'=>'apple'), 'rules'=>array( droppable => "tree-drop", multiple => true, deletable => "all", draggable => "all" ), 'callback'=>array( "onrename"=>"js:function() { alert('Rename'); }", "onmove"=>"js:function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { alert('Move id:'+NODE.id+' ref:'+REF_NODE.id+' type:'+TYPE+' rb:'+RB); }", "oncopy"=>"js:function() { alert('Copy'); }", "oncreate"=>"js:function() { alert('Create'); }", "ondelete"=>"js:function() { alert('Delete'); }", "error"=>"js:function() { }", "ondblclk"=>"js:function() { alert('Doubleclick'); TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE); }", "onrgtclk"=>"js:function() { alert('Rightclick'); }", "ondrop"=>"js:function() { alert('Foreign node dropped'); }", ), ));
Total 7 comments
please update the extension
Can you please update the extension with current version of jsTree v.1.0RC2
Yes, that would be awesome!
Hi Shocky Han,
Extension works fine, but have some major issues with jsTree, Can you please update the extension with current version of jsTree v.1.0RC2
Thank you
Hi, ok, extension works well with the nested set extension. I ask myself on how to update completely a nested set after having manipulating it with the jstree ???
(I've asked the same question on the nested set extension).
jsTree.v.0.9.9a2.zip
is the latest stable version
can you update the extension? thankyou!
Documentation is incorrect:
$this->Widget('application.extensions.jsTree.CjsTree', array( 'data'=>$data, 'ui'=>array('theme_name'=>'apple'), 'rules'=>array( droppable => "tree-drop", multiple => true, deletable => "all", draggable => "all"
The array strings should be surrounded by quotes.
I can't seem to get many other settings to work (though this may be my experience level).
Very good extension when you need to display tree stucture. Integration with netstedset extension makes this extension even more useful.
Leave a comment
Please login to leave your comment.