Yii Framework Forum: How to extendinc CbuttonColumn - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to extendinc CbuttonColumn Rate Topic: -----

#1 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 01 March 2010 - 05:07 AM

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
Thanks and Kind Regards
------
DanDinDun
0

#2 User is offline   yiimann 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 102
  • Joined: 19-December 09

Posted 01 March 2010 - 10:53 AM

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'=>'.....',
				)
                      );
}

0

#3 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 01 March 2010 - 04:18 PM

View Postyiimann, on 01 March 2010 - 10:53 AM, said:

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'=>'.....',
				)
                      );
}




Ok sir.. thanks, I will try it.. :-)
Thanks and Kind Regards
------
DanDinDun
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users