Skip to content

Commit

Permalink
Merge pull request wenzhixin#3520 from Kroneaux/patch-2
Browse files Browse the repository at this point in the history
StickyHeader Bootstrap 4 support
  • Loading branch information
wenzhixin authored Dec 30, 2017
2 parents aaafec0 + 93cd4db commit 4bdb6e7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/extensions/sticky-header/bootstrap-table-sticky-header.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* @author vincent loh <[email protected]>
* @version: v1.0.0
* @version: v1.1.0
* https://github.com/vinzloh/bootstrap-table/
* Sticky header for bootstrap-table
* @update J Manuel Corona <[email protected]>
*/

(function ($) {
Expand All @@ -12,6 +13,12 @@
$.extend($.fn.bootstrapTable.defaults, {
stickyHeader: false
});

var bootstrapVersion = 3;
try {
bootstrapVersion = parseInt($.fn.dropdown.Constructor.VERSION, 10);
} catch (e) { }
var hidden_class = bootstrapVersion > 3 ? 'd-none' : 'hidden';

var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initHeader = BootstrapTable.prototype.initHeader;
Expand All @@ -32,7 +39,7 @@
anchor_end_id = header_id +'_sticky_anchor_end';
// add begin and end anchors to track table position

table.before(sprintf('<div id="%s" class="hidden"></div>', sticky_header_container_id));
table.before(sprintf('<div id="%s" class="%s"></div>', sticky_header_container_id, hidden_class));
table.before(sprintf('<div id="%s"></div>', anchor_begin_id));
table.after(sprintf('<div id="%s"></div>', anchor_end_id));

Expand Down Expand Up @@ -82,7 +89,7 @@
$(item).css('min-width', $('#'+table_header_id+' tr').eq(0).find('th').eq(index).css('width'));
});
// match bootstrap table style
$("#"+sticky_header_container_id).removeClass('hidden').addClass("fix-sticky fixed-table-container") ;
$("#"+sticky_header_container_id).removeClass(hidden_class).addClass("fix-sticky fixed-table-container") ;
// stick it in position
$("#"+sticky_header_container_id).css('top', header_height + 'px');
// create scrollable container for header
Expand All @@ -93,7 +100,7 @@
match_position_x(event);
} else {
// hide sticky
$("#"+sticky_header_container_id).removeClass("fix-sticky").addClass('hidden');
$("#"+sticky_header_container_id).removeClass("fix-sticky").addClass(hidden_class);
}

}
Expand Down

0 comments on commit 4bdb6e7

Please sign in to comment.