js是通过registerClientScript这个方法引用进去的。
这个问题肯定是自己写个js进去 不用引用的
你问题的最终取向就是CCheckBoxColumn批量删除 批量更新 问题
根据你的需求和我做过的项目
i write like this,hope it‘ll be some help for u.
view:
<script type="text/javascript">
/<![CDATA[/
var GetCheckbox = function (){
var data=new Array();
$("input[name='selectdel[]']:checked").each(function (){
// if($(this).attr("checked")==true){
data.push($(this).val());
// }
});
if(data.length > 0){
$.post('<?php echo CHtml::normalizeUrl(array('DelSelect'));?>',{'selectdel[]':data},
function(){window.location.reload();}
);
}else{
alert("请选择要删除的内容!");
}
}
/]]>/
</script>
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'leave-grid',
'dataProvider'=>$model->search_username(),
//'filter'=>$model,
'columns'=>array(
array(
'id'=>'id',
'class'=>'CCheckBoxColumn',
'selectableRows'=>2,
'footer'=>'<button type="button" onclick="GetCheckbox();" style="width:76px">批量删除</button>',
'headerHtmlOptions' => array('width'=>'33px'),
'checkBoxHtmlOptions' => array('name' => 'selectdel[]'),
'htmlOptions'=>array(
'style'=>'text-align:center',
)
),
'date',
'type'=>array(
'name'=>"类型",
'value'=>'($data->type==1)?"上午"<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />($data->type==2)?"下午":"整天")',
),
'reasons',
'username',
'pass'=>array(
'name'=>'审核结果',
'type'=>'html',
// 'value'=>'(($data->pass==1)?"通过:"审核中")',
'value'=>'($data->pass)?"<img src=\"images/passed.jpg\" alt=\"通过\" width=\"15\" height=\"15\">":"<img src=\"images/ing.gif\" alt=\"审核中\">"',
'htmlOptions'=>array(
'style'=>'text-align:center',
)
),
array(
'header'=>'操作',
'class'=>'CButtonColumn',
),
),
)
); ?>
controller:
public function actionDelSelect()
{
if (Yii::app()->request->isPostRequest)
{
$criteria= new CDbCriteria;
$criteria->addInCondition('id', $_POST['selectdel']);
Leave::model()->deleteAll($criteria);
if(isset(Yii::app()->request->isAjaxRequest)) {
echo CJSON::encode(array('success' => true));
$this->redirect(array('/leave/admin'));
} else
$this->redirect(array('/leave/admin'));
// $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
rules里面记得申明
array(‘allow’, // allow authenticated user to perform ‘create’ and ‘update’ actions
'actions'=>array('create','update','delSelect'),//记得申明here
'users'=>array('@'),
),
这样就可以全选删除 自动刷新。