php点复选框 批量操作,Yii实现复选框批量操作实例代码

整理文档,搜刮出一个Yii实现复选框批量操作实例代码,稍微整理精简一下做下分享。

在视图下

<?php $this->widget('zii.widgets.grid.CGridView', array(

'id'=>'user-grid',

'dataProvider'=>$model->search(),//Model里需要有个search()方法,$model是Controller中传递的Model对象

// /'filter'=>$model,

'columns'=>array(

array(

'selectableRows' => 2,

'class' => 'CCheckBoxColumn',

'headerHtmlOptions' => array('width'=>'18px','align'=>'center'),

'checkBoxHtmlOptions' => array('name' => 'ids[]','align'=>'center'),

),

'homework_numberID',

'type',

'target',

'state',

'author_id',

array('name'=>'state','type'=>'raw','value'=>'($data->state =="not_read" ?"未读":"已审核")'),

// array('name'=>'passRecord','type'=>'date'),

array('name'=>'submit_time','type'=>'date'),

array(

'class'=>'CButtonColumn',

),

),

)); ?>

通过

不通过

设置状态

function getData(){

var data=new Array();

$("input:checkbox[name='ids[]']").each(function (){

if($(this).attr("checked")){

data.push($(this).val());

}

});

return data;

}

function setStatus(){

var data = getData();

if(data.length < 1) {

alert('请至少选择一个项目。');

return ;

}

//这里是传递的url post方法

$.post("index.php?r=user/status",{'ids[]':data,'status':$('#status').val()}, function (data) {

if (data=='ok') {

alert('设置状态成功!');

}else{

alert('设置状态失败,请重试!');

}

window.open('index.php?r=user/admin','mainFrame');;

});

}

在Model中的search()函数

public function search()

{

// @todo Please modify the following code to remove attributes that should not be searched.

$criteria=new CDbCriteria;

//$criteria->with = array('author'); //添加了和 author 的渴求式加载

// $this->state = "not_passed";

$criteria->compare('state',$this->state);

//这里添加了一个 compare, username 是 User 表的字段,$this->name 是我们添加的属性,true 为模糊搜索

//$criteria->compare('username',$this->name,true);

return new CActiveDataProvider($this, array(

'criteria'=>$criteria,

));

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。 ad51e517755f8fd6a7ec83ced4ecfaf3.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值