bootstrap 分页

Posted rocky-fang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bootstrap 分页相关的知识,希望对你有一定的参考价值。

1.背景:

  前端页面使用bootstrap分页,同时与搜索条件联动;

 

2. jsp页面由服务端返回后, 异步请求动态创建表格, 分页的数据由服务端第一次返回后初始化, 以后每次异步请求再更新。

jsp代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
   <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

<!DOCTYPE html>
<html lang="en" class="no-ie" style="overflow:hidden">
<head>
<!-- Meta-->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<title>Apollo - 签入记录</title>
<link rel="stylesheet" href="../app/css/bootstrap.css">
<link rel="stylesheet" href="../vendor/fontawesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../vendor/animo/animate+animo.css">
<link rel="stylesheet" href="../vendor/datetimepicker/css/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="../vendor/datatable/extensions/datatable-bootstrap/css/dataTables.bootstrap.css">
<link rel="stylesheet" href="../vendor/datatable/extensions/ColVis/css/dataTables.colVis.css">
<link rel="stylesheet" href="../app/css/app.css">
<link rel="stylesheet" href="../app/css/beadmin-theme-b3.css">
<link rel="stylesheet" href="../app/css/page.css">
<link rel="stylesheet" href="../vendor/sweetalert/lib/sweet-alert.css" />
<script src="../vendor/modernizr/modernizr.js" type="application/javascript"></script>
<script src="../vendor/fastclick/fastclick.js" type="application/javascript"></script>

<script>
    var basePath = "<%=basePath%>";
    var pageNo = ${pageNo};
    var totalCount = ${totalCount};
    var pageSize = ${pageSize};
    var startNum = ${startNum};
    var stopNum = ${stopNum};
</script>
</head>

<body style="overflow:hidden">
<!-- START Main wrapper-->
<div class="wrapper">   
  <!-- START Main section-->
  <section> 
    <!-- START Page content-->
    <div class="content-wrapper" style="margin-left:-250px;margin-top:-40px; "> 
      <h3>签入记录
      <div style="float:right; margin-top:5px;" class="form-group">
                  <button type="button" id="createBiztype"  class="btn btn-labeled btn-info"> <span class="btn-label"><i class="fa fa-plus"></i> </span>新建</button>
                </div>
      </h3>
      <!-- START panel--> 
      <!-- START DATATABLE 3-->
      <div class="row">
        <div class="col-lg-12">
          <div class="panel panel-default">
            <div class="panel-heading" style="border-bottom:1px solid #eee;">
               <form class="form-inline" id="" method="post" action="<%=path %>/page">

                <div class="form-group">
                                <b>终端ID:&nbsp;</b>
                                <input type="text" class="form-control mb-lg" id="terminalid" name="terminalid" value=‘‘>
                            </div>
                <div class="form-group">
                                <b>标志:&nbsp;</b>
                                <input type="text" class="form-control mb-lg" id="flag" name="flag" value=‘‘>
                            </div>
                <div class="form-group"> <a style="margin:-10px 0 0 5px; float:left;" href="javascript:void(0);" class="mb-sm btn btn-primary" type="button" id="searchButton">搜索</a> </div>
                  <input type="hidden" id="pageNo" name="pageNo" value=‘‘>
              </form>
            </div>
            <div class="table-responsive">
              <table class="table table-bordered table-hover dataTable no-footer" id="table-ext-1" >
                <thead>
                  <tr>
                    <th class="th200">标题</th>
                    <th class="th200">节目ID</th>
                    <th class="th800">创建时间</th>
                    <th class="th200">媒体类型</th>
                    <th class="th200">标志</th>
                    <th class="th200">进度</th>
                    <th class="th200">供应商</th>
                    <th class="th200">操作</th>
                  </tr>
                </thead>
                <tbody id="checkinRequest_tbody">
             
                </tbody>
                <tfoot>
                  <tr> </tr>
                </tfoot>
              </table>
            </div>
            <div class="panel-footer">
              <div class="row">
                <div style="line-height:35px;" class="col-lg-2">
                  <div class="input-group pull-left" id="checkinRequest_showlines">  </div>
                </div>
                <div class="col-lg-8"></div>
                  <div class="tcdPageCode"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- END DATATABLE 3--> 
      
    </div>
    <!-- END Page content--> 
  </section>
  <!-- END Main section--> 
