bootstrap table getOptions 获取配置对象方法,没有参数,返回配置对象,这个对象包含你未手动设置的默认值。
//tableId 表格对象的ID
var options=$("#tableId").bootstrapTable('getOptions');
//获取每页显示多少条数据
var pageSize=options.pageSize;
//获取表格的列对象
var columns=options.columns;
//返回对象格式如下,看不看的懂下面的对象无所谓
{
ajaxOptions: {}
buttonsAlign: "right"
buttonsClass: "secondary"
cache: true
cardView: false
detailView: false
escape: false
showColumns: false
showFooter: false
showFullscreen: false
showHeader: true
showPaginationSwitch: false
showRefresh: false
showToggle: false
sidePagination: "client"
silentSort: true
singleSelect: false
smartDisplay: true
sortOrder: "asc"
sortStable: false
sortable: true
strictSearch: false
theadClasses: ""
toolbar: "#toolbar"
......等等......
}
以下为完整代码
<!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/bootstrap-table-1.14.1/jquery-3.3.1/jquery.js"></script>
<link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
<link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.css" rel="stylesheet" />
<script src="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.js"></script>
<title>bootstrap table getOptions 获取配置对象方法在线例子</title>
<style>
.table-demo {
width: 80%;
margin: 30px auto 0px auto;
}
.titles {
float: right;
clear: both;
}
</style>
</head>
<body>
<div id="toolbar">
<button onclick="getOps()">点击获取配置</button>
</div>
<div class="table-demo">
<table id="table" ></table>
</div>
<script>
//设置需要显示的列
var columns = [
{
checkbox:true
},{
field:"Id",
title: 'ID'
}, {
field: 'XName',
title: 'Name'
} ];
//需要显示的数据
var data = [{
Id: 1000,
XName: 'XL111',
StockNum: '100'
}, {
Id: 1002,
XName: 'XL112',
StockNum: '200'
}, {
Id: 1003,
XName: 'XL113',
StockNum: '200'
}, {
Id: 1004,
XName: 'XL114',
StockNum: '200'
}];
//bootstrap table初始化数据
$('#table').bootstrapTable({
toolbar:"#toolbar",
columns: columns,
data: data
});
function getOps()
{
var ops=$('#table').bootstrapTable('getOptions');
alert(JSON.stringify(ops));
alert("获取每页显示条数:"+ops.pageSize);
}
</script>
</body>
</html>