GridView 全选可以吗?
GridView 全选可以吗?
sure.you can see CCheckBoxColumn
$this->widget('zii.widgets.CGridView', array(
...
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
'id'=>'id',
'selectableRows'=>2,
),
cute,可是我想选中后☑怎么做个按钮的jquery事件删除掉所选的呢
I solved it
<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.');
}
mark
做个记号,需要的时候来取!
mark
mark
在view中写过多的处理不便于代码复用, 比较好的解决办法是在gridview外面套一个cactiveform.
怎么个套法?
标记下