yii cgridview 怎么除去table操作列
1个回答
展开全部
1,CGridView中的columns添加
array(
'selectableRows' => 2,
'footer' => '<button type="button" style="width:76px">批量删除</button>',
'class' => 'CCheckBoxColumn',
'headerHtmlOptions' => array('width'=>'33px'),
'checkBoxHtmlOptions' => array('name' => 'selectdel[]'),
),
作用是添加多选框
2.js代码
var GetCheckbox = function (){
var data=new Array();
$("input:checkbox[name='selectdel[]']").each(function (){
if($(this).attr("checked")==true){
data.push($(this).val());
}
});
if(data.length > 0){
$.post('<?php echo CHtml::normalizeUrl(array('/admin/words/delall/'));?>',{'selectdel[]':data}, function (data) {
var ret = $.parseJSON(data);
if (ret != null && ret.success != null && ret.success) {
$.fn.yiiGridView.update('yw1');
}
});
}else{
alert("请选择要删除的关键字!");
}
}
3.Action
public function actionDelall()
{
if (Yii::app()->request->isPostRequest)
{
$criteria= new CDbCriteria;
$criteria->addInCondition('id', $_POST['selectdel']);
Words::model()->deleteAll($criteria);//Words换成你的模型
if(isset(Yii::app()->request->isAjaxRequest)) {
echo CJSON::encode(array('success' => true));
} else
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
array(
'selectableRows' => 2,
'footer' => '<button type="button" style="width:76px">批量删除</button>',
'class' => 'CCheckBoxColumn',
'headerHtmlOptions' => array('width'=>'33px'),
'checkBoxHtmlOptions' => array('name' => 'selectdel[]'),
),
作用是添加多选框
2.js代码
var GetCheckbox = function (){
var data=new Array();
$("input:checkbox[name='selectdel[]']").each(function (){
if($(this).attr("checked")==true){
data.push($(this).val());
}
});
if(data.length > 0){
$.post('<?php echo CHtml::normalizeUrl(array('/admin/words/delall/'));?>',{'selectdel[]':data}, function (data) {
var ret = $.parseJSON(data);
if (ret != null && ret.success != null && ret.success) {
$.fn.yiiGridView.update('yw1');
}
});
}else{
alert("请选择要删除的关键字!");
}
}
3.Action
public function actionDelall()
{
if (Yii::app()->request->isPostRequest)
{
$criteria= new CDbCriteria;
$criteria->addInCondition('id', $_POST['selectdel']);
Words::model()->deleteAll($criteria);//Words换成你的模型
if(isset(Yii::app()->request->isAjaxRequest)) {
echo CJSON::encode(array('success' => true));
} else
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询