</div>
<!-- END Main wrapper--> 

<!-- START modal-->
<div id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" class="modal" >
  <div class="modal-dialog" style="width:400px; margin-top:200px;">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" data-dismiss="modal" aria-hidden="true" class="close" id="cancelAdd" >×</button>
        <h4 id="myModalLabel" class="modal-title">新建签入记录</h4>
      </div>
       <div class="modal-body">
      
            <div class="table-responsive">
            <form>
            <ul class="serinfo">
            <li> 
            <div class="form-group">
                                <b>名称:&nbsp;</b>
                                <input type="text" id="addTypeName" class="form-control mb-lg" maxLength=50>
                            </div>
            </li>
            </ul>
             <ul class="serinfo">
            <li> 
            <div class="form-group">
                                <b>描述:&nbsp;</b>
                                <input type="text" id="addTypeDesc" class="form-control mb-lg" maxLength=100>
                            </div>
            </li>
            </ul>
            </form>
          </div>
        </div>
           <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
        <button type="button" class="btn btn-primary" id="confirmCreate" >确定</button>
            </div>
      </fieldset>
     
      </div>
    </div>
  </div>
  
  
  
  
  <div id="myModaledit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" class="modal" >
  <div class="modal-dialog" style="width:400px; margin-top:200px;">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" data-dismiss="modal" aria-hidden="true" class="close" id="cancelEdit" >×</button>
        <h4 id="myModalLabel" class="modal-title">编辑签入记录</h4>
      </div>
       <div class="modal-body">
      
            <div class="table-responsive">
            <form>
            <ul class="serinfo">
            <li> 
            <div class="form-group">
                                <b>名称:&nbsp;</b>
                                <input type="text" id="editTypeName" class="form-control mb-lg" maxLength=50>
                            </div>
            </li>
            </ul>
             <ul class="serinfo">
            <li> 
            <div class="form-group">
                                <b>描述:&nbsp;</b>
                                <input type="text" id="editTypeDesc" class="form-control mb-lg" maxLength=100>
                            </div>
            </li>
            </ul>
            </form>
          </div>
        </div>
           <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
        <button type="button" class="btn btn-primary" id="confirmEdit" >确定</button>
            </div>
      </fieldset>
     
      </div>
    </div>
  </div>
  
  
</div>
</div>


<!-- END modal--> 

<!-- START Scripts--> 
<!-- Main vendor Scripts--> 
<script src="../vendor/jquery/jquery.min.js"></script> 
<script src="../vendor/sweetalert/lib/sweet-alert.min.js"></script>
<script src="../vendor/bootstrap/js/bootstrap.min.js"></script> 
<script src="../vendor/chosen/chosen.jquery.min.js"></script> 
<script src="../vendor/slider/js/bootstrap-slider.js"></script> 
<script src="../vendor/filestyle/bootstrap-filestyle.min.js"></script> 
<script src="../vendor/animo/animo.min.js"></script> 
<script src="../vendor/moment/min/moment-with-langs.min.js"></script> 
<script src="../vendor/datetimepicker/js/bootstrap-datetimepicker.min.js"></script> 
<script src="../vendor/slimscroll/jquery.slimscroll.min.js"></script> 
<script src="../vendor/store/store+json2.min.js"></script> 
<script src="../vendor/screenfull/screenfull.min.js"></script> 
<script src="../vendor/datatable/media/js/jquery.dataTables.min.js"></script> 
<script src="../vendor/datatable/extensions/datatable-bootstrap/js/dataTables.bootstrap.js"></script> 
<script src="../vendor/datatable/extensions/datatable-bootstrap/js/dataTables.bootstrapPagination.js"></script> 
<script src="../vendor/datatable/extensions/ColVis/js/dataTables.colVis.min.js"></script> 
<script src="../vendor/wizard/js/bwizard.min.js"></script> 
<script src="../vendor/parsley/parsley.min.js"></script> 
<script src="../app/js/app.js"></script>
<script src="../script/commonutil.js"></script>
<script src="../app/js/page.js"></script>
<script src="../script/checkinRequest.js"></script>
<!-- END Scripts-->
</body>
</html>

