1.效果
2.代码
let pageSize = 10
$(document).on("change", '#selPageSize', () => { // 下拉选择每页数目促发事件
pageSize = $("#selPageSize").val();
init () // 重新获取数据渲染表格
})
function initTable(tableData) {
$('#dt-table').bootstrapTable('destroy').bootstrapTable({
data: tableData,
pageSize : pageSize,//单页记录数
onPageChange(number, size) {
setSelPageSizeDom()
},
});
setSelPageSizeDom ()
function setSelPageSizeDom () {
let strHtml = `<span class="page-list" style="margin-top: 12px">每页显示
<select id="selPageSize" style="border: 1px solid #cccccc; border-radius: 4px; padding: 4px 10px">
<option value="5" ${pageSize == 5 ? 'selected' : ''}>5</option>
<option value="10" ${pageSize == 10 ? 'selected' : ''}>10</option>
<option value="15" ${pageSize == 15 ? 'selected' : ''}>15</option>
<option value="30" ${pageSize == 30 ? 'selected' : ''}>30</option>
<option value="50" ${pageSize == 50 ? 'selected' : ''}>50</option>
</select> 条记录
<span>`
$(".fixed-table-pagination").append(strHtml);
}
}