这里应用的是easyui datagrid自带的全选和全不选事件
在easyui datagrid里面定义多选框也很容易,只需要在column定义为【checkbox: true】即可
然后给全选方法做定义:
onCheckAll: function (rows) { onCheckAll(rows, 'ttex1', 1); },
这里的rows就是所有的项目
当然datagrid还有很多方法,比如选中行触发事件onCheck、取消选中行事件onUncheck等等。
可以参考一下这篇博文:
datagrid属性和方法
- onUncheckAll
/**全不选的处理*/
function onUncheckAll(rows,textID,examType){
var oldTmp = document.getElementById(textID).value;//原有的 内容
var newText=oldTmp;
$.each(rows, function(index, item){
var rowData= rows[index];//获取到行内容
var rowValue ="";
if(examType==0) {
rowValue = "检验:" + GetDateStr(rowData.repTime, 0) + "," + rowData.itemName + ":" + rowData.resultValue + rowData.itemUnit + ";";//拼凑行内容
}else{
rowValue = "检查:" + GetDateStr(rowData.sendTime, 0) + "," + rowData.repName + ":" + rowData.examination+ ";";
}
if (newText.indexOf(rowValue) > -1) {//如果存在则替换
newText = newText.replace(rowValue, "");
}
});
$('#'+textID).val(newText);
}
- onCheckAll
/**全选的处理*/
function onCheckAll(rows,textID,examType){
var oldTmp = document.getElementById(textID).value;//原有的 内容
var newText=oldTmp;
$.each(rows, function(index, item){
var rowData= rows[index];//获取到行内容
var rowValue ="";
if(examType==0) {
rowValue = "检验:" + GetDateStr(rowData.repTime,0) + "," + rowData.itemName + ":" + rowData.resultValue + rowData.itemUnit + ";";//拼凑行内容
}else {
rowValue = "检查:" + GetDateStr(rowData.sendTime, 0) + "," + rowData.repName + ":" + rowData.examination + ";";
}
if(newText.indexOf(rowValue)==-1){//如果不存在则新增
newText=newText+ rowValue;
}
});
$('#'+textID).val(newText);
}