SimpleTree provides tree-view for ActiveRecords with drag'n'drop support for quick table manipulation. It uses the jsTree jQuery plugin from jstree.com.
Yii 1.1 or above. Could possibly run on Yii 1.0 as well.
Unpack to your extension folder.
Make sure the Model you're using has properties/columns for the following: ID, parent ID, name and position. By default, these are respectively called id, id_parent, title and position.
/** * Quick setup **/ $this->widget('application.extensions.SimpleTreeWidget',array( 'model'=>'MyModel', ));
/** * Customized setup **/ $this->widget('application.extensions.SimpleTreeWidget',array( 'model'=>Folder::model()->findByPk(43), 'modelPropertyParentId' => 'parent_id', 'modelPropertyName' => 'name', 'ajaxUrl' => '/ajax/simpletree', 'onSelect'=>' var id = data.inst.get_selected().attr("id").replace("node_",""); $("#contentBox").load("/ajax/getContent/id/"+id); ' )); //ajaxController public function actionsimpletree() { Yii::import('application.extensions.SimpleTreeWidget'); SimpleTreeWidget::performAjax(); }
/** * Parameters and defaults **/ $ajaxUrl; //it is recommended that you use your own url $id = 'simpletree_widget'; $model; //this can be the name of a model, an empty model or a loaded model $modelPropertyName = 'title'; //name of the name property in your model $modelPropertyId = 'id'; //name of the ID property in your model $modelPropertyParentId = 'id_parent'; //name of the parent ID property in your model $modelPropertyPosition = 'position'; //name of the position property in your model $theme = 'default'; //apple, classic, default $onSelect; //javascript $onCreate; //javascript $onMove; //javascript $onRemove; //javascript $onRename; //javascript
January 27, 2011
Release 0.6
Release 0.5b
January 26, 2011
Total 20 comments
If you have any problems with sorting after refresh - find this line in method _get_children
and change it to
Finally I got it running.
Get rid of the "static"- Problem when I changed the "_get_Children"- function into "static function" (SimpleTreeWidget.php line 203).
I don't know if this results in some new problems, but so far everything seems to be smooth.
Thanks to the community and special thanks to doodle.
See u.
Now I'm faced with this:
Trying to get rind of it with no success:
The lines in the Widged:
Strange anyway.
@ agrippa
I just realized that the accessRules need to be tweaked.
doodle
Hi, the problem was a rule. I've to login to solve the Login page thing.
But still not working because of a 403 error.
Damn, I will get this running by hook or by crook.
Regards
doodle
thanks again.
The Problem in my case seems to be the answer to the request. Firebug gives back the Login Page of the demo application. Therefor I Think there is something wrong with the Ajaxurl.
Could you please tell me where to point the ajaxurl?
Thanks for your endurance.
Of course the guide is my constant companion ;-). But its not easy cause I've got no programmers background.
Regards
@agrippa
The data table is simply that, in my case it is data associated with a web page. So the webpage has an id and the webpagedata has pageId field. In the above snippet pageID() is a method within the model, it helps build the mysql query, findAll() is a built in method and I pass an array that specifies what order to return the results in. Again it is just building a query.
You should probably read the guide, if you have already read it, read it again. I read the guide a ton of times and I still refer to it all the time.
Regarding the simple tree widget, I suggest that you start with a very simple example but make sure that there are some values in the database or nothing will be displayed.
doodle
Thanks for the Re.
I don't figured out. Now I' am getting: <data.inst.get_selected().attr("id") is undefined>
What exactly does this Code do?:
Of course Categorydata is a Model, but what kind of values are in it? It seems this does a kind of relation between Category and Categorydata.
My Settings:
Controller:
Index:
And the _ajaxContent.php:
If I get it right, the function actiongetContent takes the ids(>0) out of Category Model and store it temporarily into the _ajaxContent.php. The Index file takes the ids out of the _ajaxContent.php, right?
Where can I go further?
Best Regards.
@norbert 1: Definitely the table should have something in it if you want to see any nodes on the tree. If the table is empty there is nothing to display. 2: 'model'=>Category::model()->findByPk(43) this is requesting a single record so unless there is a record with id (43) you won't get anything, plus I doubt that this example would give any useful results unless it provide a collection of products for example and you are supplying the product category. I think it's kind of a half-baked example.
Here's an example of working code.
Notice that my example calls WebPageTreeWidget, that's because I copied the original file and tweaked it for my purposes.
In this example when you click on a node it calls this ajax routine.
hope this helps to get you going.
doodle
I try to run this extension unfortunately without success, just the same issue as in the comments: No interactivity with the DB. Could one please be so kind and give me a hint how to run this thing?
My settings so far:
in the Site Controller:
in the view/site/index:
$this->widget('appli
The Table:
Is it necessary to fill the table with values?
Best regards Norbert
Hello,
maybe would be more elegant to extend the 'model' attribute with the possibility to give a db criteria in array format and introduce a new attribute 'theHasManyRelation'(string or array, the relation connecting the nodes) instead of 'modelPropertyId','modelPropertyPosition' and 'modelPropertyParentId'.
All of those could be easely posted in a serialized format on user events to the ajax controller.
Hi, first of all i realy like this extension. There is a little bug with the sorting of the tree. The tree is initialy not sorted by the position field. Here is a solution how to fix this. The Code in SimpleTreeWidget.php
you can add
in you _create_node like this !
if parent id is empty.were throw a error!
like this~~~
Thank you ~~~
when i create two simpleTree in same page, only one display.
it seems that you haven't consider the id attribute ,or the htmlOptions:
although there is a id attribute i can set ,but it seems to not work .
another thing: you should refer to jstree , even though it out of date, but the code technique is very good , or you may see this swfupload extension, these two js wrapper widgets only have little code , but it give the user more choices to config it. you can expose the under jstree config object to us like the swfupload extension do.
if people who didn't support the config ,then its your default setting config come out ,
at last , yours is a good extension , above words is only my advice , never mind if i say some thing wrong ! best regards :)
the context menu should be i18n supportted , if can add or remove some menuitem will be better, what's this extension aim ,just for showing?
if in realistic project there should have more attributes to consider etc : mutli roots. ,there is a type field to differ from different categories . - can anyone give me some advice how to apply this extionsion in real project but a demo one. or does this extionsion can work togerther with the nestedSet and the EJNestedTreeActions ? any help will be appretiate
I just thought I would share a problem that I had when deploying this to my production server. The jquery.cookies.js file would not be served to the client because of security rules set in place by the hosting company.
This was their response when I asked for assistance. > The error you saw was being returned because access to the file was being blocked by a mod_security rule set in the server.
Before the change was made all that happened was an endless loading indicator and firebug reported that cookies.js could not be loaded.
doodle
I am experiencing the same issue as justinas. It is not working with me as well :(
When I used the quick setup, only loading displays.
Then I used this as my customized setup:
and what appeared is the folder "root". Yes I can create,move,edit,and delete a node, but what I am expecting to see is the tree derived from my table.
Sorry!
Manage contextmenu:
And manage hover_node and select_node of root node ("readonly")
Leave a comment
Please login to leave your comment.