資料網址
百度經驗:HTML表格分頁,table分頁怎么做?
官網(下載鏈接和官方教程) (右上角可選語言)
文檔
以下內容基本摘自官網
用法
1.下載資料
官網下載:
下下來長這樣:
其中src里面是源碼,主要用到bootstrap-table.css & bootstrap-table.js 和local文件夾中對應當地語言的文件,比如中文: bootstrap-table-zh-CN.js
2. 引用js和css
引入 Bootstrap 庫(假如你的項目還沒有使用)和 bootstrap-table.css
到 head 標簽下。
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-table.css">
引入 jQuery 庫,bootstrap 庫(假如你的項目還沒有使用)和 bootstrap-table.js
到 head 標簽下或者在 body 標簽關閉之前(一般建議這么做)。
<script src="jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="bootstrap-table.js"></script>
<-- put your locale files after bootstrap-table.js -->
<script src="bootstrap-table-zh-CN.js"></script>
3. 加入代碼
通過 data 屬性的方式
無需編寫 JavaScript 啟用 bootstrap table,我們對普通的 table 設置 data-toggle="table"
即可。
參數直接寫在html標簽中,具體可控制哪些標簽,詳見文檔
<table data-toggle="table" data-toggle="table"
data-pagination="true" data-side-pagination="client" >
<thead>
<tr>
<th>Item ID</th>
<th>Item Name</th>
<th>Item Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Item 1</td>
<td>$1</td>
</tr>
<tr>
<td>2</td>
<td>Item 2</td>
<td>$2</td>
</tr>
</tbody>
</table>
我們也可以通過設置遠程的 url 如 data-url="data1.json"
來加載數據。
<table data-toggle="table" data-url="data1.json">
<thead>
<tr>
<th data-field="id">Item ID</th>
<th data-field="name">Item Name</th>
<th data-field="price">Item Price</th>
</tr>
</thead>
</table>
通過 JavaScript 的方式
通過表格 id 來啟用 bootstrap table。
參數同樣詳見官方文檔~
<table id="table"></table>
$('#table').bootstrapTable({
columns: [{
field: 'id',
title: 'Item ID'
}, {
field: 'name',
title: 'Item Name'
}, {
field: 'price',
title: 'Item Price'
}],
data: [{
id: 1,
name: 'Item 1',
price: '$1'
}, {
id: 2,
name: 'Item 2',
price: '$2'
}]
});
我們也可以通過設置遠程的 url 如 url: 'data1.json'
來加載數據。
function load_publications(){
var publications_html="";
var name = getURLParameter("name");
$('#publications').bootstrapTable({
url: "personal_information/"+name+"/"+name+"_publications.json",
columns: [{
field: 'id',
title: 'id'
}, {
field: 'content',
title: 'content'
}],
pagination: "true" ,
pageSize:"6",
pageList:[6,10, 25, 50, 100]
});
$('#publications2').bootstrapTable({
url: "personal_information/"+name+"/"+name+"_publications.json",
columns: [{
field: 'id',
title: 'id'
}, {
field: 'content',
title: 'content'
}],
pagination: "true" ,
pageSize:"10",
pageList:[10, 25, 50, 100]
});
}