Wrapper class for jQuery Dynatree extension also handles with setting selected items and attaches selected items to the form in hidden fields.
Requirements ¶
Yii 1.1 or abobe
Usage ¶
You can call widget in view files like following.
<?php $this->widget('ext.dynatree.DynaTree',array(
'attribute'=>CHtml::activeName($model,'categories'),
'data'=>Category::model()->getCategoryTree('tree'),
'selection'=>$model->categoryIds,
)); ?>
Nice
You know what I havent time to make an extension for this, for my project I used vanilla JS with hidden field to post data from forms (can you imagine the whole work :p) but now I will test that and you will have my feedback.
Thanks
This extension saves a lot of time..
Need an example
Hi,
Thanks for this extension, really great!
It would be helpful to have an example of the 'data' and 'selection' format.
Thanks
demo application/sample data
Hi zvik2004,
Thank you for your advice. I will submit a demo application and sample data to download.
demo application
I uploaded demo application. It includes all related models and controller codes. Sample data is located under protected/data folder(testdrive.sql).
Ajax Button
Please could you tell me how to attach this to the post parameters on an ajax button?
Re: Ajax Button
Hi StuartMc,
You can edit DynaTree.php line 99-103. Instead of regular submit, you can make an ajax call on submit event. But you to serialize selected items.
An error?
Am I wrong or is there an error?
Line 73 sets $id, which is then never used (instead $this->id is in use, but there is no declatarion for $id in the class).
I couldnt make it work with passing the htmlOptions['id'], but once I added $id to class declaration and replaced $id with $this->id it started to work. Please correct or explain where was I lost...
Re: An error?
Yes, you are right. This is a bug. I updated the extension.
Search in Dynaa tree
Hi I wrote a script to enable search in dynatree. Let me know if it contains error or can be improved.
Yii::app()->clientScript->registerScript("tree-search1"," var tree_id=".$tree_id."; if(typeof tree_id == 'object') tree_id=tree_id.id; $('#search-tree').keyup(function(){ var text=$(this).val(); if(text.length < 4) return; var keys=new Array(); $('#'+tree_id).dynatree('getRoot').visit( function(node) { var li = node.li; var title=node.data.title; if((title.toLowerCase()).indexOf(text.toLowerCase()) !== -1) { node.makeVisible(); $(li).find('a').addClass('bold'); keys.push(node.data.key); } else { if(keys.indexOf(node.data.key) === -1) node.expand(false); $(li).find('a').removeClass('bold'); } }); }); "); <p><input class="search" id="search-tree" placeholder="Search Categories here..." autocomplete="off" /></p>
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.