欧美国产另类久热|951超碰伊人久久|伊人影视久久久久|色婷婷亚洲小电影|色东京热69XX|婷婷玖玖深爱网|加勒比东京热网站|无码A级毛片在线观看|一级a毛一级a看|中文字幕人妻欧美

BootStrap中的table實現(xiàn)數(shù)據(jù)填充與分頁應用小結
來源:易賢網(wǎng) 閱讀:3579 次 日期:2016-06-20 17:04:29
溫馨提示:易賢網(wǎng)小編為您整理了“BootStrap中的table實現(xiàn)數(shù)據(jù)填充與分頁應用小結”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了BootStrap中的table實現(xiàn)數(shù)據(jù)填充與分頁功能的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

BootStrap table 是一個輕量級的table插件,使用AJAX獲取JSON格式的數(shù)據(jù),其分頁和數(shù)據(jù)填充很方便,支持國際化。最近后臺使用此插件做了一個表格應用,做個總結。

1.使用方法

可以通過又拍云提供的CDN獲取js插件,樣式表和國際化插件,或者直接去官網(wǎng)下載。將下面的js插件和樣式放到html head 頭里即可使用。

//樣式

<link rel="stylesheet"/> 

<script src="http://cdn.bootcss.com/bootstrap-table/1.9.1/bootstrap-table.min.js"></script>

//國際化,表格漢化

<script src="http://cdn.bootcss.com/bootstrap-table/1.9.1/locale/bootstrap-table-zh-CN.min.js"></script>

2.table 數(shù)據(jù)填充

BootStrap table獲取數(shù)據(jù)有兩種方式,一是通過table 的data-url屬性指定數(shù)據(jù)源,而是通過JavaScript初始化表格時指定url來獲取數(shù)據(jù),如下示例。

<table data-toggle="table" data-url="data.json">

<thead>

... 

</thead>

</table>

$('#table').bootstrapTable({

url: 'data.json'

});

第二種方式交第一種而言在處理復雜數(shù)據(jù)時更為靈活,一般使用第二種方式來進行table數(shù)據(jù)填充。

var $table = $('#table');

$table.bootstrapTable({

url: "duoBaoActivityList", 

dataType: "json",

pagination: true, //分頁

singleSelect: false,

data-locale:"zh-US" , //表格漢化

search: true, //顯示搜索框

sidePagination: "server", //服務端處理分頁

columns: [

{

title: '活動名稱',

field: 'name',

align: 'center',

valign: 'middle'

}, 

{

title: '狀態(tài)',

field: 'status',

align: 'center',

valign: 'middle',

}, 

{

title: '參與人數(shù)',

field: 'participationCounts',

align: 'center'

},

{

title: '總?cè)藬?shù)',

field: 'totalCounts',

align: 'center'

},

{

title: '開始時間',

field: 'startTime',

align: 'center',

},

{

title: '操作',

field: 'id',

align: 'center',

formatter:function(value,row,index){ 

var e = '<a href="#" mce_href="#" onclick="edit(\''+ row.id + '\')">編輯</a> '; 

var d = '<a href="#" mce_href="#" onclick="del(\''+ row.id +'\')">刪除</a> '; 

return e+d; 

}

]

});

field字段必須與服務器端返回的字段對應才會顯示出數(shù)據(jù)。

3.分頁與搜索

分頁時BootStrap table 向后端傳遞兩個分頁字段:limit, offset ,前者表示每頁的個數(shù),默認為10個,后者表示分頁時數(shù)據(jù)的偏移量。

而搜索時則向后端傳遞的是search字段,表示具體的搜索內(nèi)容。

服務器端返回的數(shù)據(jù)中還要包括page(頁數(shù)),total(數(shù)據(jù)總量)兩個字段,前端要根據(jù)這兩個字段分頁。

最終具體顯示效果如下圖所示:

名單

以上所述是小編給大家介紹的BootStrap中的table實現(xiàn)數(shù)據(jù)填充與分頁應用小結,希望對大家有所幫助

更多信息請查看網(wǎng)絡編程
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權所有:易賢網(wǎng)