bootstrap table checkBy根据设置的取消选中行,比如将id为1,5,8的行选中。
参数名称 | |
field | 根据那个字段来选中行 |
values | 据这个字段的哪些值来选中,格式:[1,51,18] |
//取消选中Id为1和23的行
$('#table').bootstrapTable('uncheckBy', {field: 'Id', values:[22,23]});
<!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/jquery-3.3.1/jquery.js"></script>
<link href="https://www.itxst.com/package/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
<link href="https://www.itxst.com/package/bootstrap-table-1.15.3/bootstrap-table.css" rel="stylesheet" />
<script src="https://www.itxst.com/package/bootstrap-table-1.15.3/bootstrap-table.js"></script>
<title>bootstrap table checkBy uncheckBy在线例子</title>
<style>
.table-demo {
width: 80%;
margin: 30px auto 0px auto;
}
.titles {
float: right;
clear: both;
}
</style>
</head>
<body>
<div id="toolbar">
<button onclick="check(1)">选中21,3行</button>
<button onclick="check(2)">取消选中21,3行</button>
</div>
<div class="table-demo">
<table id="table" ></table>
</div>
<script>
//定义列
var columns = [
{
checkbox:true
},
{
field:"Id",
title: 'ID'
}, {
field: 'fid',
title: 'Len'
} ];
var data= [{
Id: 21,
fid: 'B1',
}, {
Id: 3,
fid: 'B2',
}, {
Id: 23,
fid: 'B3',
} ];
$('#table').bootstrapTable({
toolbar:"#toolbar",
data:data,
columns: columns,
});
function check(icase)
{
if(icase===1)
{
$('#table').bootstrapTable('checkBy', {field: 'Id', values:[21, 3]});
}
if(icase===2)
{
$('#table').bootstrapTable('uncheckBy', {field: 'Id', values:[21, 3]});
}
}
</script>
</body>
</html>