欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

bootstrap table列和表頭對(duì)不齊的解決方法

 更新時(shí)間:2019年07月19日 08:42:58   作者:奔跑的蝸牛  
這篇文章主要為大家詳細(xì)介紹了bootstrap table列和表頭對(duì)不齊的解決方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

我們?cè)谑褂胋ootstraptable做表格展示時(shí),有時(shí)需要固定表格的高度當(dāng)數(shù)據(jù)超出高度會(huì)出現(xiàn)滾動(dòng)條,這時(shí)有可能出現(xiàn)表頭列和數(shù)據(jù)列對(duì)不齊。出現(xiàn)這個(gè)問題的原因是數(shù)據(jù)列出現(xiàn)了滾動(dòng)條占了寬度,造成表頭 數(shù)據(jù) 的div寬度不一樣。

通過Chrome瀏覽器 f12,看到樣式為 .fixed-table-header  .fixed-table-body .fixed-table-footer的3個(gè)div容器寬度不一樣, .fixed-table-header  .fixed-table-footer這兩個(gè)div沒有滾動(dòng)條。

解決方法:

bootstraptable在渲染完列表時(shí)會(huì)執(zhí)行onPostBody事件,代碼如下。

$('#dataGrid').bootstrapTable({ 
 method: 'post', 
 url: 'http://www.itxst.com/?ajax', 
 dataType: "json", 
 striped: true, //隔行變色 
 pagination: true, //底部顯示分頁碼
 pageSize: 30, //每頁顯示行數(shù)
 pageNumber: 1, //頁碼
 pageList: [30, 50, 100, 200, 500], //每頁顯示數(shù)量選擇器
 idField: "objectId", //主鍵字段 
 showColumns: true, //顯示隱藏列 
 showRefresh: true, //刷新按鈕 
 singleSelect: true, 
 search: false, 
 clickToSelect: true, 
 sidePagination: "server", 
 queryParams: queryParams, 
 queryParamsType: "limit", 
 toolbar: "#toolbar", //設(shè)置工具欄的Id 
 columns: column, //要顯示的列
 silent: true, //刷新事件必須設(shè)置 
 formatLoadingMessage: function () { 
 return "it小書童正在加載中..."; 
 }, 
 formatNoMatches: function () { 
 return '未查詢到結(jié)果'; 
 }, 
 onLoadError: function (data) { 
 
 }, 
 onClickRow: function (row) { 
 window.location.href = "/detail?id=" + row.objectId; 
 }, 
 onPostBody:function()
 {
 //重點(diǎn)就在這里,獲取渲染后的數(shù)據(jù)列td的寬度賦值給對(duì)應(yīng)頭部的th,這樣就表頭和列就對(duì)齊了
 var header=$(".fixed-table-header table thead tr th");
 var body=$(".fixed-table-header table tbody tr td");
 var footer=$(".fixed-table-header table tr td");
 body.each(function(){
 header.width((this).width());
 footer.width((this).width());
 });
 }
});

如果大家還想深入學(xué)習(xí),可以點(diǎn)擊這里進(jìn)行學(xué)習(xí),再為大家附3個(gè)精彩的專題:

Bootstrap學(xué)習(xí)教程

Bootstrap實(shí)戰(zhàn)教程

Bootstrap插件使用教程

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論