CButtonColumn - render custom template/partial

Hi there.

I am doing some testing here and there with Yii 1.1.2 before using it in production sites.

My question is about the CGridView generated with the CRUD.

The thing is: it would be great you could render a custom template/partial in the button or the entire cell.

Symfony uses TOO MUCH this approach, and the idea is grabbed from there. What I say is use a very much limited version of that…

Something like (using the Blog demo):




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

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'ajaxUpdate' => false,

	'columns'=>array(

		array(

			'name'=>'title',

			'type'=>'raw',

			'value'=>'CHtml::link(CHtml::encode($data->title), $data->url)'

		),

		array(

			'name'=>'status',

			'value'=>'Lookup::item("PostStatus",$data->status)',

			'filter'=>Lookup::items('PostStatus'),

		),

		array(

			'name'=>'create_time',

			'type'=>'datetime',

			'filter'=>false,

		),

		array(

			'class'=>'CButtonColumn',

			'template' => '{view}{update}{mydelete}',

			'buttons' => array(

				'mydelete' => array(

					'partial' => '_mydeletebutton' // here my partial, it could access $model or $data, and $row

				),

			)

		),

	),

)); ?>



In this case, the partial would look like this (just an useless example):




<span><?php echo $row; ?></span>

<?php echo CHtml::link('Delete', array('delete', 'id' => $model->id)); ?>



In the other case, maybe replace all the cell with a partial:




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

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'ajaxUpdate' => false,

	'columns'=>array(

		array(

			'name'=>'title',

			'type'=>'raw',

			'value'=>'CHtml::link(CHtml::encode($data->title), $data->url)'

		),

		array(

			'name'=>'status',

			'value'=>'Lookup::item("PostStatus",$data->status)',

			'filter'=>Lookup::items('PostStatus'),

		),

		array(

			'name'=>'create_time',

			'type'=>'datetime',

			'filter'=>false,

		),

		array(

			'class'=>'CButtonColumn',

			'partial' => '_mycustomcolumn', // same as before, but replacing the entire cell			

		),

	),

)); ?>



And in this case, the partial would look like this (maybe a bit more useful):




<ul class="grid_actions">

   <li><span><?php echo $row; ?></span><?php echo CHtml::link('Update', array('update', 'id' => $model->id)); ?></li>

   <li><span><?php echo $row; ?></span><?php echo CHtml::link('Delete', array('delete', 'id' => $model->id)); ?></li>

</ul>



Well…thanks for everything… :P

You can easily implement it by creating your class extending CGridColumn and then use like:




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

        'dataProvider'=>$model->search(),

        'filter'=>$model,

        'ajaxUpdate' => false,

        'columns'=>array(

                array(

                        'class'=>'PartialColumn',

                        'partial' => '_mycustomcolumn', // same as before, but replacing the entire cell                        

                ),

        ),

)); ?>



Hi, samdark.

I am going that way, making my own copy/pasted column class, and works well btw.

Just want to know if anyone else could need some like this feature shipped with YII.

And btw2, is not the same if I just copy/paste something, extend it and “make it work” that Quiang, or some other YII developer (cough…samdark…cough) make it the right way… :P

Cheers!

i have tried using partial but it does not work at all please helpppppppppppppppppppppppppppppppppp