1 function UpdateTableHeaders() {
2 $("div.divTableWithFloatingHeader").each(function() {
3 var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
4 var floatingHeaderRow = $(".tableFloatingHeader", this);
5 var offset = $(this).offset();
6 var scrollTop = $(window).scrollTop();
7 if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height())) {
8 floatingHeaderRow.css("visibility", "visible");
9 floatingHeaderRow.css("top", Math.min(scrollTop - offset.top, $(this).height() - floatingHeaderRow.height()) + "px");
10 floatingHeaderRow.css("z-index", "20");
12 // Copy cell widths from original header
13 $("th", floatingHeaderRow).each(function(index) {
14 var cellWidth = $("th", originalHeaderRow).eq(index).css('width');
15 $(this).css('width', cellWidth);
18 // Copy row width from whole table
19 floatingHeaderRow.css("width", $(this).css("width"));
22 floatingHeaderRow.css("visibility", "hidden");
23 floatingHeaderRow.css("top", "0px");
28 $(document).ready(function() {
29 $("table.tableWithFloatingHeader").each(function() {
30 $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
32 var originalHeaderRow = $("tr:first", this)
33 originalHeaderRow.before(originalHeaderRow.clone());
34 var clonedHeaderRow = $("tr:first", this)
36 clonedHeaderRow.addClass("tableFloatingHeader");
37 clonedHeaderRow.css("position", "absolute");
38 clonedHeaderRow.css("top", "0px");
39 clonedHeaderRow.css("left", $(this).css("margin-left"));
40 clonedHeaderRow.css("visibility", "hidden");
42 originalHeaderRow.addClass("tableFloatingHeaderOriginal");
45 $(window.parent).scroll(UpdateTableHeaders);
46 $(window.parent).resize(UpdateTableHeaders);