Bootstrap Table使用方法详解

bootstrap-table使用总结

bootstrap-table是在bootstrap-table的基础上写出来的,专门用于显示数据的表格插件。而bootstrap是来自 Twitter,是目前最受欢迎的前端框架。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的,具有简便灵活,快速前端开发的优势。对与bootstrap在此就不在叙述。本文将着重讲解自己在项目中使用到bootstrap-table的一些理解和如何学习它。

首先交代一下,jquery ,bootstrap ,bootstrap-table 三者之间的关系。bootstrap很多部分代码涉及到了jquery的,也就是说 bootstrap是依赖jquery的,而我们要使用的bootstrap-table则是在bootstrap基础上创造出来的,所以在使用bootstrap-table之前必须引用 jquery 和bootstrap的相关js,css文件。

接着说,bootstrap-table的特点:与jquery-ui,jqgrid等表格显示插件而言,bootstrap-table扁平化,轻量级,对于一些轻量级的数据显示,他是绰绰有余,而对父子表等的支持也很好,最主要的是可以与bootstrap的其他标签无缝组合。

好了,简介的话就说到这,直接上代码和效果图之后,再做进一步的讨论。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <head> <title>bootstrap-table</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta content="" /> <meta content="" /> <script type="text/javascript" src="https://www.jb51.net/article/js/jquery-2.2.1.js"></script> <script type="text/javascript" src="https://www.jb51.net/article/bootstrap/js/bootstrap.min.js"></script> <script type="text/javascript" src="https://www.jb51.net/article/bootstrap-table/bootstrap-table-all.js"></script> <script type="text/javascript" src="https://www.jb51.net/article/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script> <link type="text/css" href="https://www.jb51.net/article/bootstrap/css/bootstrap.min.css" > <link type="text/css" href="https://www.jb51.net/article/bootstrap-table/bootstrap-table.min.css" > </head> <script language="javascript"> </script> <body> <div> <div> <div> <h3>已添加教师账号</h3> </div> <div> <div> <button type="button" > <span aria-hidden="true"></span>修改 </button> <button type="button"> <span aria-hidden="true"></span>删除 </button> </div> <table data-toggle="table" data-url="./data.php" data-method="post" data-query-params="queryParams" data-toolbar="#toolbar" data-pagination="true" data-search="true" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-page-size="5"> <thead> <tr> <th data-field="name">用户账号</th> <th data-field="pwd">用户密码</th> <th data-field="t_name">教师姓名</th> </tr> </thead> </table> </div> </div> </div> </body>

效果图:

Bootstrap Table使用方法详解


好接下来我们 分步骤剖析一下上面的代码的含义。

 1.首先我们需要去下载相应的 jquery bootstrap  bootstrap-table的包,这些网上都有教程,在此不再叙述如何下载。

由上面<head>标签中引用js和css文件名可知我们必须引进这几个文件。

注意bootstrap,下载编译过的压缩包中只有三个文件夹 css ,fonts, js

1. jquery-2.2.1.js  ----  最新的jquery文件

2. bootstrap.min.js --- 最新的bootstrap/js中bootstrap.min.js 压缩文件

3.bootstrap.min.css ---最新的bootstrap/css中bootstrap.min.css 压缩文件

4.bootstrap-table-all.js ---最新bootstrap-table下的js文件

5.bootstrap-table-zh-CN.js ----最新bootstrap-table/locale下的中文初始文件

6.bootstrap-table.min.css ---最新的bootstrap-table下css压缩文件

这六个必须配置,其中bootstrap-table-zh-CN.js是支持中文的js文件,只有加载了这个文件我们的一些表格显示信息才会被设置成中文。

我们来实验一下 将bootstrap-table-zh-CN.js去掉后的显示效果。

Bootstrap Table使用方法详解


当然我们还可以把显示信息设置成其他语言,只要将bootstrap-table-zh-CN.js换成其他语言的js文件即可。bootstrap-table包中都有支持。

我们还可以看看这个文件中的源码,我们看一下,就知道这个文件干了什么了。 

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

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