Hi
Does anyone know if there a way to filter data inside de widget CTreeView like in the CGridView ?
My goal is to load data in the treeview depending on a dropdownlist
I need to select group in a dropdownlist and then, display data of a selected group in the treeview
thank you
Here is my _treeview.php view
<?php
$this->widget('CTreeView',array(
'id'=>'myTreeView',
'url'=>$urlTreeView,
//'data'=>$dataTreeView,
'animated'=>'fast', //quick animation
'collapsed'=>false,//remember must giving quote for boolean value in here
'htmlOptions'=>array(
'class'=>'treeview-famfamfam',//there are some classes that ready to use gray black red famfamfam
),
));?>
Here is the view with the dropdownlist
$form=$this->beginWidget('CActiveForm',
array(
'id'=>'_ligneComboBox',
'enableAjaxValidation'=>false,
));
echo CHtml::dropDownList(
'groupeId', //cbxName
'', //selected value
CHtml::listData($dataGroupe,'id','nom'), array( //data
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('manage/getSitesFromGroupe'), //url to call.
'update'=>'#siteId', //selector to update
),
'prompt'=>'Groupes',
'onchange'=>'',
),
array()
);
//empty since it will be filled by the other dropdown
echo CHtml::dropDownList(
'siteId', //cbxName
'', // selected value
array(), //data will be set by groupeID
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('manage/renderTreeView'),
'update'=>'#divTreeView',
),
'prompt'=>'Sites',
//'onchange'=>'javascript:alert(2)',
)
);
$this->endWidget();
Here is a part of the controlleur
public function actionRenderTreeView($filtre=''){
$urlTreeView = $this->createUrl('manage/remplisTreeView');
$cManageComponent = new ManageComponent();
$dataTreeView = $cManageComponent->getTreeViewDatas($filtre);
$this->renderPartial('_treeView',array('urlTreeView'=>$urlTreeView));
}
And then the components
public function getTreeViewDatas($filtre=''){
// partie _treeView
$cGroupeComponent = new GroupeComponent();
if($filter==''){
$mySearch = new GroupeVO;
$mySearch->nom = $filtre;
$groupes = $cGroupeComponent->getGroupeSearch($mySearch);
} else {
$groupes = $cGroupeComponent->getGroupes();
}
$tableauTreeView = null;
foreach ((array)$groupes as $groupe)
{
$tableauSite = null;
foreach((array)$groupe->sites as $site){
foreach((array)$site->applications as $app){
$tableauAppli[] = array('text'=>$app->repertoire.' '.$app->commentaire);
}
$tableauSite[] = array('text'=>$site->nom.' ( '.count($site->applications).' application'.(count($site->applications)>1?'s':'').' )', 'children'=>$tableauAppli);
//echo '</blockquote>';
}
$tableauTreeView[] = array('text'=>$groupe->nom.' ( '.count($groupe->sites).' site'.(count($groupe->sites)>1?'s':'').' )', 'children'=>$tableauSite);
}
$dataTreeView = CTreeView::saveDataAsJson($tableauTreeView);
return ($dataTreeView);
}
seb