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','continent.name'),

			array(

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

			'ajax' => array(

			'type'=>'POST', 

			//'url'=>array('action'),

			//'update'=>'#id',

	))); ?>	

	

	<?php

		$this->widget('application.extensions.MTreeView.MTreeView',

			array('url'=>array('ajaxFillTree'),

			'animated'=>'fast',

			)

		);

	?>

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


<?php echo $form->dropDownList(

                    $model,

                    'country_id',

                     CHtml::listData(Project::model()->with('continent')->findAll(),

                    'id',

                    'name',

                    'continent.name'

                    ),

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…


<?php

                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…

like


$this->renderPartail('view_widgets');

  1. in view/view_widgets.php

<?php

                $this->widget('application.extensions.MTreeView.MTreeView',

                        array('url'=>array('ajaxFillTree'),

                        'animated'=>'fast',

                        )

                );

        ?>

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');}

with


 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?

Hi,

please see it…

1)http://demo.bsourcecode.com/yiiframework/

2)http://www.eha.ee/labs/yiiplay/index.php/en/site/widget?view=treeview

i hope it’s may be helpful :rolleyes:

try this…

e.g


$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…

http://www.yiiplayground.com/