您的位置:首页 > Web前端 > BootStrap

Bootstrap-table中跨页记住checbox,返回时保留勾选状态

2017-09-12 14:46 549 查看

Bootstrap-table中跨页记住checbox,返回时保留勾选状态

<body>
<div class="container">
<h1>Maintain selected on server side.(<a href="https://github.com/wenzhixin/bootstrap-table/issues/917" target="_blank">#917</a>).</h1>
<table id="table"
data-toggle="table"
data-pagination="true"
data-side-pagination="server"
data-url="/examples/bootstrap_table/data"
data-response-handler="responseHandler">
<thead>
<tr>
<th data-field="state" data-checkbox="true"></th>
<th data-field="id">ID</th>
<th data-field="name">Item Name</th>
<th data-field="price">Item Price</th>
</tr>
</thead>
</table>
</div>
<script>
var $table = $('#table'),
selections = [];
$(function () {
$table.on('check.bs.table check-all.bs.table ' +
'uncheck.bs.table uncheck-all.bs.table', function (e, rows) {
var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
return row.id;//注意这里的row.id 中的id指的是列表的主键,替换成你使用的就行了比如 studentId等
}),
func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference';
selections = _[func](selections, ids);
});
});
function responseHandler(res) {
$.each(res.rows, function (i, row) {
//注意这里的row.id 中的id指的是列表的主键,替换成你使用的就行了比如 studentId等
row.state = $.inArray(row.id, selections) !== -1;
});
return res;
}
</script>
</body>


勾选的结果保留在selections数组中


使用时在jquery.min.js、bootstrap.min.js、bootstrap-table.js之后引入

lodash.min.js

lodash.min.js下载地址

http://download.csdn.net/download/capmiachael/9974980

参考

http://issues.wenzhixin.net.cn/bootstrap-table/#issues/917.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: