Layui Tableデフォルト全選択

12378 ワード

<table class="layui-hide" id="test" data-type="reload" lay-filter="test"></table>
table.render({
     
elem: '#test'
 , url: ''
 , where: {
     }
 , parseData: function (res) {
     
   let count = res.data ? res.data.totalCount : ''
   let list = res.data ? res.data.list : ''
   return {
     
     "code": res.status, // 
     "msg": res.msg, // 
     "count": count, // 
     "data": list // 
   }
 }
 , cellMinWidth: 80 // ,layui 2.2.1  
 , page: true
 , limit: 1000
 , limits: [200,400,600,800,1000]
 , cols: [[
   {
      type: 'checkbox' }
   , {
      field: 'uid', title: 'ID' }
   , {
      field: 'name', title: ' ' }
 ]]
 , id: 'test'
 ,done: function(res, page, count){
     
 //  
 //  
   $('.layui-table-header input[name="layTableCheckbox"]').prop('checked', true)
   $('.layui-table-header input[name="layTableCheckbox"]').next().addClass('layui-form-checked')
  //  
   res.data.forEach((element, index) => {
     
     element["LAY_CHECKED"]='true'
     $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
     $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
   });
 }
});
let cher = []
table.on('checkbox(test)', function(obj){
     
  //  , uid cher, cher uid
	if (obj.checked == false) {
     
	  if (!cher.includes(obj.data.uid)){
     
	    console.log('you')
	    cher.push(obj.data.uid)
	  }
	} else {
     
	  let n = cher.indexOf(obj.data.uid)
	  cher.splice(n, 1)
	}
	console.log(cher)
});