EasyUi datagrid列表增加復選框


本文為博主原創,未經允許不得轉載

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); 
    }
    
}

 效果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM