2012-09-13 35 views
3

我用這plugin實現我Table粘性表頭。實際上,與插件示例和我的頁面中一樣,表格標題稍後會在表格中的最後一行消失。我希望我的表格標題在最後一行消失時正好消失。有沒有機會實現這個目標?粘表標題

回答

4

這裏有一個工作示例:fiddle

所有我改變了這一行的末尾:

if ((scrollTop > offset.top) && (scrollTop < offset.top + $this.height()-base.$clonedHeader.height())) { 
+0

你應該做一個[拉請求( https://github.com/jmosbech/StickyTableHeaders/pulls) – PiTheNumber

+0

嘿vonflow,我認爲你擊中了現場,你能更好地解釋我哪一行你解決了嗎?我只是簡單地在Jsfiddle中做了一個粘貼和複製代碼,它似乎也適用於我的項目。我會在github上提一下你的名字。由於 – Koala7

+0

其實我只是想出瞭如何做拉請求,所以我剛想把它英寸 – vonflow

1

我知道ŧ他是老了,但我覺得奉獻的東西,可以幫助一些......

對於動態表(其中每個單元的寬度是預先計算),這個插件打亂了標題行的寬度。

我做了幫助計算基於從基於第一TBODY行的單元,每個單元outerWidth寬度的一些變化。

出在插件當前寬度計算首評:

base.updateWidth = function() { 
     // Copy cell widths and classes from original header 
     $('th', base.$clonedHeader).each(function (index) { 
      var $this = $(this); 
      var $origCell = $('th', base.$originalHeader).eq(index); 
      this.className = $origCell.attr('class') || ''; 
      //$this.css('width', $origCell.width()); 
     }); 

     // Copy row width from whole table 
     //base.$clonedHeader.css('width', base.$originalHeader.width()); 
    }; 

    // Run initializer 
    base.init(); 

然後添加以下base.toggleHeaders的末尾=函數(){

// Set cell widths for header cells based on first row's cells 
var firstTr = $this.children("tbody").children("tr").first(); 
var iCol = 0; 
$(firstTr).children("td:visible").each(function() 
{ 
    var colWidth = $(this).outerWidth(); 
    console.log(colWidth.toString()); 
    var headerCell = $this.children("thead.tableFloatingHeader").children("tr").children("th:eq(" + iCol + ")"); 
    var firstRowCell = $this.children("tbody").children("tr:first").children("td:eq(" + iCol + ")"); 
    $(headerCell).outerWidth(colWidth); 
    $(firstRowCell).outerWidth(colWidth); 

    iCol++; 
}); 
0

我寫一個jquery庫這使得表中可以固定在頁面的頂部,準確地消失在最後一排走了

這是一個小的jQuery庫函數與ScrollFix 01組合庫提供固定在主菜單下的表頭表。該庫還支持在同一個頁面

https://github.com/doska80/ScrollTableFixed