Bootstrap Table使用心得總結(jié)
之前一直在調(diào)研我們的管理后臺(tái)使用的表格控件,查詢到 : http://bootstrap-table.wenzhixin.net.cn的Bootstrap Table 感覺(jué)挺不錯(cuò),但是由于官方的文檔不是怎么的完善,導(dǎo)致自己的網(wǎng)絡(luò)數(shù)據(jù)請(qǐng)求一直沒(méi)有通過(guò)。
今天終于調(diào)試通過(guò),在這里與大家分享一下。
一、相關(guān)的配置文件引入
<!-- jQuery文件。務(wù)必在bootstrap.min.js 之前引入 --> <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script> <link rel="stylesheet" > <script src="http://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <!-- bootstrap table --> <link rel="stylesheet"> <script src="http://cdn.bootcss.com/bootstrap-table/1.11.0/bootstrap-table.min.js"></script> <script src="http://cdn.bootcss.com/bootstrap-table/1.11.0/bootstrap-table-locale-all.js"></script> <script src="http://cdn.bootcss.com/bootstrap-table/1.11.0/extensions/export/bootstrap-table-export.min.js"></script> <!-- bootstrap table 包含excel導(dǎo)出,pdf導(dǎo)出 --> <script src="https://rawgit.com/hhurz/tableExport.jquery.plugin/master/tableExport.js"></script> <script src="http://cdn.bootcss.com/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
注意!!!!! 這里的 tableExport.js并不是 bootcdn上的tableExport,使用的時(shí)候注意看作者,不到會(huì)導(dǎo)致無(wú)法導(dǎo)出excel
二、編寫表頭和工具欄
其實(shí)整個(gè)表頭的編寫非常簡(jiǎn)單,只需要簡(jiǎn)單的幾個(gè)配置就好。
注意,把每一個(gè)bean的屬性書寫在th中
注意綁定工具欄
可以參考如下配置
<!-- 工具欄的按鈕,可以自定義事件 -->
<div id="toolbar" class="btn-group">
<button type="button" class="btn btn-default">
<i class="glyphicon glyphicon-plus"></i>
</button>
<button type="button" class="btn btn-default">
<i class="glyphicon glyphicon-heart"></i>
</button>
<button type="button" class="btn btn-default">
<i class="glyphicon glyphicon-trash"></i>
</button>
</div>
<table id="demo" class="table table-striped table-hover table-bordered"
data-toolbar="#toolbar" // 這里必須綁定工具欄,不然布局會(huì)錯(cuò)亂
data-search="true"
data-show-refresh="true"
data-show-columns="true"
data-show-export="true"
data-export-types="['excel']"
data-export-options='{ // 導(dǎo)出的文件名
"fileName": "products",
"worksheetName": "products"
}'
>
<thead>
<tr>
<th width="3%" data-field="prodId">產(chǎn)品Id</th>
<th width="10%" data-field="nameOfProduct">產(chǎn)品名稱</th>
<th width="4%" data-field="categoryId">產(chǎn)品類別</th>
<th width="5%" data-field="domicileOfCapital">資本類型</th>
<th width="8%" data-field="underwriter">發(fā)行機(jī)構(gòu)</th>
<th width="6%" data-field="managementInstitution">基金公司</th>
<th width="5%" data-field="managementInstitution2">管理機(jī)構(gòu)</th>
<th width="3%" data-field="flag">角標(biāo)</th>
<th width="7%" data-field="beginTime">上線時(shí)間</th>
<th width="7%" data-field="endTime">下線時(shí)間</th>
<th width="4%" data-field="status">發(fā)布狀態(tài)</th>
<th width="4%" data-field="fundRaisingStatus">募集狀態(tài)</th>
<th width="3%" data-field="totalScore">打分</th>
<th width="3%" data-field="modesOfGuaranteeScore">擔(dān)保</th>
<th width="3%" data-field="invsetmentTargetScore">投資</th>
<th width="3%" data-field="underwriterScore">發(fā)行</th>
<th width="3%" data-field="sourceOfPaymentScore">還款</th>
<th width="3%" data-field="issuerDescriptionScore">融資</th>
<th width="10%">操作</th>
</tr>
</thead>
</table>
三、綁定后端邏輯
因?yàn)椋珺ootstrap Table默認(rèn)是使用了form表單的方式提交,其分頁(yè)參數(shù)與查詢參數(shù)都與我們的后端邏輯協(xié)議不一致。(官方就缺少這一部分的文檔)
所以,我們需要更具其協(xié)議做一個(gè)自定義的配置。
$(function() {
$("#demo").bootstrapTable({
url: "http://ydjr.dev.chengyiwm.com/goldman-mgr/listProduct",
sortName: "prodId", //排序列
striped: true, //條紋行
sidePagination: "server", //服務(wù)器分頁(yè)
clickToSelect: true, //選擇行即選擇checkbox
singleSelect: true, //僅允許單選
searchOnEnterKey: true, //ENTER鍵搜索
pagination: true, //啟用分頁(yè)
escape: true, //過(guò)濾危險(xiǎn)字符
queryParams: getParams, //攜帶參數(shù)
method: "post", //請(qǐng)求格式
responseHandler: responseHandler,
});
});
/**
* 默認(rèn)加載時(shí)攜帶參數(shù)
*
* 將自帶的param參數(shù)轉(zhuǎn)化到cy的請(qǐng)求邏輯協(xié)議
*/
function getParams(params) {
var query = $("#searchKey").val();
console.log(JSON.stringify(params));
return {
head: {
userId: "11154",
skey: "6FC19FCE5D8DCF130954D8AE2CADB30A",
platform: "pc",
imei: "",
appVersion: "",
cityId: "",
platformVersion: "",
deviceId: "",
channel: "",
protoVersion: 1,
isPreview: 2
},
body: {
'query': params.search, // 搜索參數(shù)
'start': params.offset, // 分頁(yè)開始位置
'pageSize': params.limit, //每頁(yè)多少條
}
}
}
/**
* 獲取返回的數(shù)據(jù)的時(shí)候做相應(yīng)處理,讓bootstrap table認(rèn)識(shí)我們的返回格式
* @param {Object} res
*/
function responseHandler(res) {
return {
"rows": res.body.listProduct, // 具體每一個(gè)bean的列表
"total": res.body.totalCount // 總共有多少條返回?cái)?shù)據(jù)
}
}
Ok配置完成后給大家看看我們的顯示效果:

