一、前言
bootstrap-table是非常方便好用的前端表格分頁(yè)插件,使用者只需要提供數(shù)據(jù)源就能實(shí)現(xiàn)非常完美的分頁(yè)效果,其分頁(yè)方式可以分成客戶端分頁(yè)和服務(wù)端分頁(yè),其接收的數(shù)據(jù)源都是json數(shù)據(jù)格式。服務(wù)端分頁(yè)在項(xiàng)目中應(yīng)用得非常的廣泛,但有時(shí)也需要使用客戶端分頁(yè)來(lái)加快分頁(yè)速度,加快分頁(yè)瀏覽效率。本篇博客就不介紹服務(wù)端分頁(yè),只提供bootstrap-table客戶端分頁(yè)的簡(jiǎn)單例子(數(shù)據(jù)源也從前端獲取),供初學(xué)者了解使用。
二、實(shí)例
<title>bootstrap-table表格客戶端分頁(yè)</title>   <link rel="stylesheet" href="./bootstrap/css/bootstrap/bootstrap.css" rel="external nofollow" />  <link rel="stylesheet" href="./bootstrap-table/bootstrap-table.css" rel="external nofollow" />     <script src="./jquery/jquery.min.js"></script>  <script src="./bootstrap/js/bootstrap.js"></script>  <script src="./bootstrap-table/bootstrap-table.js"></script>  <script src="./bootstrap-table/bootstrap-table-export.js"></script>  <script src="./extends/tableExport/jquery.base64.js"></script>  <script src="./extends/tableExport/tableExport.js"></script>  </head>  <body >  <div id="reportTableDiv" >   <table id="reportTable"></table>  </div>  <script type="text/javascript">  //手動(dòng)制造30條數(shù)據(jù)  var datas = [];  for(var i=0;i<30;i++){   datas[i]={"name":"傻逼"+i+"號(hào)","age":"年齡:"+i+"歲","sex":"男"+i}  }    $(function () {   $('#reportTable').bootstrapTable({    method: 'get',    cache: false,    height: 400,    striped: true,    pagination: true,    pageSize: 20,    pageNumber:1,    pageList: [10, 20, 50, 100, 200, 500],    search: true,    showColumns: true,    showRefresh: false,    showExport: false,    exportTypes: ['csv','txt','xml'],    search: true,    clickToSelect: true,    columns:    [     {field:"checked",checkbox:true},     {field:"name",title:"測(cè)試姓名",align:"center",valign:"middle",sortable:"true"},     {field:"age",title:"年齡",align:"center",valign:"middle",sortable:"true"},     {field:"sex",title:"性別",align:"center",valign:"middle",sortable:"true"},    ],    data:datas,   });           });  </script> <div>   </body> </html> 三、總結(jié)
    1. bootstrap-table客戶端分頁(yè)只需要幾個(gè)步驟即可實(shí)現(xiàn):引入bootstrap的js、css;html頁(yè)面添加一個(gè)table標(biāo)簽同時(shí)給id賦值;js添加初始化代碼;
    2.bootstrap-table客戶端分頁(yè)的數(shù)據(jù)源可以是服務(wù)器端傳遞過(guò)來(lái),也可以是前端js獲取,該實(shí)例使用的是前端js的數(shù)據(jù)源,初始化參數(shù)需要添加data,同時(shí)去掉url;
3.本博客的實(shí)例下載路徑
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注