Bootstrap-table中跨页记住checbox,返回时保留勾选状态 (多选框分页保留)

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数组中
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值