近期使用表格,做一下功能分類:
HTML表格初始化部分:
<div class="twoTable">
<table id="twoTable" data-toggle="table" data-height="400" data-show-export="true" data-pagination="true" data-url="oneTableIndex.json">
<thead>
<tr>
<th data-field="SelectAll" ></th>
<th data-field="Product">Product</th>
<th data-field="LongShort">LongShort</th>
<th data-field="Price">Price</th>
<th data-field="Qty">Qty</th>
<th data-field="Ultimate">Ultimate</th>
<th data-field="Operate" data-formatter="actionTwoFormatter" data-events="actionTwoEvents"></th>
</tr>
</thead>
</table>
</div>
1.動態加載表格數據時,在表格最後加上button並進行操作(添加Delete與Edit按鈕),方法如下:
function actionTwoFormatter(value, row, index) {
return [
'<a id="btn_detail">Delete</a>'+
'<a id="btn_Edit">Edit</a>'
].join('');
}
對添加的按鈕進行操作:
window.actionEvents = {
'click #btn_detail': function (e, value, row, index){
alert('You click like icon, row: ' + JSON.stringify(row.id));
}
click #btn_Edit': function (e, value, row, index){}
};
2.刷新表格(twoTable爲表格的id,jsonTable爲表格上的json)
$('#twoTable').bootstrapTable('refresh', {url: 'jsonTable'});