bootstrap table表格在detail view详情视图模式下,点击收起按钮时的事件,参数返回行号、行数据对象。
参数返回如下对象
参数名称 | 说明 |
index | 被收起行的索引行号,从0开始 |
row | 行的原始数据如{id:1,name:'itxst'} |
detail | 被收起的详情jquey对象 |
$('#table').bootstrapTable({
columns: columns,
data: data,
onCollapseRow:function(index, row, detail)
{
alert(JSON.stringify(row));
}
});
$('#table').on('collapse-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 onCollapseRow 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: 1,
Name: '哈密瓜',
Level: '一级'
}, {
Id: 2,
Name: '琵琶',
Level: '一级'
}, {
Id: 3,
Name: '杨梅',
Level: '二级'
} ];
//bootstrap table初始化数据
$('#table').bootstrapTable({
columns: columns,
data: data,
toggle:"table",
detailView:true,
detailFormatter:"detailFormatter",
onCollapseRow: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>