forked from shuxuecode/bootstrap-table
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wenzhixin#3520 from Kroneaux/patch-2
StickyHeader Bootstrap 4 support
- Loading branch information
Showing
1 changed file
with
11 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ($) { | ||
|
@@ -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; | ||
|
@@ -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)); | ||
|
||
|
@@ -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 | ||
|
@@ -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); | ||
} | ||
|
||
} | ||
|