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();
}
Nice !
Nice extension.
Just a request:
I'd rather want the 'yesno' button to show the current state.
Maybe not a single property of 'yesnoButtonImageUrl', but a pair of properties : 'yesButtonImageUrl' and 'noButtonImageUrl'.
hmmm
sounds reasonable, not something right out of my head. bet i need a bit more time to figure that out.
[updated] @softark, thanks for the request. i made the change to support flipping yes/no images. check it out.
Yeah !
Looks good to me. (You're so fast, btw)
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.