How To Implement Dependent Treeview By Dropdownlist

Hello All,

I want to implement the dynamic treeview dependent on what dropdownlist selected, but i don’t have any idea, is there anybody could give me a guide to implement this ? Thanks in advance. Belows are my code, FYI:

<?php echo CHtml::dropDownList('country_id','', CHtml::listData(country::model()->with('continent')->findAll(), 'id', 'name',''),


			'prompt' => '-- please select country --',

			'ajax' => array(




	))); ?>	









try this…i am not sure it’s work or not

<?php echo $form->dropDownList(








array('empty'=>'please select country'));


Thanks for your reply, but I wanted is if i select a option from dropDownList, the MTreeView will do corresponding change.

try this

for example…


                echo CHtml::dropDownList('venue_name', '', CHtml::listData(Venue::model()->findAll('status!="2"'), 'id', 'venue_name'), array(

                    'id' => 'send_venue',

                    'prompt' => 'Select Venue',

                    'class' => 'col_165',

                    'ajax' => array(

                        'type' => 'POST',

                        'url' => CController::createUrl('eventname'),

                        'update' => '#event_name',

                        'data' => array('venue_id' => 'js:this.value'),



<div id= "event_name"></div>

public function actionEventname(){

		//code here

               //just create the new page and render the page 

              // in page put your widgets code..


With Ankit Modi’s solution, the CtreeView can’t render to page, but with other widgets(i.e: zii.widgets.CMenu) or direct echo ‘view’, the solution is okay.

maybe need to add more things for CtreeView.

i think you may use this renderPartail methods…



  1. in view/view_widgets.php








I tried this, but still failed. maybe I should use submit button for this.

what should be the error?

can u post the code?

Hi Ankit Modi,

so thanks, i have to get off work now. And if you catched some problems in my code, just post it. ;D

Why do you want to use the widgets?

have you created tree base drop-down?

I want to get the treeview with different root that generated by dropdownlist.

haha, gaoding!

replace controller

 public function actionCaseTree(){$this->renderPartial('case_tree');}


 public function actionCaseTree(){$this->renderPartial('_casetree',array(),false,true);}

have you resolved this issue?

Hi Ankit Modi, thanks.

The issue was fixed by modifing renderpartial parameter. e.g: $this->renderPartial(’_casetree’,array(),false,true).

But, I just found that the CtreeView is very slow in bad network environment, I am going to remove the CtreeView widget, do you know any good tree-view extension or method?


please see it…



i hope it’s may be helpful :rolleyes:

try this…


$parents = Category::model()->findAll();


   foreach($parents as $parent)


          $data = array();

          $category_detail = Category::model()->findAll('parent_id = "'.$parent->id.'"');

          foreach($category_detail as $value){

                                                                                                            $data[$value->id] = $value->category_name;


                $result[$parent->category_name] = $data;             




                /*           use  the dropdwn menu the tree */

         echo $form->dropDownList($model,'category',  $result);

wow, so cool! lot of things are i wanted. many thanks, Modi!

Also one more…

i hope it’s help…