$(function () {
$('#exampleTable').on('uncheck.bs.table check.bs.table check-all.bs.table uncheck-all.bs.table',function(e,rows){
var datas = $.isArray(rows) ? rows : [rows]; // 点击时获取选中的行或取消选中的行
examine(e.type,datas); // 保存到全局 Array() 里
});
})
//exampleTable为bootstrap table名称
var overAllIds = new Array(); //全局数组
function examine(type,datas){
if(type.indexOf('uncheck')==-1){
$.each(datas,function(i,v){
// 添加时,判断一行或多行的 id 是否已经在数组里 不存则添加
overAllIds.indexOf(v.id) == -1 ? overAllIds.push(v.id) : -1;
});
}else{
$.each(datas,function(i,v){
overAllIds.splice(overAllIds.indexOf(v.id),1); //删除取消选中行
});
}
}
//设置bootstrap table checkbox自动选中
columns : [
{
checkbox : true,
formatter : function(value, row, index) {
if (row.userId == $("#userId").val()) {
overAllIds.indexOf(row.id) == -1 ? overAllIds.push(row.id) : -1;
return {
checked: true//设置选中
};
}
}
},
{
title : '操作',
width : '130',//设置列宽
field : 'id',
align : 'center'
}
]
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步