您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“Bootstrap中table怎么用”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Bootstrap中table怎么用”這篇文章吧。
構(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ù)來源,json格式 data-pagination="true" //是否支持分頁 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ù)器端分頁,默認(rèn)是client> <thead> <tr> <th data-field="user_id">ID</th> <th data-field="username" data-formatter="usernameFormatter" //columns option 參見官網(wǎng)解釋 data-events="usernameEvents">用戶名</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">用戶類型</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, //是否分頁 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-formatter 和 data-events
要實(shí)現(xiàn)如下效果,用上面兩個(gè)option配合使用即可,一個(gè)定義格式,一個(gè)定義點(diǎn)擊的操作。
直接上js代碼
//value: 所在collumn的當(dāng)前顯示值, //row:整個(gè)行的數(shù)據(jù) ,對象化,可通過.獲取 //表格-操作 - 格式化 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ù)器分頁/客戶端分頁的轉(zhuǎn)換,table刷新
bootstrap默認(rèn)是客戶端分頁 ,可通過html標(biāo)簽
data-side-pagination:"client"
或者js中的
sidePagination: 'server'
指定。注意,這兩種后臺傳過來的json數(shù)據(jù)格式也不一樣
client: 正常的json array格式 [{},{},{}]
server: {“total”:0,”rows”:[]} 其中total表示查詢的所有數(shù)據(jù)條數(shù),后面的rows是指當(dāng)前頁面展示的數(shù)據(jù)量。
有事需要根據(jù)情況改變分頁方式,就要用到Methods中的
‘refreshOptions' //設(shè)置更新時(shí)候的options
‘refresh' //設(shè)置更新時(shí)的 url ,query(往后臺傳參數(shù))
$("#tablelist").bootstrapTable('refreshOptions', { sidePagination: 'client' //改為客戶端分頁 }); $("#tablelist").bootstrapTable('refresh', { url: "${ctxAdmin}/user/getsearchuserinfo", //重設(shè)數(shù)據(jù)來源 query: {username: $('#sea-username').val(),realname: $("#sea-realname").val(),mobile: $("#sea-mobile").val()}//傳到后臺的參數(shù) });
以上是“Bootstrap中table怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。