arlen_yi
(Yishichang)
August 14, 2013, 6:21am
1
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'));
?>
arlen_yi
(Yishichang)
August 14, 2013, 6:54am
3
try this…i am not sure it’s work or not
<?php echo $form->dropDownList(
$model,
'country_id',
CHtml::listData(country::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..
}
arlen_yi
(Yishichang)
August 14, 2013, 9:43am
5
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');
in view/view_widgets.php
<?php
$this->widget('application.extensions.MTreeView.MTreeView',
array('url'=>array('ajaxFillTree'),
'animated'=>'fast',
)
);
?>
arlen_yi
(Yishichang)
August 14, 2013, 10:08am
7
I tried this, but still failed. maybe I should use submit button for this.
Ankit_Modi
(Ankit Modi)
August 14, 2013, 10:21am
8
what should be the error?
can u post the code?
arlen_yi
(Yishichang)
August 14, 2013, 10:41am
9
Hi Ankit Modi,
so thanks, i have to get off work now. And if you catched some problems in my code, just post it.
Ankit_Modi
(Ankit Modi)
August 14, 2013, 11:21am
10
Why do you want to use the widgets?
have you created tree base drop-down?
arlen_yi
(Yishichang)
August 14, 2013, 3:29pm
11
I want to get the treeview with different root that generated by dropdownlist.
arlen_yi
(Yishichang)
August 15, 2013, 4:39am
12
haha, gaoding!
replace controller
public function actionCaseTree(){$this->renderPartial('case_tree');}
with
public function actionCaseTree(){$this->renderPartial('_casetree',array(),false,true);}
Ankit_Modi
(Ankit Modi)
August 15, 2013, 1:23pm
13
have you resolved this issue?
arlen_yi
(Yishichang)
August 15, 2013, 2:27pm
14
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?
Ankit_Modi
(Ankit Modi)
August 16, 2013, 3:58am
15
Ankit_Modi
(Ankit Modi)
August 16, 2013, 4:03am
16
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);
arlen_yi
(Yishichang)
August 16, 2013, 7:58am
17
wow, so cool! lot of things are i wanted. many thanks, Modi!
Ankit_Modi
(Ankit Modi)
August 16, 2013, 8:05am
18
Also one more…
i hope it’s help…
http://www.yiiplayground.com/