bootstrap table checkInvert反选反向选中行的方法

bootstrap table checkInvert反选反向选中行的方法,反选就是比如你手动选中了1,2行,执行checkInvert反选方法方法后就会变成1,2行不选中其他行选中。

checkInvert方法

参数名称

代码例子

//反选反向选中行的方法
$('#table').bootstrapTable('checkInvert');

在线试一试 

完整例子

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="https://www.itxst.com/package/jquery-3.3.1/jquery.js"></script>
    <link href="https://www.itxst.com/package/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
    <link href="https://www.itxst.com/package/bootstrap-table-1.15.3/bootstrap-table.css" rel="stylesheet" />
    <script src="https://www.itxst.com/package/bootstrap-table-1.15.3/bootstrap-table.js"></script> 
    <title>bootstrap table checkInvert在线例子</title>
    <style>
  .table-demo {
    width: 80%;
    margin: 30px auto 0px auto;
    }
   .titles {
  float: right;
  clear: both;
  }
    </style>
</head>
<body>
  
  <div id="toolbar">
    <button onclick="check(1)">选中1,3行</button> 
    <button onclick="check(2)">反选</button>  
  </div>
    <div class="table-demo">
        <table id="table"  ></table>
    </div>
    <script>
        //定义列
        var columns = [
        { 
          checkbox:true
        },
        { 
           field:"Id",  
          title: 'ID'
        }, {
            field: 'fid',
            title: 'Len'
        } ];
      var data= [{
            Id: 1,
            fid: 'B1', 
        }, {
            Id: 20,
            fid: 'B2', 
        }, {
            Id: 23,
            fid: 'B3', 
      } ];
     
     $('#table').bootstrapTable({  
        toolbar:"#toolbar",  
        data:data,
        columns: columns,  
      });
 
     
     function check(icase)
     {
      
       if(icase===1)
       {
         $('#table').bootstrapTable('checkBy', {field: 'Id', values:[1, 23]});
       }
       if(icase===2)
       {
         $('#table').bootstrapTable('checkInvert');
       }
       
     } 
    
    </script>
</body>
</html>