fhelix72
(Lorenzo 99)
February 16, 2010, 8:34am
1
Hello, I would like to use CGridView and CButtonColumn, the buttons should be different for each row conditioned by the data in the row.
So I could have in the first row "Show Update Delete" in the second only "Show" and so on…
Is this possible?
thanks
yiimann
(Contact)
February 17, 2010, 8:05pm
2
Maybe by attaching a behaviour to CDataColumn you could change the buttons template for each row
mdomba
(Maurizio Domba Cerin)
February 18, 2010, 12:03pm
3
lruiz
(Oracleruiz)
February 19, 2010, 4:00pm
4
Hello,
thanks for the extension. It helped me to that I was looking for. Hide the update and edit buttons of all rows.
By the way, which is the function of the property visible from CButtonColumn class? Because for me it don’t work or I don’t know how to use it.
mdomba
(Maurizio Domba Cerin)
February 19, 2010, 10:12pm
5
Hello,
thanks for the extension. It helped me to that I was looking for. Hide the update and edit buttons of all rows.
By the way, which is the function of the property visible from CButtonColumn class? Because for me it don’t work or I don’t know how to use it.
Note that this extension is better suited for the need to have different buttons in different rows… if you want to omit the update button in all rows than it is faster to just set the template property - http://www.yiiframework.com/doc/api/CButtonColumn#template-detail
the visible property is for the custom buttons - http://www.yiiframework.com/doc/api/CButtonColumn#buttons-detail
toall
(Tomasz Aleksandrowicz)
March 4, 2013, 9:07am
6
I resolved this problem like below:
In this example visibility of delete button depends on result of function CzyTypJestDowiazany().
CGridViewVidget :
$this->widget(‘zii.widgets.grid.CGridView’, array(
‘id’=>‘typy-grid’,
‘dataProvider’=>$DataProvTU,
‘columns’=>array(‘nazwa’,
array('class'=>'CButtonColumn',
'htmlOptions'=>array('style'=>'float:left;'),
'template'=>'{update} {delete}',
'buttons'=>array(
'deleteButtonVisible'=>'User::canDelete($data->id)',
'delete'=>array('url'=>'CController::createUrl("/typyUzytkownikow/delete",array("id"=>$data->primaryKey))',
[b] 'visible'=>'CzyTypJestDowiazany($data->id)', [/b]
),
),
),
),
));
And now function CzyTypJestDowiazany . You can put it in Controler or in some other file included in index.php.
function CzyTypJestDowiazany($id_typu){
// Put Your code here …
// whatever you want
// and return false or true depend of result of your code.
if ($RESULT) {return true;}
else {return false;}
}