如果大家還想深入學(xué)習(xí),可以點(diǎn)擊這里進(jìn)行學(xué)習(xí),再為大家附3個(gè)精彩的專題:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript變速動(dòng)畫函數(shù)封裝添加任意多個(gè)屬性
這篇文章主要介紹了JavaScript變速動(dòng)畫函數(shù)封裝添加任意多個(gè)屬性 ,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04
使用threejs實(shí)現(xiàn)第一人稱視角的移動(dòng)的問(wèn)題(示例代碼)
第一人稱視角的場(chǎng)景巡檢主要需要解決兩個(gè)問(wèn)題,人物在場(chǎng)景中的移動(dòng)和碰撞檢測(cè)。移動(dòng)與碰撞功能是所有三維場(chǎng)景首先需要解決的基本問(wèn)題,今天我們就通過(guò)最基本的threejs來(lái)完成第一人稱視角的場(chǎng)景巡檢功能,感興趣的朋友一起看看吧2022-02-02
JavaScript中const關(guān)鍵字的用法及特性
該文章講解了JavaScript中const關(guān)鍵字的用法以及它的一些特性,該關(guān)鍵字用于創(chuàng)建常量,即一旦賦值之后就不能再修改,但是,使用?const創(chuàng)建的對(duì)象和數(shù)組卻可以被修改,本文通過(guò)講解“賦值”和“變異”之間的重要區(qū)別,詳細(xì)解釋了這一現(xiàn)象,需要的朋友可以參考下2023-05-05
JS+CSS實(shí)現(xiàn)的經(jīng)典圓角下拉菜單效果代碼
這篇文章主要介紹了JS+CSS實(shí)現(xiàn)的經(jīng)典圓角下拉菜單效果代碼,可實(shí)現(xiàn)非常經(jīng)典的圓角下拉菜單效果,涉及JavaScript動(dòng)態(tài)操作頁(yè)面元素css樣式的相關(guān)技巧,需要的朋友可以參考下2015-10-10
cookie丟失問(wèn)題(認(rèn)證失效) Authentication (用戶驗(yàn)證信息)也會(huì)丟失
window.showModalDialog() 后 window.open() 導(dǎo)致cookie丟失問(wèn)題(認(rèn)證失效) Authentication (用戶驗(yàn)證信息)也會(huì)丟失2009-06-06
利用谷歌地圖API獲取點(diǎn)與點(diǎn)的距離的js代碼
下面是一段利用谷歌地圖API獲取點(diǎn)點(diǎn)之間距離的代碼,采用V3版本中的DirectionsService()2012-10-10
關(guān)于IE只能嵌套27層表格的說(shuō)法證明
關(guān)于IE只能嵌套27層表格的說(shuō)法證明...2006-11-11