js代码

$(function(){
    initTable();
    
    $(‘.tcdPageCode‘).extendPagination({
        pageId : pageNo,
        totalCount : totalCount,
        showPage : 5,
        limit : pageSize,
        callback : function(pageNo, limit, totalCount) {
            checkinRequestSearch(pageNo);
        }
    });
    
    $("#searchButton").on(‘click‘,function(){
        checkinRequestSearch(pageNo);
    });
});

function initTable(){
    $.ajax({
        url : basePath + "page/checkinRequest_list.action",
        type : "get",
        dataType : "json",
        success : function(dataMap){
            createTBody(dataMap);
            createTFoot();
        },
        error : function(errorData){
        }
    });
}

function createTBody(dataMap){
    if(dataMap!=null){
        var html = [];
        var checkinRequestList = dataMap.checkinRequestList;
        for(var i=0; i<checkinRequestList.length; i++){
            var checkinRequest = checkinRequestList[i];
            html.push(‘<tr class="gradeX center">‘);
            html.push(‘<td style="text-align:left;">‘+checkinRequest.title+‘</td>‘);
            html.push(‘<td style="text-align:left;">‘+checkinRequest.assetguid+‘</td>‘);
            html.push(‘<td style="text-align:left;">‘+checkinRequest.createtime+‘</td>‘);
            html.push(‘<td style="text-align:left;">‘+checkinRequest.mediatype+‘</td>‘);
            html.push(‘<td style="text-align:left;">‘+checkinRequest.flag+‘</td>‘);
            html.push(‘<td style="text-align:left;">‘+checkinRequest.progress+‘</td>‘);
            html.push(‘<td style="text-align:left;">‘+checkinRequest.provider+‘</td>‘);
            html.push(‘<td><a href="#" class="checkin_view btn btn-default btn-xs">&nbsp;查看&nbsp;</a></td>‘);
            html.push(‘</tr>‘);
        }
        $("#checkinRequest_tbody").empty().html(html.join(‘‘));
    }
}

function createTFoot(dataMap){
        var reloadPagination = false;
        if(dataMap!=null){
            startNum = dataMap.startNum;
            stopNum = dataMap.stopNum;
            reloadPagination = totalCount==dataMap.totalCount?false:true
            totalCount = dataMap.totalCount;
            pageNo = dataMap.pageNo;
            //pageSize = dataMap.pageSize;
        }
        var str = ‘显示 ‘ + startNum + ‘至‘ + stopNum + ‘项 , 共‘ + totalCount +‘ 项。‘;
        $("#checkinRequest_showlines").empty().html(str);
        if(totalCount==‘0‘){
            $(‘.tcdPageCode‘).empty();
        }else if($(‘.tcdPageCode‘).html()==‘‘ || reloadPagination){//
            $(‘.tcdPageCode‘).extendPagination({
                pageId : pageNo,
                totalCount : totalCount,
                showPage : 5,
                limit : pageSize,
                callback : function(pageNo, limit, totalCount) {
                    checkinRequestSearch(pageNo);
                }
            });
        }
}

以上是关于bootstrap 分页的主要内容,如果未能解决你的问题,请参考以下文章

BootStrap实用代码片段(持续总结)

怎么取消bootstrap默认表格的分页

ThinkPHP 怎么结合Bootstrap进行分页

bootstrap 分页

Bootstrap分页

bootstrap分页与翻页