var all_check = new Array();// 勾选的pm_code集合
var table_data = new Array();// 表格数据缓存
var tableResult = table.render({
elem: ‘#’ + Also.tableId,
url: Feng.ctxPath + ‘/also/getCheckOutFile’,
page: true,
height: “full-250”,
cellMinWidth: 100,
cols: Also.initColumn(),
done: function (res, curr, count) {
$(‘table tr’).on(‘click’,function(){
$(‘table tr’).css(‘background’,’’);
$(this).css(‘background’,’<%=PropKit.use(“config.properties”).get(“table_color”)%>’);
});
// 设置换页勾选之前的
table_data = res.data;
//在缓存中找到PM_CODE ,然后设置data表格中的选中状态
//循环所有数据,找出对应关系,设置checkbox选中状态
for(var i=0;i<res.data.length;i++){
for(var j=0;j<all_check.length;j++){
if(res.data[i].id==all_check[j].id){
//这里才是真正的有效勾选
res.data[i][“LAY_CHECKED”]=‘true’;
//找到对应数据改变勾选样式,呈现出选中效果
var index= res.data[i][‘LAY_TABLE_INDEX’];
$(’.layui-table tr[data-index=’ + index + ‘] input[type=“checkbox”]’).prop(‘checked’, true);
$(’.layui-table tr[data-index=’ + index + ‘] input[type=“checkbox”]’).next().addClass(‘layui-form-checked’);
}
}
}
//设置全选checkbox的选中状态,只有改变LAY_CHECKED的值, table.checkStatus才能抓取到选中的状态
var checkStatus = table.checkStatus(‘AlsoFileTable’);
if(checkStatus.isAll){
$(’.layui-table-header th[data-field=“0”] input[type=“checkbox”]’).prop(‘checked’, true);
$(’.layui-table-header th[data-field=“0”] input[type=“checkbox”]’).next().addClass(‘layui-form-checked’);
}
}
});
//复选框选中监听,将选中的id 设置到缓存数组,或者删除缓存数组
table.on('checkbox(AlsoFileTable)', function (obj) {
console.info(obj)
if(obj.checked==true){
if(obj.type=='one') {
all_check.push(obj.data);
}else{
for(var j=0;j<table_data.length;j++){
var bool=true;
for(var i=0;i<all_check.length;i++){
if(all_check[i].id==table_data[j].id){
bool=false;
}
}
if(bool){
all_check.push(table_data[j]);
}
}
}
}else{
if(obj.type=='one'){
for(var i=0;i<all_check.length;i++){
if(all_check[i].id==obj.data.id){
all_check.remove(i);
}
}
}else{
for(var j=0;j<table_data.length;j++){
for(var i=0;i<all_check.length;i++){
if(all_check[i].id==table_data[j].id){
all_check.remove(i);
}
}
}
}
}
});
//删除数组自定义函数
Array.prototype.remove=function(dx)
{
if(isNaN(dx)||dx>this.length){return false;}
for(var i=0,n=0;i<this.length;i++)
{
if(this[i]!=this[dx])
{
this[n++]=this[i]
}
}
this.length-=1
}