一 bootsrap简介

  Bootstrap,来自 Twitter,是目前很受欢迎的前端框架。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷。

  它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架。Bootstrap提供了优雅的HTML和CSS规范,它即是由动态CSS语言Less写成。Bootstrap一经推出后颇受欢迎,一直是GitHub上的热门开源项目,包括NASA的MSNBC(微软全国广播公司)的Breaking News都使用了该项目。

  简介不介绍过多,相信用过的人都知道boostrap的好处。多浏览器兼容性、页面美观、提供一整套的样式解决方案、基于H5+CSS3,对移动应用提供了非常好的支持...

二 配置文件

  1. <script src="../js/jquery.1.11.3.min.js"></script>
  2. <script src="../js/bootstrap.js"></script>
  3. <script src="../js/bootstrap-table.js"></script>
  4. <link rel="stylesheet" href="../css/bootstrap.min.css" />
  5. <link rel="stylesheet" href="../css/bootstrap-table.css" />

  boostrap基于jquery开发而成,需要在head中最先引入jquery,再进行其他boostrap的js包的引入。在bootsrap3以后,支持模块化导入包,针对自己使用的功能,导入必要的js包,可以有效的减少页面的资源加载量。

三 Boostrap Table配置

  html

  Boostrap通过解析服务端返回的json对象,与table的data-field进行比对,如果名字相同,则取对应的数据进行展现。

  可以通过data-formatter属性指定的js方法对服务端返回的数据进行相应的格式化,此例中使用了boostrap的图标,例如:<span class="glyphicon glyphicon-credit-card"></span>,不允许在boostrap图标的<span>标签内添加内容。

  1. <div class="table-responsive tableDIV">
  2. <table class="table table-striped table-no-bordered table-hover"
  3. id="accountTable" data-toggle="accountTable" data-height="400">
  4. <thead>
  5. <tr>
  6. <th data-field="name" data-formatter="accFormatterName"><span class="glyphicon glyphicon-user"></span>&nbsp;企业名称/姓名</th>
  7. <th data-field="mobile" ><span class="glyphicon glyphicon-phone"></span>&nbsp;手机号</th>
  8. <!-- <th data-field="email" ><span class="glyphicon glyphicon-envelope"></span>&nbsp;邮箱</th> -->
  9. <th data-field="code" data-formatter="FormatterNoOrCode"> <span class="glyphicon glyphicon-credit-card"></span>&nbsp;身份证/组织机构代码证</th>
  10. <th data-field="company" data-formatter="FormatterOrgan" ><span class="glyphicon glyphicon-home" ></span>&nbsp;所属公司</th>
  11. <th data-field="createDate" ><span class="glyphicon glyphicon-calendar"></span>&nbsp;导入日期</th>
  12. <th data-field="tagName" ><span class="glyphicon glyphicon-list"></span>&nbsp;用户组</th>
  13. <th data-field="status" data-formatter="FormatterStatus"><span class="glyphicon glyphicon-th-large"></span>&nbsp;实名状态</th>
  14. <th data-field="" data-formatter="FormatterOperate" class="col-md-2"><span class="glyphicon glyphicon-briefcase"></span>&nbsp;操作</th>
  15. <th data-field="accountUid" class="hidden"></th>
  16. <th data-field="tagrefIds" class="hidden"></th>
  17. <th data-field="tagId" class="hidden"></th>
  18. </tr>
  19. </thead>
  20. </table>
  21. </div>

  JS

  服务端分页需要指定sidePagination 值为true, 同时可以指定对应的查询参数,内置的分页查询参数包括offset、limit等。

  1.    function getAccountTab() {
  2. $("#accountTable").bootstrapTable({
  3. method : 'get',
  4. url : "../rest/api/account/query",
  5. pagination : true,
  6. pageList : [5, 8 ],
  7. search : false,
  8. showColumns : false,
  9. sidePagination : "server", //服务端请求
  10. queryParams : 'queryParams',
  11. pageSize : 8,
  12. pageNumber : 1,
  13. clickToSelect : true,
  14. singleSelect: true,
  15. paginationFirstText : "第一页",
  16. paginationPreText : "上一页",
  17. paginationNextText : "下一页",
  18. paginationLastText : "最后一页",
  19. onLoadSuccess : function(data) {
  20.  
  21. },
  22. onLoadError : function(data) {
  23. },
  24. onCheck: function (row) {
  25.  
  26. },
  27. onCheckAll: function(rows){
  28.  
  29. },
  30. onCheckSome: function(rows){
  31.  
  32. },
  33. onUncheck:function(row){
  34.  
  35. },
  36. onUncheckAll:function(){
  37. delArray = new Array();
  38. }
  39.  
  40. });
  41. }
  1. //设置传入参数
  2. function queryParams(param) {
  3. return {
  4. limit : param.limit,
  5. offset : param.offset,
  6. name : $('#accountName').val(),
  7. mobile : $('#accountMobile').val(),
  8. email : $('#accountEmail').val(),
  9. organize : $('#accountOrganize').val(),
  10. type : $('#accountType option:selected').val(),
  11. tagId: $('#user_tag option:selected').val()
  12. };
  13. }

  后端

  1. @GET
  2. @Path("/query")
  3. @Produces(MediaType.APPLICATION_JSON)
  4. public String queryAccount(@QueryParam("limit") final int limit,
  5. @QueryParam("offset") final int offset,
  6. @QueryParam("name") final String name,
  7. @QueryParam("mobile") final String mobile,
  8. @QueryParam("email") final String email,
  9. @QueryParam("organize") final String organize,
  10. @QueryParam("order") final String order,
  11. @QueryParam("type") final int type,
  12. @QueryParam("tagId") final String tagId) {
  13. final String accountUid = (String) request.getSession().getAttribute(
  14. ACCOUNTUID);
  15. final BasePageResponse response = this.accountService
  16. .findPageBySelector(offset, limit, type, name, email, 0,
  17. mobile, accountUid, tagId);
  18. final List<AccountManagerData> accs = BeanConvertUtil
  19. .getAccountBeans(response);
  20. final JsonConfig jsonConfig = new JsonConfig();
  21. jsonConfig.registerJsonValueProcessor(Date.class,
  22. new JsonDateValueProcessor("yyyy-MM-dd HH:mm:ss"));
  23. final JSONArray array = JSONArray.fromObject(accs, jsonConfig);
  24. final JSONObject jsonObj = new JSONObject();
  25. jsonObj.put("rows", array.toString());
  26. jsonObj.put("total", response.getTotalCount());
  27. return jsonObj.toString();
  28. }

  采用jersey进行数据接收以及业务处理返回相应数据,使用struts2或者springMVC也同样可以,只需要按照boostrap的要求,对返回的json对象中包含rows、total这两项数据。

  对应实现的效果

  

