forked from wenzhixin/bootstrap-table-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrollTo.html
More file actions
69 lines (64 loc) · 1.73 KB
/
scrollTo.html
File metadata and controls
69 lines (64 loc) · 1.73 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
59
60
61
62
63
64
65
66
67
68
69
<script>
init({
title: 'scrollTo',
desc: 'Scroll to the number value position, set \'bottom\' means scroll to the bottom.<br>' +
'<code>$table.bootstrapTable(\'scrollTo\', 0)</code><br>' +
'<code>$table.bootstrapTable(\'scrollTo\', number)</code><br>' +
'<code>$table.bootstrapTable(\'scrollTo\', \'bottom\')</code>',
links: ['bootstrap-table.min.css'],
scripts: ['bootstrap-table.min.js']
})
</script>
<style>
.row-index {
display: inline-block;
width: 100px;
vertical-align: middle;
}
</style>
<div id="toolbar">
<button id="button" class="btn btn-secondary">scrollTo Top</button>
<button id="button2" class="btn btn-secondary">Scroll to row index: </button>
<input type="number"
class="form-control row-index"
value="3" min="0">
<button id="button3" class="btn btn-secondary">scrollTo Bottom</button>
</div>
<table
id="table"
data-toggle="table"
data-toolbar="#toolbar"
data-height="460"
data-url="json/data1.json">
<thead>
<tr>
<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 $button = $('#button')
var $button2 = $('#button2')
var $button3 = $('#button3')
function mounted() {
$button.click(function () {
$table.bootstrapTable('scrollTo', 0)
})
$button2.click(function () {
var index = +$('.row-index').val()
var top = 0
$table.find('tbody tr').each(function (i) {
if (i < index) {
top += $(this).height()
}
})
$table.bootstrapTable('scrollTo', top)
})
$button3.click(function () {
$table.bootstrapTable('scrollTo', 'bottom')
})
}
</script>