BootStrap中Table分页插件使用详解

分页(Pagination),是一种无序列表,Bootstrap 像处理其他界面元素一样处理分页

bootstrap-table介绍

bootstrap-table 是一个轻量级的table插件,使用AJAX获取JSON格式的数据,其分页和数据填充很方便,支持国际化。

下载地址

https://github.com/wenzhixin/bootstrap-table/archive/1.11.0.zip

使用方式

引入css和js

<!--css样式--> <link href="https://www.jb51.net/css/bootstrap/bootstrap.min.css"> <link href="https://www.jb51.net/css/bootstrap/bootstrap-table.css"> <!--js--> <script src="https://www.jb51.net/js/bootstrap/jquery-1.12.0.min.js" type="text/javascript"></script> <script src="https://www.jb51.net/js/bootstrap/bootstrap.min.js"></script> <script src="https://www.jb51.net/js/bootstrap/bootstrap-table.js"></script> <script src="https://www.jb51.net/js/bootstrap/bootstrap-table-zh-CN.js"></script>

2. table数据填充

bootstrap-table获取数据有两种方式,一是通过table 的data-url属性指定数据源,二是通过JavaScript初始化表格时指定url来获取数据

<table data-toggle="table"> <thead> ... </thead> </table> $(function () { $('#screenTable').bootstrapTable({ url: "/screen/list", dataField: "rows", cache: false, //是否使用缓存,默认为true striped: true, //是否显示行间隔色 pagination: true, //是否显示分页 pageSize: 10, //每页的记录行数 pageNumber: 1, //初始化加载第一页,默认第一页 pageList: [10, 20, 50], //可供选择的每页的行数 search: true, //是否显示表格搜索 showRefresh: true, //是否显示刷新按钮 clickToSelect: true, //是否启用点击选中行 toolbar: "#toolbar_screen", //工具按钮用哪个容器 sidePagination: "server", //分页方式:client客户端分页,server服务端分页 queryParamsType: "limit", //查询参数组织方式 columns: [{ field: "id", title: "ID", align: "center", valign: "middle" }, { field: "name", title: "定制名称", align: "center", valign: "middle", formatter: 'infoFormatter' }, { field: "time", title: "定制时间", align: "center", valign: "middle" }], formatNoMatches: function () { return '无符合条件的记录'; } }); $(window).resize(function () { $('#screenTable').bootstrapTable('resetView'); }); }); function infoFormatter(value, row, index) { return '<a href=https://www.jb51.net/screen/' + row.id + ' target="_blank">' + row.name + '</a>'; }

效果图如下

BootStrap中Table分页插件使用详解

以上所述是小编给大家介绍的BootStrap中Table分页插件使用详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzdpxj.html