How to extendinc CbuttonColumn


(Didienna) #1

Hi sir,

I use CGridView to view my data.

here is my view




<div style="border-bottom:1px solid maroon;margin-bottom:10px;">

    <div style="float:left;width:80%;"><?php echo CHtml::link(CHtml::encode('Add New'), array('admin/create')); ?></div>

    <div style="float:right;width:20%;color:maroon;font-size:18px;text-align:right;">Admin User</h1</div>

    <div style="clear:both;"></div>

</div>


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

	'dataProvider' => $dataProvider,

	'columns'=>array(

                array(

			'name'=>'username',

			'type'=>'raw',

			'value'=>'$data->username'

		),

                'display_name',

		array(

			'name'=>'email',

			'value'=>'$data->email',

		),

		'created_time:datetime',

		'edited_time:datetime',

                array(

                        'name' => 'status',

                        'value' => 'SuperAdmins::lookup_item($data->status)'

                ),

		array(

			'class'=>'CButtonColumn',

		),

	)

)); ?>



I using class CButtonColumn and defaultly it was provide 3 button for each record ( Detail, Update anda Delete)

The problem is, I want add some button (Publish and Hide) button. both button will be displayed alternately (not together). how I can do this sir…

thank you very much…

Dan Din Dun


(Contact) #2

I guess you can either add a behavior or extend the class and use ButtonColumn in your cgridview instead of CButtonColumn.

I’m not sure for the behavior way as cgridview takes a classname as argument and not a object




class ButtonColumn extends CButtonColumn

{

	/**

	 * @var array the configuration for additional buttons. Each array element specifies a single button

	 * which has the following format:

	 * <pre>

	 * 'buttonID' => array(

	 *     'label'=>'...',     // text label of the button

	 *     'url'=>'...',       // the PHP expression for generating the URL of the button

	 *     'imageUrl'=>'...',  // image URL of the button. If not set or false, a text link is used

	 *     'options'=>array(...), // HTML options for the button tag

	 *     'click'=>'...',     // a JS function to be invoked when the button is clicked

	 * )

	 * </pre>

	 * Note that in order to display these additional buttons, the {@link template} property needs to

	 * be configured so that the corresponding button IDs appear as tokens in the template.

	 */


public $buttons= array(

                        'newbtn'=>array(

					'label'=>'.....',

					'url'=>'......',

					'imageUrl'=>'......',

					'options'=>'.....',

				)

                      );

}




(Didienna) #3

Ok sir… thanks, I will try it… :slight_smile: