最近在研究bootstrap table的使用,過程中查詢了許多資料,在給table做點擊下拉詳情時發現網上的資料大部分是基礎應用的資料,只有很少的一部分關於這部分的資料,而且並不完全。這里記錄一下昨天遇到的問題。
在數據綁定上用了$('#table').bootstrapTable({...})的方式,在參數中添加了
detailView:true,
detailFormatter:function(index, row){
var html = [];
$.each(row, function (key, value) {
html.push('<p><b>' + key + ':</b> ' + value + '</p>');
})
}
發現table上確實出現了可操作按鈕
但是當點擊展開按鈕會報錯404無法找到action[],也無法進入detailFormatter定義的方法中,遍尋無果,不得已改用另一種數據綁定的方式
<table id="table" data-mobile-responsive="true"
data-toggle="table" data-toolbar="#toolbar"
data-detail-view="true" data-pagination="true"
data-page-number="1" data-page-size="10" data-page-list="[10,20,30]"
data-click-to-select="true" data-show-columns="true"
data-side-pagination="server"
data-detail-formatter="detailFormatter"
data-url="./showOrderList">
<thead>
<tr>
<th data-field="id">ID</th>
<th data-field="contractNo">貨單合同編號</th>
<th data-field="sendTime" >發貨日期</th>
</tr>
</thead>
</table>
成功進入了detailFormatter定義的方法中
field: 'id',
title: 'ID',
visible: false
}]
background-image:url(../images/up.png);
display: block;
margin-left: 3px;
height: 16px;
width: 16px;
background-repeat: no-repeat;
}
.glyphicon.img-up{
background-image:url(../images/down.png);
display: block;
margin-left: 3px;
height: 16px;
width: 16px;
background-repeat: no-repeat;
background-position: center center;
}
field: 'state1',
title: '操作',
formatter: xlFMT
}
return "<a href='javascript:' class=\"detail-icon\" ><i class=\"glyphicon img-up\"></i></a> ";
}
data-icons | Object | { paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down', paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up', refresh: 'glyphicon-refresh icon-refresh' toggle: 'glyphicon-list-alt icon-list-alt' columns: 'glyphicon-th icon-th' detailOpen: 'glyphicon-plus icon-plus' detailClose: 'glyphicon-minus icon-minus' } |
自定義圖標 |
detailOpen: 'img-up',
detailClose: 'img-down',
refresh: 'glyphicon-refresh icon-refresh',
toggle: 'glyphicon-list-alt icon-list-alt',
columns: 'glyphicon-th icon-th'
},
is subtable | Collapse all rows if the detail view option is set to True. |
$('#table').bootstrapTable("collapseAllRows");
var html = [];
$.each(row, function (key, value) {
if(key=='orderType'){
if(value==1){
html.push('<span>' + '委托代發單' + '</span>');
}
if(value==0){
html.push('<span>' + '貨主自派單 '+ '</span>');
}
}
//html.push('<p><b>' + key + ':</b> ' + value + '</p>');
});
return html.join('');
}
同時說一下,因為展開的操作列是人工寫入的,可能跳過了框架本身的某些限定,所以,在定義columns的字段時,加入visible:false也同樣生效。
{
field: 'orderType',
title: '貨源類型',
formatter: checkFMT,
events: operateEvents,checkFM
}
function checkFMT(value) {
return "<a href='javascript:void(0)' class=\"check_a check_a_active\" style='margin-right:5px' value=\"1\" >"+value+"</a> ";
}
//格式化a標簽點擊事件
window.operateEvents = {
'click a': function (e, value, row, index) {
window.location.href=url;
}
};