bootstrap table getVisibleColumns获取显示的列,即获取哪些列当前可见的列,因为有的列可以通过工具栏或者方法被隐藏了。
参数名称 | 参数说明 |
无 |
//获取显示的列 返回值为数组对象
var cols= $('#table').bootstrapTable('getVisibleColumns');
//返回值cols的格式如下
[
{"widthUnit":"px","radio":false,"checkbox":true,"checkboxEnabled":true,"clickToSelect":true,
"showSelectTitle":false,"sortable":false,"order":"asc","visible":true,"switchable":true,
"cardVisible":true,"searchable":true,"searchFormatter":true,"escape":false,"colspanIndex":0,
"fieldIndex":0,"field":0},
{"widthUnit":"px","radio":false,"checkbox":false,"checkboxEnabled":true,"clickToSelect":true,
"showSelectTitle":false,"sortable":false,
"order":"asc","visible":true,"switchable":true,"cardVisible":true,"searchable":true,
"searchFormatter":true,"escape":false,"field":"Id",
"title":"ID","colspanIndex":1,"fieldIndex":1
}]
<!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 getVisibleColumns在线例子</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="getVisCols()">获取显示的列</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,
});
function col(icase)
{
if(icase===1)
{
$('#table').bootstrapTable('hideColumn','clog');
}
if(icase===2)
{
$('#table').bootstrapTable('showColumn','clog');
}
}
function getVisCols()
{
var cols= $('#table').bootstrapTable('getVisibleColumns');
alert(JSON.stringify(cols));
}
</script>
</body>
</html>