Use CTreeView Generate CGridView


My admin.php view page has two div parts, the left is CTeView, and the right side is CGridView.

The CTreeView is filled with nodes. I want to make each node to be a link, so everytime i click one node, the right side CGridView will update it’s related database table regarding to the clicked node.

Here is my Controller class php file: "ProjectController.php"

class ProjectController extends Controller


	//$this->layout = false;


	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.


	public $layout='//layouts/column2';

	public $treeNodeText;

public function actionAdmin()


		$model=new Project('search');

		$model->unsetAttributes();  // clear any default values




		$table = 'jiashu';

		$count=Yii::app()->db->createCommand('SELECT COUNT(*) FROM '.$table)->queryScalar();

		$sql='SELECT * FROM '.$table;

		$dataProvider=new CSqlDataProvider($sql, array(




             		'id', 'name', 'description',








		$this->render('admin',array('dataProvider' => $dataProvider,'model'=>$model,));



public function actionajaxFillTree(){

		if (!Yii::app()->request->isAjaxRequest) {



				        $parentId = 0;

        if (isset($_GET['root']) && $_GET['root'] !== 'source') {

            $parentId = (int) $_GET['root'];


		$treeNodeText = $parentId;

		        $req = Yii::app()->db->createCommand(

            "SELECT, AS text, IS NOT NULL AS hasChildren "

            . "FROM tbl_tree AS m1 LEFT JOIN tbl_tree AS m2 ON "

            . "WHERE m1.parent_id <=> $parentId "

            . "GROUP BY ORDER BY ASC"


        $children = $req->queryAll();



		foreach($children as $child){


			//Create tag 'a', and put $options contents in to a.

     		$nodeText = CHtml::openTag('a', $options);

      		$nodeText.= $child['text'];

      		$nodeText.= CHtml::closeTag('a')."\n";

      		$child['text'] = $nodeText;




        echo str_replace(







		//$this->render('admin',array('dataProvider' => $dataProvider,));



Here is my view php file: admin.php




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



$this->widget('zii.widgets.grid.CGridView', array(





I can successfully create a treeview with all link node. But i am confused of how to click one of the node, then the $dataprovider chages as well, and the CGridView is updated as well.

Thank you very much for your help!

Is this your thread your thread also ? Seems like duplication under different users :)