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


免責聲明!

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



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