bootstrap table取消全选事件,onUncheckAll事件返回取消全选前已选中的数据和全选后的数据。
全选事件返回参数如下。
参数名称 | 说明 |
rowsAfter | 取消全选后全部选中的数据 |
rowsBefore | 取消全选前的数据,在1.41之前此参数无效,1.52之后有效 |
$('#table').bootstrapTable({
columns: columns, //列对象
data: data, //要显示的数据对象
onUncheckAll: function (rowsAfter,rowsBefore) {
alert(JSON.stringify(rowsBefore)); //在1.41之前此参数无效,1.52之后有效
}
});
$('#table').on('uncheck-all.bs.table', function (e,rowsAfter,rowsBefore) {
alert(JSON.stringify(rowsBefore));
});
注意:初始化时注册和初始化后注册的第一个返回参数对象是不一样的
<!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://unpkg.com/bootstrap-table@1.15.2/dist/bootstrap-table.min.js"></script>
<title>bootstrap table onUncheckAll取消全选事件例子</title>
<style>
.table-demo {
width: 80%;
margin: 30px auto 0px auto;
}
.fixed-table-header {
border-right: solid 1px #ddd;
border-top: solid 1px #ddd;
}
.fixed-table-header table {
border-top: solid 0px #ddd !important;
margin-top: -1px;
}
</style>
</head>
<body>
<div class="table-demo">
<table id="table"></table>
</div>
<script>
//设置需要显示的列
var columns = [{
checkbox: true
}, {
field: 'Id',
title: 'ID'
}, {
field: 'Model',
title: '型号'
}, {
field: 'Num',
title: '数量'
}];
//bootstrap table初始化数据
$('#table').bootstrapTable({
columns: columns,
data: getData(),
classes: "table table-bordered table-striped table-sm table-dark",
height: 400,
//******前端分页设置****
pagination: true,
pageNumber: 2,
pageSize: 10,
pageList: "[10, 20, 50, 200]",
paginationHAlign: "left",
paginationDetailHAlign: "right",
//******取消全选事件****
onUncheckAll: function (rowsAfter, rowsBefore) {
alert(JSON.stringify(rowsAfter));
}
});
function getData() {
var data = [];
for (var i = 0; i < 100; i++) {
var item = {
Id: i,
Model: 'QX1000' + i,
Num: i + 20
};
data.push(item);
};
return data;
}
</script>
</body>
</html>