本文为博主原创,未经允许不得转载

1.增加复选框列

{
field: 'oid',
title: '<input type=\"checkbox\" name=\"selectRadioList\" id=\"selectRadioList\" checked= true onchange="selectAll()"/>',
width: 28,
formatter: function(value, rowData, rowIndex){
return "<input type=\"checkbox\" name=\"selectRadioName\" value=\"" + rowData.id + "\" >";
}
},

2.表单提交或查询时获取选中的数据id

var _this = this;
//获取选中的数据
obj = document.getElementsByName("selectRadioName");
var ids;
var checked = false;
for(k in obj){
var selectId = obj[k].value;
if(selectId){
if(obj[k].checked){
//取到对象数组后,我们来循环检测它是不是被选中
//如果选中,将value添加到变量s中
if(ids!=null){
ids+=","+selectId;
}else{
ids =selectId;
}
}
}
}
if(ids==null||ids == undefined){
_this.tip("请选择记录");
return;
}

3.控制标题栏中复选框全选和取消操作

function selectAll(){ 
var vals=document.getElementById("selectRadioList").checked;
if(vals==true){
$("input[name='selectRadioName']").attr("checked", 'checked');
$("input[name='selectRadioName']").prop("checked",true);
}
if(vals==false){
$("input[name='selectRadioName']").removeAttr("checked");
$("input[name='selectRadioName']").prop("checked",false);
}

}

 效果:

EasyUi datagrid列表增加复选框_复选框