Bootstraptable簡(jiǎn)單使用總結(jié)

最近接觸一個(gè)很棒的插件,Bootstrap table沒(méi)做過(guò)前端的表示對(duì)table的印象還只停留在html的table標(biāo)簽?zāi)且惶?,用過(guò)bootstrap table之后不得不說(shuō)真的很實(shí)用。

成都做網(wǎng)站、網(wǎng)站制作的關(guān)注點(diǎn)不是能為您做些什么網(wǎng)站,而是怎么做網(wǎng)站,有沒(méi)有做好網(wǎng)站,給成都創(chuàng)新互聯(lián)一個(gè)展示的機(jī)會(huì)來(lái)證明自己,這并不會(huì)花費(fèi)您太多時(shí)間,或許會(huì)給您帶來(lái)新的靈感和驚喜。面向用戶(hù)友好,注重用戶(hù)體驗(yàn),一切以用戶(hù)為中心。

構(gòu)造方式

1 、HTML

<div class="btn-group hidden-xs"id="exampleTableEventsToolbar" >
 //定義一系列工具欄...
 </div>
<table data-toggle="table"
 data-url="${ctxAdmin}/user/userData?orgId=${orgId}" //table數(shù)據(jù)來(lái)源,json格式
 data-pagination="true" //是否支持分頁(yè)
 data-show-search="true" //是否顯示搜索框功能
 data-show-columns="true" //顯示columns功能按鈕
 data-icon-size="outline" 
 data-mobile-responsive="true"
 data-height="500" 
 id="tablelist"
 data-side-pagination="server" //支持服務(wù)器端分頁(yè),默認(rèn)是client>
 <thead>
 <tr>
 <th data-field="user_id">ID</th>
 <th data-field="username" 
  data-formatter="usernameFormatter" //columns option 參見(jiàn)官網(wǎng)解釋
  data-events="usernameEvents">用戶(hù)名</th>
 <th data-field="real_name">真實(shí)姓名</th>
 <th data-field="tel_num">座機(jī)</th>
 <th data-field="mobile">手機(jī)</th>
 <th data-field="user_type">用戶(hù)類(lèi)型</th>
 <th data-field="operation" 
  data-formatter="actionFormatter"
  data-events="actionEvents">操作</th>
 </tr>
 </thead>
</table>

 2 、 js構(gòu)造:

 (function() {
 $('#tablelist').bootstrapTable({
  url: "${ctxAdmin}/user/userData?orgId=${orgId}",
  search: true, //是否顯示搜索框功能
  pagination: true, //是否分頁(yè)
  showRefresh: true, //是否顯示刷新功能 
  showToggle: true,
  showColumns: true,
  iconSize: 'outline',
  // toolbar: '#exampleTableEventsToolbar', 可以在table上方顯示的一條工具欄,
  icons: {
  refresh: 'glyphicon-repeat',
  toggle: 'glyphicon-list-alt',
  columns: 'glyphicon-list'
  }
 });

 結(jié)合官網(wǎng)上展示的Table options,Column options,Events,Methods可以完成很多功能。上面的data-formatter ,data-events就是Column options中的選項(xiàng) 。

data-formatterdata-events

要實(shí)現(xiàn)如下效果,用上面兩個(gè)option配合使用即可,一個(gè)定義格式,一個(gè)定義點(diǎn)擊的操作。

Bootstrap table簡(jiǎn)單使用總結(jié)

直接上js代碼

 //value: 所在collumn的當(dāng)前顯示值,
 //row:整個(gè)行的數(shù)據(jù) ,對(duì)象化,可通過(guò).獲取
  //表格-操作 - 格式化 
 function actionFormatter(value, row, index) {
  return '<a class="mod" >修改</a> ' + '<a class="delete">刪除</a>';
 }
 //表格 - 操作 - 事件
 window.actionEvents = {
  'click .mod': function(e, value, row, index) {  
    //修改操作
   },
  'click .delete' : function(e, value, row, index) {
    //刪除操作 
   }
  }

服務(wù)器分頁(yè)/客戶(hù)端分頁(yè)的轉(zhuǎn)換,table刷新

bootstrap默認(rèn)是客戶(hù)端分頁(yè) ,可通過(guò)html標(biāo)簽

data-side-pagination:"client"

 或者js中的

sidePagination: 'server' 

指定。注意,這兩種后臺(tái)傳過(guò)來(lái)的json數(shù)據(jù)格式也不一樣
client : 正常的json array格式 [{},{},{}]
server:{“total”:0,”rows”:[]} 其中total表示查詢(xún)的所有數(shù)據(jù)條數(shù),后面的rows是指當(dāng)前頁(yè)面展示的數(shù)據(jù)量。

有事需要根據(jù)情況改變分頁(yè)方式,就要用到Methods中的
‘refreshOptions' //設(shè)置更新時(shí)候的options
‘refresh' //設(shè)置更新時(shí)的url ,query(往后臺(tái)傳參數(shù))

 $("#tablelist").bootstrapTable('refreshOptions', {
  sidePagination: 'client' //改為客戶(hù)端分頁(yè)
    });
 $("#tablelist").bootstrapTable('refresh', {
   url: "${ctxAdmin}/user/getsearchuserinfo", //重設(shè)數(shù)據(jù)來(lái)源
   query: {username: $('#sea-username').val(),realname: $("#sea-realname").val(),mobile: $("#sea-mobile").val()}

  //傳到后臺(tái)的參數(shù)
 });

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

本文題目:Bootstraptable簡(jiǎn)單使用總結(jié)
轉(zhuǎn)載注明:http://muchs.cn/article24/gdecce.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)、微信公眾號(hào)、標(biāo)簽優(yōu)化、動(dòng)態(tài)網(wǎng)站、品牌網(wǎng)站制作網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)