Bootsrap Table表格分页

一 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,对移动应用提供了非常好的支持...

二 配置文件

<script src="../js/jquery.1.11.3.min.js"></script>
<script src="../js/bootstrap.js"></script>
<script src="../js/bootstrap-table.js"></script>
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<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>标签内添加内容。

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

  JS

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

   function getAccountTab() {
        $("#accountTable").bootstrapTable({
            method : ‘get‘,
            url : "../rest/api/account/query",
            pagination : true,
            pageList : [5, 8 ],
            search : false,
            showColumns : false,
            sidePagination : "server", //服务端请求
            queryParams : ‘queryParams‘,
            pageSize : 8,
            pageNumber : 1,
            clickToSelect : true,
            singleSelect: true,
            paginationFirstText : "第一页",
            paginationPreText : "上一页",
            paginationNextText : "下一页",
            paginationLastText : "最后一页",
            onLoadSuccess : function(data) {

            },
            onLoadError : function(data) {
            },
            onCheck: function (row) {

               },
               onCheckAll: function(rows){

               },
               onCheckSome: function(rows){

               },
               onUncheck:function(row){

               },
               onUncheckAll:function(){
                   delArray = new Array();
               }

        });
    }
//设置传入参数
    function queryParams(param) {
        return {
            limit : param.limit,
            offset : param.offset,
            name : $(‘#accountName‘).val(),
            mobile : $(‘#accountMobile‘).val(),
            email : $(‘#accountEmail‘).val(),
            organize : $(‘#accountOrganize‘).val(),
            type : $(‘#accountType option:selected‘).val(),
            tagId: $(‘#user_tag option:selected‘).val()
        };
    }

  后端

    @GET
    @Path("/query")
    @Produces(MediaType.APPLICATION_JSON)
    public String queryAccount(@QueryParam("limit") final int limit,
            @QueryParam("offset") final int offset,
            @QueryParam("name") final String name,
            @QueryParam("mobile") final String mobile,
            @QueryParam("email") final String email,
            @QueryParam("organize") final String organize,
            @QueryParam("order") final String order,
            @QueryParam("type") final int type,
            @QueryParam("tagId") final String tagId) {
        final String accountUid = (String) request.getSession().getAttribute(
                ACCOUNTUID);
        final BasePageResponse response = this.accountService
                .findPageBySelector(offset, limit, type, name, email, 0,
                        mobile, accountUid, tagId);
        final List<AccountManagerData> accs = BeanConvertUtil
                .getAccountBeans(response);
        final JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.registerJsonValueProcessor(Date.class,
                new JsonDateValueProcessor("yyyy-MM-dd HH:mm:ss"));
        final JSONArray array = JSONArray.fromObject(accs, jsonConfig);
        final JSONObject jsonObj = new JSONObject();
        jsonObj.put("rows", array.toString());
        jsonObj.put("total", response.getTotalCount());
        return jsonObj.toString();
    }

  采用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/

  

时间: 2024-08-01 04:11:05

Bootsrap Table表格分页的相关文章

layer学习笔记之table表格引入数据实现分页

LayUI是一款免费,开源,轻量级的前端cms框架,适用于企业后端,能快速上手开发,集成了常用的组件,还有完善的文档和社区. 最近一直在学习使用layer的layui框架技术,这个主要表现在于弹出层的使用,但是layer页面效果使用也是非常好用的. 之前写一个一个关于数据的table表格显示 并带有分页功能,实现过程遇到了很多问题,现抽空总结一下. 使用之前请先详细阅读layer的文档:http://www.layui.com/doc/modules/layer.html 首先下载最新版的lay

JS表格分页组件:fupage的设计思路和具体用法(未来考虑开源,争取在2015年)

一.背景         之前在秒针工作的时候,某js高级工程师写了很多自己的组件,其中一套是分页组件,叫做st-grid.不过在我看来,bug太多,我经常给他反馈bug,我也不清楚为啥别人没有发现.    回到武汉工作后,我自己利用业余实践完善自己的官网,从前端到后端,都是自己一个人亲自搞定.    第1个分页的需求是,文章下方的评论,异步加载.第2个需求是,表格管理,比如后台管理系统,经常需要列出user.log等表的记录.   二.实例 <table class="table tab

实现表格分页

由于工作需要,经常在开发中需要实现表格分页这种特效,目的的为提升用户体验,减少大数据渲染数量. 分页的分两种,一种是要和服务器交互,另一种是一次性拿到所有数据,在本地做分页处理.本次主要谈论第二种. 分页原理很简单,无非就是数组切片. 最关键是这两句: var startRow = (currentPage - 1) * pageSize;  //currentPage 为当前页,pageSize为每页显示的数据量var endRow = currentPage * pageSize -1: 比

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

BootPage组件简介 其实也不是啥高大上的组件了,相反确实一个简单的表格分页组件而已,主要是自己最近项目中需要一个表格分页组件,而Vue官方组件库里分页组件都功能太强大或者没有适合我的,所以就自己写了一个凑合着用,或许有人和我一样需要这样一个简单的分页组件来实现简单的分页功能,我便在这里分享一下,大家自觉填坑咯. 如需高大上的组件,可以移步Vue官方组件库:https://github.com/vuejs/awesome-vue#libraries--plugins BootPage是一款支

Vue.js的表格分页组件

转自:http://www.cnblogs.com/Leo_wl/p/5522299.html 有一段时间没更新文章了,主要是因为自己一直在忙着学习新的东西而忘记分享了,实在惭愧. 这不,大半夜发文更一篇文章,分享一个自己编写的一个Vue的小组件,名叫BootPage. 不了解Vue.js的童鞋可以移步我的上一篇文章<浅谈Vue.js>了解一下. BootPage组件简介 其实也不是啥高大上的组件了,相反确实一个简单的表格分页组件而已,主要是自己最近项目中需要一个表格分页组件,而Vue官方组件

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

table表格组件 表格的渲染组件,demo请点击http://lovewebgames.com/jsmodule/table.html,git源码请点击https://github.com/tianxiangbing/table 如上图所示,功能基本包括常用表格中遇到的分页.搜索.删除.AJAX操作.由于是用的HANDLEBARS渲染的,所以样式可能很好的控制,要加新的功能也较容易. 调用例子 html <div class="form"> 名称: <input t

基于jquery的无刷新表格分页

html结构 <table id="cs_table" class="datatable"></table> css样式     html,body{margin: 0;padding:0}         a:focus {outline: none;}             /* 通用表格显示 */         table, th, td {font: 12px Arial,Helvetica,sans-serif,'宋体';mar

关于element 框架中table表格选中并切换下一页之前选中数据消失的问题

问题描述: 在实际项目中使用element框架的table表格时,发现当前页选中了数据,点击切换下一页时,再选中数据,发现上一页选中的数据消失了.(目的是:要把用户选择的所有数据显示到页面上) 代码如下: <!-- html 代码 --> <table :data="tableData" @selection-change="handleSelectionChange" ref="multipleTable" :row-key=

学习10 table表格制作标签

<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>认识table表格标签</title> <style type="text/css"> table tr td,th{border:1px solid