Skip to content

Commit dd13c85

Browse files
author
Vincent Loh
committed
Default offset Y to 0px for sticky header example, if top fixed navbar not present
1 parent 652de88 commit dd13c85

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

extensions/sticky-header.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ <h1>Sticky Header</h1>
3131
function buildTable($el, cells, rows) {
3232
var i, j, row,
3333
columns = [],
34-
data = [];
34+
data = [],
35+
stickyHeaderOffsetY = 0;
3536

3637
for (i = 0; i < cells; i++) {
3738
columns.push({
@@ -47,12 +48,20 @@ <h1>Sticky Header</h1>
4748
}
4849
data.push(row);
4950
}
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+
5059
$el.bootstrapTable('destroy').bootstrapTable({
5160
columns: columns,
5261
data: data,
5362
search: true,
5463
stickyHeader: true,
55-
stickyHeaderOffsetY: +$('.navbar-fixed-top').css('height').replace('px','') + +$('.navbar-fixed-top').css('margin-bottom').replace('px','') + 'px'
64+
stickyHeaderOffsetY: stickyHeaderOffsetY + 'px'
5665
});
5766
}
5867
</script>

0 commit comments

Comments
 (0)