easyui datagrid的全选、全不选方法

本文介绍了如何在easyui datagrid中实现全选和全不选功能,通过设置column的checkbox属性为true创建多选框,同时讲解了onCheckAll和onUncheckAll等事件的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里应用的是easyui datagrid自带的全选和全不选事件

在easyui datagrid里面定义多选框也很容易,只需要在column定义为【checkbox: true】即可
然后给全选方法做定义:
onCheckAll: function (rows) { onCheckAll(rows, 'ttex1', 1); },
这里的rows就是所有的项目
当然datagrid还有很多方法,比如选中行触发事件onCheck、取消选中行事件onUncheck等等。
可以参考一下这篇博文:
datagrid属性和方法

  1. 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);
}
  1. 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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值