2

Hello is it possible to add another delete button to Yii CGridView? I would like it to make an ajax post request to one of mine controllers.

An use case would be:

Lets say I have a blog entry with comments. In administration I would like to have a gridview where I can delete this blog entry (this is already) possible. I would also like to have another delete button next to the original delete button which would only delete blog's comments (which I don't know how to add).

I looked over the HTML generated by Yii framework to see how the original delete button works. One possible solution would be to copy/paste that delete and refresh java script code and modify it a bit. But I don't like this. I have some concerns that if I do this, when I upgrade Yii framework there is no guarantee that my solution will still work.

Kai
  • 38,985
  • 14
  • 88
  • 103
netuser24
  • 86
  • 1
  • 9

2 Answers2

4

Use above tutorial and add class="delete" to the new button

'options'=>array('class'=>'delete')

Yii framework assigns ajax call to this class.

array('class'=>'CButtonColumn','template'=>'{remove}{view}{update}{delete}',
          'htmlOptions'=>array('style'=>'width:65px'),
          'buttons'=>array(
            'remove'=>array('url'=>'Yii::app()->createUrl("resolution/removeApp", array("id_application"=>$data->id_application,"id_resolution"=>'.$model->id_resolution.'))','label'=>'Remove application from resolution.','imageUrl'=>Yii::app()->request->baseUrl.'/images/remove.png','options'=>array('class'=>'delete')),
            ))
Speedy
  • 41
  • 2
0

You can follow this Using CButtonColumn to customize buttons in CGridView to add a new button which will be calling the action in your controller to delete comments. Cheers.

Puigcerber
  • 9,814
  • 6
  • 40
  • 51
  • I've already tried this by adding custom button to CButtonColumn's buttons property. Problem was that click element in button array doesn't get php evaluated (as url) so I can't pass row's id to my ajax post request. – netuser24 Mar 26 '12 at 13:54
  • I'm sorry then, because I guess I don't understand your question. – Puigcerber Mar 28 '12 at 07:43