Skip to content

Commit 00b5781

Browse files
committed
Merge pull request wenzhixin#103 from vinzloh/sticky-header
Sticky header
2 parents 95919b2 + dd13c85 commit 00b5781

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

extensions/sticky-header.html

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Sticky Header</title>
5+
<meta charset="utf-8">
6+
<link rel="stylesheet" href="../assets/bootstrap/css/bootstrap.min.css">
7+
<link rel="stylesheet" href="../assets/bootstrap-table/src/bootstrap-table.css">
8+
<link rel="stylesheet" href="../assets/bootstrap-table/src/extensions/sticky-header/bootstrap-table-sticky-header.css">
9+
<link rel="stylesheet" href="http://bootstrap-table.wenzhixin.net.cn/assets/css/docs.min.css">
10+
<link rel="stylesheet" href="../assets/examples.css">
11+
<script src="../assets/jquery.min.js"></script>
12+
<script src="../assets/bootstrap/js/bootstrap.min.js"></script>
13+
<script src="../assets/bootstrap-table/src/bootstrap-table.js"></script>
14+
<script src="../assets/bootstrap-table/src/extensions/sticky-header/bootstrap-table-sticky-header.js"></script>
15+
<script src="../ga.js"></script>
16+
</head>
17+
<body>
18+
<div class="container">
19+
<h1>Sticky Header</h1>
20+
<p>An extension which provides a sticky header for table columns when scrolling on a long page and / or table. Works for tables with many columns and narrow width with horizontal scrollbars too.</p>
21+
<hr>
22+
<table id="table" data-show-columns="true"></table>
23+
</div>
24+
<script>
25+
var $table = $('#table');
26+
27+
$(function () {
28+
buildTable($table, 20, 50);
29+
});
30+
31+
function buildTable($el, cells, rows) {
32+
var i, j, row,
33+
columns = [],
34+
data = [],
35+
stickyHeaderOffsetY = 0;
36+
37+
for (i = 0; i < cells; i++) {
38+
columns.push({
39+
field: 'field' + i,
40+
title: 'Cell' + i,
41+
sortable: true
42+
});
43+
}
44+
for (i = 0; i < rows; i++) {
45+
row = {};
46+
for (j = 0; j < cells; j++) {
47+
row['field' + j] = 'Row-' + i + '-' + j;
48+
}
49+
data.push(row);
50+
}
51+
52+
if ( $('.navbar-fixed-top').css('height') ) {
53+
stickyHeaderOffsetY = +$('.navbar-fixed-top').css('height').replace('px','');
54+
}
55+
if ( $('.navbar-fixed-top').css('margin-bottom') ) {
56+
stickyHeaderOffsetY += +$('.navbar-fixed-top').css('margin-bottom').replace('px','');
57+
}
58+
59+
$el.bootstrapTable('destroy').bootstrapTable({
60+
columns: columns,
61+
data: data,
62+
search: true,
63+
stickyHeader: true,
64+
stickyHeaderOffsetY: stickyHeaderOffsetY + 'px'
65+
});
66+
}
67+
</script>
68+
</body>
69+
</html>

0 commit comments

Comments
 (0)