-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy path917.html
71 lines (63 loc) · 1.68 KB
/
917.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
<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>
<template>
<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>
</template>
<script>
const $table = $('#table')
let selections = []
window.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) {
let rows = rowsAfter
if (e.type === 'uncheck-all') {
rows = rowsBefore
}
const ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
return row.id
})
const func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference'
selections = window._[func](selections, ids)
})
}
</script>