bootstrap table 保留翻页选中数据

$(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'
  }
]

猜你喜欢

转载自www.cnblogs.com/liw66/p/10188942.html