近期使用表格,做一下功能分类:
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'});