本文摘自PHP中文网,作者angryTom,侵删。
本篇文章介绍了Bootstrap分页表格插件的使用方法,bootStrap table获取数据有两种方式,一是通过table 的data-url属性指定数据源,二是通过JavaScript初始化表格时指定url来获取数据。
Bootstrap分页表格插件使用教程
找了两个table的插件,一个是bootstrap table ,另一个是bootstrap-paginator
这里只介绍 bootstrap table 插件 使用及简单案例
文档介绍:http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/
推荐视频教程:Bootstrap教程
1. 引入js、css文件
1 2 3 4 5 6 | <link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
<link href="http://cdn.bootcss.com/bootstrap-table/1.11.0/bootstrap-table.min.css">
<script src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap-table/1.11.0/bootstrap-table.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap-table/1.11.0/locale/bootstrap-table-zh-CN.min.js"></script>
|
2.table数据填充
bootStrap table获取数据有两种方式,一是通过table 的data-url属性指定数据源,二是通过JavaScript初始化表格时指定url来获取数据*
注意:使用data-toggle="table"的话,js操作就会失效,反之生效
1 2 3 4 5 6 7 8 9 | <table data-toggle="table">
<thead>
...
</thead>
</table>
$('#table').bootstrapTable({
url: 'data.json'
});
|
3. js获取数据的案例及释义
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <div class="panel panel-default">
<div class="panel-body table-responsive">
<div class="query-div" id="toolbar">
<form class="form-inline" role="form" id="query_form">
<div class="form-group query-form-group">
<label for="status">状态</label>
<select class="form-control" id="with_appr_status"
<option value="">全部</option>
<option value="S1">待处理</option>
<option value="S2">已处理</option>
</select>
</div>
<div class="form-group query-form-group">
<button type="button" class="btn btn-default" id="with_query">查询</button>
</div>
</form>
</div>
<table id="query_results" class="table table-hover">
<thead>
<tr>
<th data-field="code">编号</th>
<th data-field="time">申请时间</th>
<th data-field="status" data-formatter="formatStatus">提现状态</th>
<th data-field="remark">备注</th>
</tr>
</thead>
</table>
</div>
</div>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | loadData();
function loadData(){
$('#query_results').bootstrapTable({
url: '/test',
method: 'post',
contentType: "application/x-www-form-urlencoded",
dataType: "json",
toolbar: '#toolbar',
toolbarAlign: "left",
striped: true,
cache: false,
pagination: true,
sidePagination: "server",
pageNumber: 1,
pageSize: 5,
pageList: [5, 10, 25, 50, 100],
sortOrder: "asc",
search: false,
buttonsAlign: "left",
strictSearch: true,
clickToSelect: true,
uniqueId: "id",
cardView: false,
detailView: false,
queryParamsType: 'limit',
queryParams: queryParams
});
function queryParams(params) {
var params = {
pageNo : Math.ceil(params.offset/params.limit) + 1,
pageSize : params.limit,
"status" : $("#status").val()
};
return params;
}
}
$("#query").bind("click",function(){
$("#query_results").bootstrapTable('destroy');
loadPageData();
});
function formatStatus(value, row, index){
if(value == 'S1'){
return "待处理";
}else{
return "已处理"
}
}
|
以上就是Bootstrap分页表格插件使用教程的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
bootstrap 怎么关闭tab
为什么要使用bootstrap框架
html怎么删除表格的第二行
bootstrap和react的区别是什么?
bootstrap如何使用路径分页标签
bootstrap怎么设置面板大小
bootstrap基本样式介绍
bootstrap和vue的区别
bootstrap双击事件怎么写
bootstrap轮播怎么停止自动轮播
更多相关阅读请进入《bootstrap》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » Bootstrap分页表格插件使用教程