Yii 1.1: mybuttoncolumn

extension to make CButtonColumn different in CGridView from row to row depending on data in single rows
4 followers

NOTE: As of Yii version 1.1.1 the visible attribute is added to the core, so this extension is NOT NEEDED.

myButtonColumn extends CButtonColumn in CGridView and adds the attribute 'visible' to the buttons properties so that the buttons can be different from row to row depending on the evaluation of this attribute.

For the default buttons adds:

  • viewButtonVisible
  • updateButtonVisible
  • deleteButtonVisible.

Documentation

Requirements

  • Yii 1.0 or above

Installation

  • Extract the release file under protected/components

Overview

myButtonColumn extends CButtonColumn in CGridView and adds the attribute 'visible' to the buttons properties so that the buttons can be different from row to row depending on the evaluation of this attribute.

Additionaly, for the default buttons, adds:

  • viewButtonVisible
  • updateButtonVisible
  • deleteButtonVisible

Usage

Use it like CGridButton

<?php
$this->widget('zii.widgets.grid.CGridView', array(
  'dataProvider'=>$dataProvider,
  'columns'=>array(
    'name',
    'type',
    array(
      'class'=>'myButtonColumn',
      'viewButtonVisible'=>'$data->id==Yii::app()->user->id',
      'updateButtonVisible'=>'$data->id==Yii::app()->user->id',
      'deleteButtonVisible'=>'User::canDelete($data->id)',
    ),
  ),
));
?>

Change Log

February 18, 2010

  • Initial release.

Total 4 comments

#4587 report it
sis at 2011/07/22 07:59am
SOLVED: call_user_func_array() expects parameter 1 ...

I had some error Error 500:

PHP Error [2]

call_user_func_array() expects parameter 1 to be a valid callback, no array or string given (C:\server\www\crm\yii\framework\base\CComponent.php:621)

#0 unknown(0): CWebApplication->handleError()

1 C:\server\www\crm\yii\framework\base\CComponent.php(621): call_user_func_array()

2 C:\server\www\crm\yii\framework\zii\widgets\grid\CButtonColumn.php(306): myButtonColumn->evaluateExpression()

3 C:\server\www\crm\protected\components\myButtonColumn.php(42): myButtonColumn->renderButton()

I modified line 40 like below. Now everything works fine.

$button['visible']=$this->evaluateExpression("'".$button['visible']."'",array('data'=>$data,'row'=>$row));
#4449 report it
Ali Lotfi at 2011/07/10 05:51am
tnx

tnx for help

#644 report it
cma at 2010/03/30 07:58pm
Suggestion

Thank you for your exemple.

Default action links doesnt work when the grid is rendered in the contect of a renderPartial with another AR. The links are going to the main view....

So I add this member :

public $baseActionUrl;

And do some stuff before base init()

public function init()

  if ( !empty( $this->baseActionUrl ) )
  {
     $this->viewButtonUrl = str_replace( '"view"' , '"' . ( $this->baseActionUrl ) . '/view"' , $this->viewButtonUrl );
     $this->updateButtonUrl = str_replace( '"update"' , '"' . ( $this->baseActionUrl ) . '/update"' , $this->updateButtonUrl );
     $this->deleteButtonUrl = str_replace( '"delete"' , '"' . ( $this->baseActionUrl ) . '/delete"' , $this->deleteButtonUrl );
  }

  parent::init();
  ....
#849 report it
DarkNSF at 2010/02/18 10:40pm
nice

i was searching the yii docs for something like this.

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: Other Open Source License
  • Developed by: Maurizio Domba Cerin
  • Category: User Interface
  • Votes: +7 / -1
  • Downloaded: 755 times
  • Created on: Feb 18, 2010
  • Last updated: Oct 18, 2010