Show Parent And Children In Cgridview

In a table showing all ‘projects’, I have projects with and without parents. I’d like to show:

  • parent projects (aka projects with no parentId)

  • Under each parent project the related child projects

So, for instance:

  • project, not parent

  • project, parent

    • child

    • child

    • child

  • project, parent

    • child
  • project, not parent

I came across the GroupGridView extension, but don’t know if that can help me… Anyone?

[size="5"]In your relation[/size]:

‘parent’ => array(self::BELONGS_TO, ‘Yiicms’, ‘parent_title’, ‘condition’ => ‘t.parent_title = 0’),

					'children' => array(self::HAS_MANY, 'Yiicms', 'parent_title'),

					'childCount' => array(self::STAT, 'Yiicms', 'parent_title'),



public static function getParent($id)


	$title = self::model()->findByPk($id);

	//echo '<pre>';

	//print_r($title); exit;

	return $title['title'];


And your controller:

public function actionAjaxFillTree()


    // accept only AJAX request (comment this when debugging)

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



    // parse the user input

    $parentId = "NULL";

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

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


    // read the data (this could be in a model)

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

        "SELECT, m1.title AS text, IS NOT NULL AS hasChildren "

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

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



    echo str_replace(






in your admin page:

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(










			'value'=&gt; 'Yiicms::getParent(&#036;data-&gt;parent_title)'),






i don’t know what you r expectin but try this becoz this is my training project i got good result