bootstrap table show/hide Column隐藏显示列的方法

bootstrap table showColumn显示指定的列,hideColumn隐藏指定的列。

showColumn显示列方法

参数名称参数说明
name需要显示的列

showColumn代码例子

//显示catalog列
$table.bootstrapTable('showColumn', 'catalog')

hideColumn隐藏列方法

参数名称参数说明
name需要显示的列

hideColumn代码例子

//隐藏catalog列
$table.bootstrapTable('hideColumn', 'catalog')

在线试一试 

完整例子

<!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 hideColumn showColumn在线例子</title>
    <style>
  .table-demo {
    width: 80%;
    margin: 30px auto 0px auto;
    }
   .titles {
  float: right;
  clear: both;
  }
    </style>
</head>
<body>
  <div id="toolbar">
    <button onclick="col(1)">隐藏的列</button> 
    <button onclick="col(2)">显示的列</button> 
  </div>
    <div class="table-demo">
        <table id="table"  ></table>
    </div>
    <script>
        //设置需要显示的列
        var columns = [
        { 
          checkbox:true
        },
        { 
           field:"Id",  
          title: 'ID'
        }, {
            field: 'catalog',
            title: '分类'
        } ];
      var data= [{
            Id: 11,
            catalog: 'catalog 101', 
        }, {
            Id: 12,
            catalog: 'catalog 102', 
        }, {
            Id: 13,
            catalog: 'catalog 103', 
      } ];
     
     $('#table').bootstrapTable({  
        toolbar:"#toolbar",  
        data:data,
        columns: columns,  
      });
 
     function col(icase)
     {
      
       if(icase===1)
       {
         $('#table').bootstrapTable('hideColumn','catalog');
       }
       if(icase===2)
       {
         $('#table').bootstrapTable('showColumn','catalog');
       }
       
     } 
    </script>
</body>
</html>