bootstrap table全选的事件,onCheckAll事件返回全选前已选中的数据和全选后的数据。
全选事件返回参数如下。
参数名称 | 说明 |
rowsAfter | 数组,返回全选后全部选中的数据 |
rowsBefore | 全选前的数据,在1.41之前此参数无效,1.52之后有效 |
$('#table').bootstrapTable({
columns: columns, //列对象
data: data, //要显示的数据对象
onCheckAll: function (rowsAfter,rowsBefore) {
alert(JSON.stringify(rowsAfter));
}
});
copy
$('#table').on('check-all.bs.table', function (e,rowsAfter,rowsBefore) {
alert(JSON.stringify(rowsAfter));
});
copy
注意:初始化时注册和初始化后注册的第一个返回参数对象是不一样的
<!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 onCheckAll全选事件例子</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", //******前端分页设置**** onCheckAll: function (rowsAfter, rowsBefore) { alert(JSON.stringify(rowsAfter)); } }); function getData() { var data = []; for (var i = 0; i < 200; i++) { var item = { Id: i, Model: 'XH1000' + i, Num: i + 20 }; data.push(item); }; return data; } </script> </body> </html>
copy