bootstrap table getHiddenColumns获取表格隐藏的列,即获取哪些列当前不可见的列,因为有的列可以通过工具栏或者方法可以设置列隐藏,如何隐藏某个列请查看左侧菜单。
参数名称 | 参数说明 |
无 |
//获取隐藏的列 返回值为数组
var cols= $('#table').bootstrapTable('getHiddenColumns');
//返回值cols的格式如下
[{
"widthUnit":"px","radio":false,"checkbox":false,"checkboxEnabled":true,"clickToSelect":true,
"showSelectTitle":false,"sortable":false,"order":"asc","visible":false,"switchable":true,
"cardVisible":true,"searchable":true,"searchFormatter":true,"escape":false,"field":"clog",
"title":"分类","colspanIndex":2,"fieldIndex":2
}]
copy
<!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 getHiddenColumns在线例子</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> <button onclick="getHideCols()">获取隐藏的列</button> </div> <div class="table-demo"> <table id="table" ></table> </div> <script> //设置需要显示的列 var columns = [ { checkbox:true }, { field:"Id", title: 'ID' }, { field: 'clog', title: '分类' } ]; var data= [{ Id: 11, clog: '分类 101', }, { Id: 12, clog: '分类 102', }, { Id: 13, clog: '分类 103', } ]; $('#table').bootstrapTable({ toolbar:"#toolbar", data:data, columns: columns, }); $('#table').bootstrapTable('hideColumn','clog'); function col(icase) { if(icase===1) { $('#table').bootstrapTable('hideColumn','clog'); } if(icase===2) { $('#table').bootstrapTable('showColumn','clog'); } } function getHideCols() { var cols= $('#table').bootstrapTable('getHiddenColumns'); alert(JSON.stringify(cols)); $("#toolbar").html(JSON.stringify(cols)); } </script> </body> </html>
copy