MTreeView extends CTreeView, which displays a tree view of hierarchical data. It can handle both nested set and adjacency hierarchy model,and can create a linked node and adds icon if you wish. It can also be used to render AJAX tree!
Yii 1.1.7 and above (not tested with 1.1.6 and below,so I'm not sure whether it'll work there)
Download the latest MTreeView_2.1.zip and extract to extensions folder.
Click here to view all releases or MTreeView
Refer here to view all the available options for MTreeView.
If you are already using the initial release of MTreeView, all you have to do is replace the MTreeView.php. There should be no problem encountered after the update, but just to be sure, just rename the old MTreeView.php. Please report any errors which will be encountered at our discussion page.
For more detailed explanation about this extension, visit my blog or download the latest sample zip file to play with the extension. The new sample zip file can be used with the sample database for version 1.1 (mtreeview_1.1.sql).
$this->widget('application.extensions.MTreeView.MTreeView',array( 'collapsed'=>true, 'animated'=>'fast', //---MTreeView options from here 'table'=>'menu_adjacency',//what table the menu would come from 'hierModel'=>'adjacency',//hierarchy model of the table 'conditions'=>array('visible=:visible',array(':visible'=>1)),//other conditions if any 'fields'=>array(//declaration of fields 'text'=>'title',//no `text` column, use `title` instead 'alt'=>false,//skip using `alt` column 'id_parent'=>'parent_id',//no `id_parent` column,use `parent_id` instead 'task'=>false, 'icon'=>false, 'url'=>array('/menuAdjacency/view',array('id'=>'id')) ), ));
Download the latest sample ZIP file for examples of usage and further details.
http://stackoverflow.com/questions/841014/nested-sets-php-array-and-transformation
http://semlabs.co.uk/journal/converting-nested-set-model-data-in-to-multi-dimensional-arrays-in-php
http://www.fliquidstudios.com/2008/12/23/nested-set-in-mysql/
Total 19 comments
My apologies if I have been so busy with my real life projects. I was in the process of improving the mtreeview,with new features like draggable nodes,node searching and editable labels, sadly my hands are full as of the moment so I can't update the extension yet.
Thank you all for the support.
Because in strict php the undefined variables are not allowed please place a $list=null; inside your code like this:
Waiting for the new version! Very good job until now, and also nicely presented :)
After I changed it your code in line 291 of php file looks like this:
It is strange that you call some options to be passed as a third parameter to createUrl. Maybe are you referring to an older version of Yii?..
It is also strange that inside your sample project everything works ok. I noticed that in your example the $arrOptions is not empty but it is a string with css style red
Still wondering how this string passed as a third parameter to createUrl does not return an error, like in my case!.... :/
Hi macinville,
I hope the AJAX tree also has the feature the same with adjacency and nested set which allow viewing the details of every node's link in a grid.
Hi Kabinenkoffer, the link has been updated, thanks for pointing that out.
Hi, the link to the latest version is broken. Just to let you know. Greetings
Hi MacInville,
Since i have a huge database record to presented as a tree, please provide the component with search capability to find text in the tree.
Thank you.
Thanks for sharing your experience with us moysoft. I'm glad your problem is now solved. :)
I had solved my problem, the problem is in my sql statement that i used. In my case i'm using SQLServer 2008 Express, it's totally different with MySQL syntax that you used here.
Rather than using "NULL" in initialy $parent_id i'm using 0. And change the sign <=> with isnull SQLServer function.
Thank you for great Yii extension.
So sorry I was not able to attend to your issue quick enough. Anyway, I think there's something wrong with the spelling of your controller. Instead of
, it should be
(take note of the capital 'A' in the word 'ajax').
Hi macinville,
I have installed your sample code and i have to try the sample, it's work, but when i apply to my yii project it doesn't work.
This is my controller (MemberController) looks like :
in view _ajaxTree.php looks like this :
and in the view that call the addSomeThing (_something.php) :
and the browser just output :
AJAX Tree with links and icons, with the template set to '{icon}Text:{text}'. UPDATED: considered the htmlOptions (which is saved in the
optionsfield) for the nodeno tree view shown. It's looks like every java script i call is not responding.
Please help me, maybe i forget something.
I use this extension in combination with the Yii nestedset extension. Works great. But your example of the widget does not work entirely
should be replaced by
otherwise you get a not ambigious error. Not really a neat solution i think.
Thanks to Timbo for noticing that template is still being reset to the old pattern. Apologies for the inconvenience.
I have changed the downloadable latest version, I forgot to consider the 'options' of the node (if given) once the 'url' is an array.
Apologies for the inconvenience.
I updated the extension so that each node can now have different htmlOptions. I added the field 'option', which value should be encoded in JSON form (such as {"style":"font-weight:bold"}). This is disabled by default, so if you're not going to use this additional feature, you don't have to update anything in your created widget.
Download the latest sample zip file to further test the update. Your comments and suggestions will be greatly appreciated.
@mettalph Thanks! I forgot to update it. :)
Theres a error in the Table of Properties:
When the correct form is as it:
when faced hierarchy data , it's hard to choice which model meet my requirements , in my project i use the adjacency model,but i found the nested set model some times more convenience ,so i need a combination UI ,in future may be i will change the adjacency to nested set model but do little change of my existing view file .
I have replaced the downloadable files, I made a small difference with AJAX tree. For some reason, the node can no longer be collapsed or expanded when the text of the node is clicked (unlike with the non-AJAX tree). At any rate, the tree can still be opened by clicking the "hitArea" (the icon to open the tree) of the node. Nevertheless, I will still look for a solution for this. If someone has a solution for this, please inform me so I can update the extension.
Wow, I'm amazed with your packed example. Though the explanation is not so detailed, it can be easily understood.
So far so good!Keep up the good work!
Thumbs up!
Leave a comment
Please login to leave your comment.