Yii實(shí)現(xiàn)復(fù)選框批量操作實(shí)例代碼
整理文檔,搜刮出一個(gè)Yii實(shí)現(xiàn)復(fù)選框批量操作實(shí)例代碼,稍微整理精簡(jiǎn)一下做下分享。
在視圖下
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),//Model里需要有個(gè)search()方法,$model是Controller中傳遞的Model對(duì)象
// /'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',
),
),
)); ?>
<select name="status" id="status">
<option value="1">通過(guò)</option>
<option value="0">不通過(guò)</option>
</select>
<button type="button" onclick="setStatus();" style="width:120px;">設(shè)置狀態(tài)</button>
<script type="text/javascript">
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('請(qǐng)至少選擇一個(gè)項(xiàng)目。');
return ;
}
//這里是傳遞的url post方法
$.post("index.php?r=user/status",{'ids[]':data,'status':$('#status').val()}, function (data) {
if (data=='ok') {
alert('設(shè)置狀態(tài)成功!');
}else{
alert('設(shè)置狀態(tài)失敗,請(qǐng)重試!');
}
window.open('index.php?r=user/admin','mainFrame');;
});
}
</script>
在Model中的search()函數(shù)
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);
//這里添加了一個(gè) compare, username 是 User 表的字段,$this->name 是我們添加的屬性,true 為模糊搜索
//$criteria->compare('username',$this->name,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Yii2 批量插入、更新數(shù)據(jù)實(shí)例
- YII框架批量插入數(shù)據(jù)的方法
- Yii框架批量插入數(shù)據(jù)擴(kuò)展類(lèi)的簡(jiǎn)單實(shí)現(xiàn)方法
- Yii2如何批量添加數(shù)據(jù)
- 淺析Yii2 gridview實(shí)現(xiàn)批量刪除教程
- yii2使用GridView實(shí)現(xiàn)數(shù)據(jù)全選及批量刪除按鈕示例
- JavaScript中全選、全不選、反選、無(wú)刷新刪除、批量刪除、即點(diǎn)即改入庫(kù)(在yii框架中操作)的代碼分享
- Yii中CGridView實(shí)現(xiàn)批量刪除的方法
- Yii2.0實(shí)現(xiàn)的批量更新及批量插入功能示例
相關(guān)文章
PHP讓數(shù)組中有相同值的組成新的數(shù)組實(shí)例
下面小編就為大家分享一篇PHP讓數(shù)組中有相同值的組成新的數(shù)組實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12
Mac版PhpStorm之XAMPP整合apache服務(wù)器配置的圖文教程詳解
選擇在PhpStorm集成apache服務(wù)器,但是很多朋友不知道是如何操作的,下面小編分步驟通過(guò)圖文的形式給大家介紹Mac版PhpStorm之XAMPP整合apache服務(wù)器配置的教程,感興趣的朋友一起看看吧2016-10-10
PHP之使用swoole統(tǒng)計(jì)在線人數(shù)和ID案例講解
這篇文章主要介紹了PHP之使用swoole統(tǒng)計(jì)在線人數(shù)和ID案例講解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08
DEDECMS首頁(yè)調(diào)用圖片集里的多張圖片
本文給大家分享的是織夢(mèng)系統(tǒng)中首頁(yè)調(diào)用圖片集里的多張圖片的方法,有相同需要的小伙伴可以參考下。2015-06-06
詳解將數(shù)據(jù)從Laravel傳送到vue的四種方式
這篇文章主要介紹了詳解將數(shù)據(jù)從Laravel傳送到vue的四種方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
ThinkPHP框架實(shí)現(xiàn)導(dǎo)出excel數(shù)據(jù)的方法示例【基于PHPExcel】
這篇文章主要介紹了ThinkPHP框架實(shí)現(xiàn)導(dǎo)出excel數(shù)據(jù)的方法,結(jié)合實(shí)例形式分析了thinkPHP添加org擴(kuò)展基于PHPExcel進(jìn)行Excel數(shù)據(jù)的導(dǎo)出操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-05-05
ThinkPHP框架實(shí)現(xiàn)session跨域問(wèn)題的解決方法
這篇文章主要介紹了ThinkPHP框架實(shí)現(xiàn)session跨域問(wèn)題的解決方法,需要的朋友可以參考下2014-07-07

