In regards to my last reply - I have implemented a solution. Unfortunately it is not true Yii code, I have used some raw MySql code in order to make it work - I am new to the Yii framework but know PHP to some decent amount.
Here is my code - edit the parts in CAPS if you use it in your web app.
View file (.../admin.php):
[CODE]
…
<?php
$this->widget(‘bootstrap.widgets.TbGridView’, array(
'id'=>'GRID_ID_GOES HERE', // Add Grid ID here
'type' => 'striped bordered',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'class'=>'CCheckBoxColumn', // Checkboxes
'selectableRows'=>2, // Allow multiple selections
),
'COLUMN_1', // Columns
'COLUMN_2',
'COLUMN_3',
'COLUMN_4',
'COLUMN_5',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
));
$this->widget(‘bootstrap.widgets.TbButton’,array( // Button to delete
‘label’ => ‘Delete Selected Items’,
‘type’ => ‘danger’,
‘size’ => ‘small’,
‘id’ => ‘delete’
));
?>
<?php
Yii::app()->clientScript->registerScript(‘delete’,’
$("#delete").click(function(){
var checked=$("#GRID_ID").yiiGridView("getChecked","GRID_ID_c0"); // _c0 means the checkboxes are located in the first column, change if you put the checkboxes somewhere else
var count=checked.length;
if(count==0){
alert("No items selected");
}
if(count>0 && confirm("Do you want to delete these "+count+" item(s)"))
{
$.ajax({
data:{checked:checked},
url:"'.CHtml::normalizeUrl(array('CONTROLLER_NAME/RemoveChecked')).'",
success:function(data){$("#GRID_ID").yiiGridView("update",{});},
});
}
});
');?>[/CODE]
In my controller file:
[CODE]…
public function actionRemoveChecked()
{ if(Yii::app()->request->getIsAjaxRequest())
{
$checkedIDs=$_GET['checked'];
foreach($checkedIDs as $id){
$connect = mysql_connect ('DB_HOST', 'DB_USERNAME', 'DB_PASSWORD'); // Edit as appropriate
$submit = mysql_query("DELETE FROM DATABASE.TABLE WHERE id=".$id); // Edit as appropriate
}
}
}
…[/CODE]
Hope this helps people!
Regards,
Stephen