Repository navigation
Expand file tree
/
Copy path917.html
More file actions
58 lines (51 loc) · 1.54 KB
/
Copy path917.html
File metadata and controls
58 lines (51 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<script>
init({
title: 'Issue #917',
desc: 'Maintain selected on server side.(<a href="https://github.com/wenzhixin/bootstrap-table/issues/917" target="_blank">#917</a>).',
links: ['bootstrap-table.min.css'],
scripts: [
'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js',
'bootstrap-table.min.js'
]
})
</script>
<table
id="table"
data-toggle="table"
data-pagination="true"
data-side-pagination="server"
data-url="https://examples.wenzhixin.net.cn/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>
<script>
var $table = $('#table')
var selections = []
function responseHandler(res) {
$.each(res.rows, function (i, row) {
row.state = $.inArray(row.id, selections) !== -1
})
return res
}
function mounted() {
$table.on('check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table',
function (e, rowsAfter, rowsBefore) {
var rows = rowsAfter
if (e.type === 'uncheck-all') {
rows = rowsBefore
}
var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
return row.id
})
var func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference'
selections = window._[func](selections, ids)
})
}
</script>