bootstrap table resetView刷新表格视图如宽度高度,bootstrap table本身不提供设置表格的width属性,只能设置某列的宽度,如果表格的父容器大小发生了变化(如缩小放大了窗口) 这时就可以用resetView方法刷新表格视图并会触发onResetView事件。
参数名称 | 参数说明 |
height | 表格的新高度 |
//初始化
$('#table').bootstrapTable({
toolbar:"#toolbar",
data:data,
columns: columns,
});
//刷新视图
$('#table').bootstrapTable('resetView');
//刷新高度
$('#table').bootstrapTable('resetView',{height:200});
<!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 resetView在线例子</title>
<style>
.table-demo {
width: 80%;
margin: 30px auto 0px auto;
}
.titles {
float: right;
clear: both;
}
</style>
</head>
<body>
<div id="toolbar">
<button onclick="reset()">刷新视图</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: 10000,
catalog: 'D-101',
}, {
Id: 10001,
catalog: 'D-102',
}, {
Id: 10003,
catalog: 'D-103',
} ];
$('#table').bootstrapTable({
toolbar:"#toolbar",
data:data,
columns: columns,
onResetView:function(){
alert("你刷新了视图");
}
});
function reset()
{
$(".table-demo").css({width:"100%"});
$('#table').bootstrapTable('resetView');
}
</script>
</body>
</html>