bootstrap table表格在detail view详情视图模式下,点击展开按钮时的事件,参数返回行号、行数据对象。
参数返回如下对象
参数名称 | 说明 |
index | 被展开行的索引行号,从0开始 |
row | 行的原始数据如{id:1,name:'itxst'} |
$detail | 被展开的详情jquey对象 |
$('#table').bootstrapTable({
columns: columns,
data: data,
onExpandRow:function(index, row, $detail)
{
alert(JSON.stringify(row));
}
});
$('#table').on('expand-row.bs.table', function (e,index, row, $detail){
alert(JSON.stringify(row));
});
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://www.itxst.com/package/bootstrap-table-1.14.1/jquery-3.3.1/jquery.js"></script>
<link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
<link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.css" rel="stylesheet" />
<script src="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.js"></script>
<link href="https://www.itxst.com/package/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
<title>bootstrap table onExpandRow detail视图模式点击展开事件在线例子</title>
<style>
.table-demo {
width: 80%;
margin: 30px auto 0px auto;
}
</style>
</head>
<body>
<div class="table-demo">
<table id="table" ></table>
</div>
<script>
//设置需要显示的列
var columns = [{
field:"Id",
title: '序号'
}, {
field: 'Name',
title: '水果名称'
}
];
//需要显示的数据
var data = [{
Id: 3000,
Name: '香蕉',
StockNum: '100'
}, {
Id: 3002,
Name: '波罗蜜',
StockNum: '200'
}, {
Id: 3003,
Name: '车厘子',
StockNum: '200'
}, {
Id: 3004,
Name: '桃子',
StockNum: '200'
}];
//bootstrap table初始化数据
$('#table').bootstrapTable({
columns: columns,
data: data,
toggle:"table",
detailView:true,
detailFormatter:"detailFormatter",
onExpandRow:function(index, row, $detail)
{
alert(JSON.stringify(row));
}
});
function detailFormatter(index, row) {
var html = []
$.each(row, function (key, value) {
html.push('<p><b>' + key + ':</b> ' + value + '</p>')
});
return html.join('')
}
</script>
</body>
</html>