四 资料下载

  Boostrap-table下载,包括table js以及相对应的boostrap-table的API,以及对应的部分示例。

  http://bootstrap-table.wenzhixin.net.cn/examples/

  Boostrap中文网官网、API

  http://www.bootcss.com/

  希望大家相互指正,有需要共同讨论!

  

Bootsrap Table表格分页的更多相关文章

  1. MySQL+Service+Servlet+Jsp实现Table表格分页展示数据

    下面以一个示例讲解如何使用MySQL+Service+Servlet+Jsp实现Table表格分页展示数据: eg:请假管理系统 要求如下: 一.打开首页页面, 访问查询请假记录的 servlet , ...

  2. bootstrap table + spring + springmvc + mybatis 实现从前端到后端的表格分页

    1.使用准备 前台需要的资源文件,主要有Bootstrap3相关css.js以及bootstrap Table相关css.js: <-- 样式 --> <link rel=" ...

  3. 基于Vue.js的表格分页组件

    有一段时间没更新文章了,主要是因为自己一直在忙着学习新的东西而忘记分享了,实在惭愧. 这不,大半夜发文更一篇文章,分享一个自己编写的一个Vue的小组件,名叫BootPage. 不了解Vue.js的童鞋 ...

  4. [js开源组件开发]table表格组件

    table表格组件 表格的渲染组件,demo请点击http://lovewebgames.com/jsmodule/table.html,git源码请点击https://github.com/tian ...

  5. Vue.js的表格分页组件

    转自:http://www.cnblogs.com/Leo_wl/p/5522299.html 有一段时间没更新文章了,主要是因为自己一直在忙着学习新的东西而忘记分享了,实在惭愧. 这不,大半夜发文更 ...

  6. Angular.js+Bootstrap实现表格分页

    最近一直学习Angular.js,在学习过程中也练习了很多的Demo,这里先贴一下表格+分页. 先上图看看最终结果: 不得不说Angular.js代码风格很受人欢迎,几十行代码清晰简洁的实现了上面的功 ...

  7. 【转】基于jquery的无刷新表格分页

    效果图 css样式 <style> html,body{margin: 0;padding:0} a:focus {outline: none;} /* 通用表格显示 */ table, ...

  8. ASP.NET MVC 之表格分页

    简单效果图:(框架:MVC+NHibernate) 要点: (1)首先建立表格分页Model(GridModel.cs) (2)然后建立数据展示页(PageCloth.cshtml) (3)再建分页版 ...

  9. layui table 表格模板按钮实例

    这是个是全部的jsp 页面: <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8& ...

随机推荐

  1. Hexo下Next主题配置与优化

    使用Next主题 在这里Downloads Next主题代码 将下载的代码放在myBlog/theme/next目录下 设置站点myBlog/_config.yml的theme字段值为next 生成新 ...

  2. 使用穷人版profiler定位调试MySQL

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 周末闲得蛋疼,来英飞特做人工空气净化器.开了电脑后,习惯性得点击xshell按钮,进入InnoSQL稳定性测 ...

  3. JavaScript 测试和捕捉(try与catch)

    JavaScript 测试和捕捉 try 语句允许我们定义在执行时进行错误测试的代码块. catch 语句允许我们定义当 try 代码块发生错误时,所执行的代码块. JavaScript 语句 try ...

  4. 转场动画CALayer (Transition)

    1.将对应UI控件的层调用以下接口即可 1.1 .h文件 // // 文 件 名:CALayer+Transition.h // // 版权所有:Copyright © 2018年 leLight. ...

  5. day03-Linux操作系统目录结构

    一. Linux系统目录表示        ‘/’表示根目录:                                                            ‘.’表示当前目录 ...

  6. nginx 简单教程

    使用 nginx 的使用比较简单,就是几条命令. 常用到的命令如下: nginx -s stop 快速关闭Nginx,可能不保存相关信息,并迅速终止web服务. nginx -s quit 平稳关闭N ...

  7. 「BZOJ1010」[HNOI2008] 玩具装箱toy(斜率优化)

    P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为 1⋯N1\cdots N1⋯N ...

  8. P4172 [WC2006]水管局长 LCT维护最小生成树

    \(\color{#0066ff}{ 题目描述 }\) SC 省 MY 市有着庞大的地下水管网络,嘟嘟是 MY 市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的 ...

  9. CF708B Recover the String 构造

    For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 an ...

  10. linux下将当前目录下的文件名存到一个文本文件里

    如果只是想得到当前目录下(不包括子目录)的相关文件时:ls -l | grep  ".gz$" > 1.txt 如果想得到当前目录下,包括子目录中的相关文件时,应该用find ...