一、前言
1.使用bootstrap-table表格插件,只要有json数据格式的数据源,即可随心所欲
2.本博客只展示了前端分页实例(PS:该插件两种分页方式:前端分页、服务端分页)
3.废话不多说,实例开始
二、实例demo
1.引入资源部分
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.min.js"></script>
2.html+js
<table id="table"></table>
<script type="text/javascript">
//没有请求,自己写50条数据
var datas = [];
for(var i=0;i<50;i++){
datas[i]={"name":i+"号","age":i+"岁"}
}
$('#table').bootstrapTable({
pagination: true,
pageSize: 20,
pageNumber:1,
sidePagination:'client',
paginationFirstText: "首页",
paginationPreText: "上一页",
paginationNextText: "下一页",
paginationLastText: "末页",
iconSize: 'pager',
columns: [{field:"name",title:"编号",align:"center",valign:"middle",sortable:"true"},
{field:"age",title:"年龄",align:"center",valign:"middle",sortable:"true"}],
data:datas,
});
</script>
三.总结
demo可适用于本地加载数据(即前端获取数据来源后在进行加载),当然,获取到的数据源格式要为json数据格式哦!切忌
好久没系统的引用这个插件了,这次来复习下,demo简单但实用
PS:好紧张好紧张,第一次来分享姿势~~