bootstrap table onPageChange分页事件,当用户点击下一页上一页或页码时的回调事件,返回number, size参数。
分页时的事件,返回参数如下。
参数名称 | 说明 |
number | 当前第几页 |
size | 每页显示多少行数据 |
$('#table').bootstrapTable({
columns: columns, //列对象
data: data, //要显示的数据对象
onPageChange: function(number, size) {
alert(JSON.stringify(number));
}
});
$('#table').on('page-change.bs.table', function (e,number, size) {
alert(JSON.stringify(number));
});
<!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 onPageChange例子</title>
<style>
.table-demo {
width: 80%;
margin: 30px auto 0px auto;
}
.fixed-table-header {
border-right: solid 1px #ddd;
border-top: solid 1px #ddd;
}
.fixed-table-header table {
border-top: solid 0px #ddd !important;
margin-top:-1px;
}
</style>
</head>
<body >
<div class="table-demo">
<table id="table"></table>
</div>
<script>
//设置需要显示的列
var columns = [{
field: 'Id',
title: '编号'
}, {
field: 'ProductName',
title: '名称'
}, {
field: 'StockNum',
title: '库存'
}];
//bootstrap table初始化数据
$('#table').bootstrapTable({
columns: columns,
data: getData(),
classes: "table table-bordered table-striped table-sm table-dark", //设置表格样式
height:400,
//******前端分页设置****
pagination:true,
pageNumber:2,
pageSize:10,
pageList:"[10, 20, 50, 200]",
paginationHAlign:"left",
paginationDetailHAlign:"right",
//******前端分页设置****
onPageChange:function(number, size)
{
alert(number)
}
});
function getData()
{
var data = [];
for (var i = 0; i < 200; i++)
{
var item = {
Id: i,
ProductName: '苹果',
StockNum: '200'
};
data.push(item);
};
return data;
}
</script>
</body>
</html>