xbuttoncolumn extends CButtonColumn adding an extra button {yesno} for updating db status-type field in the way of {delete} button via ajax

  1. Update
  2. Scenario
  3. Requirements
  4. Install & Usage

Update

  • version 1.1 April 21, 2012 - support fliping yes/no image
  • version 1.0.1 April 19, 2012 - original version

Scenario

when you simply want to flip a status in gridview with a button - eg. prove a comment or post in your blog;

when you want add row in gridview to your favorite under your profile - eg. bookmark;

inspired by reading this post and this post

Requirements

Tested under Yii 1.1.10

Install & Usage

1) unzip XButtonColumn.php and folder /XButtonColumn/ to /protected/components/ folder

2) in CGridView widget: change your CButtonColumn's class name to XButtonColumn & specify properties for this new button

version 1.0

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

	'id' => 'mymodel-grid',
	'dataProvider' => $model->search(),
	'columns' => array(
		'id',
		'name',
		'yesno',
		array(
			'class' => 'XButtonColumn', //<--new XButtonColumn class
			'template' => '{view}{update}{delete}{yesno}', //<-- new button {yesno}
			'yesnoAction' => 'flag', //<--name the new button
			'yesnoButtonLabel' => 'flip flag', //<--label the new button
			/* 
			* more properties {yesno} button related
			* please refer to deleteButton in CButtonColumn for usage
			*
			'yesnoButtonImageUrl' => null,
			'yesnoButtonUrl'=>null, //default to yesnoAction
			'yesnoButtonOptions=>null;
			'yesnoConfirmation'=>null, //confirmation message
			'afterYesno'=>null, 
			*/

		),
	),
)); 

?>

updated: version 1.1

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

	'id' => 'mymodel-grid',
	'dataProvider' => $model->search(),
	'columns' => array(
		'id',
		'name',
		'yesno',
		array(
			'class' => 'XButtonColumn', //<--new XButtonColumn class
			'template' => '{view}{update}{delete}{yesno}', //<-- new button {yesno}
			'yesnoAction' => 'flag', //<--action for this button
			'yesnoValue' => '$data->yesno',
			//'yesValue' => '1',
			//'noValue' => '0',
			//'yesButtonLabel' => 'Flip to No',
			//'yesButtonImageUrl' => null,
			//'noButtonLabel' => 'Flip to Yes',
			//'noButtonImageUrl' => null,			

		),
	),
)); 

?>

3) Add new action in your controller to response to the new button

//assuming: model => Mymodel & you have a field in db.table named 'yesno' value 0 or 1
public function actionFlag($id) {

	//simplified version, add more code here please
	$model = $this->loadModel($id, 'Mymodel');
	$model->yesno = 1 - $model->yesno;
	$model->save();
}

3 0
6 followers
608 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: rootbear
Created on: Apr 19, 2012
Last updated: 12 years ago

Downloads

show all

Related Extensions