1、添加复选框
<th field="ck" checkbox="true"></th>
将属性singleSelect修改为false,可以多选
2、批量删除传递数组
function remove(index){
$('#datagrid').datagrid('selectRow',index);
var items = $('#datagrid').datagrid('getSelections');
if(items.length==0){
$.messager.alert('提示','请选择删除的记录!');
return false;
}
$.messager.confirm('信息提示','确定要删除该记录?', function(result){
if(result){
//var items = $('#datagrid').datagrid('getSelections');
var ids =[];
$(items).each(function(){
ids.push(this.id);
});
//alert(console.log(ids));return false;
$.ajax({
type:"POST",
url:'{:url("User/del")}',
dataType: 'json',
data:{'id':JSON.stringify(ids)},
traditional: true,
success:function(data){
if(data){
$.messager.alert('信息提示','删除成功!','info');
$('#datagrid').datagrid('reload');
}
else
{
$.messager.alert('信息提示','删除失败!','info');
}
}
});
}
});
}
传递数组使用JSON.stringify()
3、后台接受
public function del(){
if(request()->isAjax()) {
$id=input("post.id");
$id = json_decode($id);
if(Db::name('user')->where('id','in',$id)->delete())
{
return json(true,200);
}else{
return json(false,0);
}
}
}