Skip to content

Commit 652de88

Browse files
author
Vincent Loh
committed
Add sticky header example
1 parent 95919b2 commit 652de88

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

extensions/sticky-header.html

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
36+
for (i = 0; i < cells; i++) {
37+
columns.push({
38+
field: 'field' + i,
39+
title: 'Cell' + i,
40+
sortable: true
41+
});
42+
}
43+
for (i = 0; i < rows; i++) {
44+
row = {};
45+
for (j = 0; j < cells; j++) {
46+
row['field' + j] = 'Row-' + i + '-' + j;
47+
}
48+
data.push(row);
49+
}
50+
$el.bootstrapTable('destroy').bootstrapTable({
51+
columns: columns,
52+
data: data,
53+
search: true,
54+
stickyHeader: true,
55+
stickyHeaderOffsetY: +$('.navbar-fixed-top').css('height').replace('px','') + +$('.navbar-fixed-top').css('margin-bottom').replace('px','') + 'px'
56+
});
57+
}
58+
</script>
59+
</body>
60+
</html>

0 commit comments

Comments
 (0)