2014-02-06 30 views
1

我嘗試把2代表在同一​​頁面上,使用jQuery插件的tablesorter .. 但是,如果做到這一點,我的第二個表不正常工作..的tablesorter問題,2臺在頁面

在我的第二個表,我還沒有我的第二個表的頭名,

你可以在這裏看到:http://jsfiddle.net/9hHx5/

<html> <head> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="jquery.tablesorter.min.js"></script> <script type="text/javascript" src="jquery.tablesorter.scroller.js"></script> <script type="text/javascript"> $(document).ready(function() { $('table.tablesorter').tablesorter({ scrollHeight: 150, widgets: ['zebra','scroller'] }); //Setup window.resizeEnd event $(window).bind('resize', window_resize); $(window).bind('resizeEnd', function (e) { /* IE calls resize when you modify content, so we have to unbind the resize event so we don't end up with an infinite loop. we can rebind after we're done. */ $(window).unbind('resize', window_resize); $('table.tablesorter').each(function(n, t) { if (typeof t.resizeWidth === 'function') t.resizeWidth(); }); $(window).bind('resize', window_resize); }); }); function window_resize() { if (this.resize_timer) clearTimeout(this.resize_timer); this.resize_timer = setTimeout(function() { $(this).trigger('resizeEnd'); } , 250 ); } </script> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div class="inner-header">Demo</div> <table id="table1" cellspacing="0" cellpadding="0" class="tablesorter"> <thead> <tr> <th class="yr">Year</th> <th>Artist</th> <th>Single</th> <th>Album</th></tr> </thead> <tbody> <tr><td class="yr">1979</td><td>Specials</td><td>Gangsters</td><td>Non-album single</td></tr> <tr><td class="yr">1979</td><td>Specials</td><td>A Message to You, Rudy</td><td>Specials </td></tr> <tr><td class="yr">1980</td><td>Specials</td><td>Too Much Too Young</td><td>Specials</td></tr> <tr><td class="yr">1980</td><td>Specials</td><td>Rat Race</td><td>Non-album single</td></tr> <tr><td class="yr">1980</td><td>Specials</td><td>Stereotype</td><td>More Specials</td></tr> <tr><td class="yr">1980</td><td>Specials</td><td>Do Nothing</td><td>More Specials</td></tr> </tbody> </table> <table id="table2" cellspacing="0" cellpadding="0" class="tablesorter"> <thead> <tr> <th>People</th><th>Age</th><th>Birthday</th> </thead> <tbody> <tr> <td class="yr">XYZ</td><td>12</td><td>12/15/2012</td></tr> <tr> <td class="yr">RZE</td><td>36</td><td>12/12/1985</td></tr> <tr> <td class="yr">HFF</td> <td>36</td><td>01/02/1985</td> </tr> </tbody> </table> </body> </html>

請,如果有人可以幫助我

+0

這就是爲什麼我寫自己的表排序腳本:p它只有50行代碼,支持自定義排序值(例如,如果列中有「星期一」,「星期二」等,則可以設置數據屬性和數值進行排序),支持數字和字母排序,保存頁面重新加載時的排序順序......這真棒! :3 –

+0

你可以分享一個現場演示...你正在使用的滾動腳本是什麼?我不記得'scrollHeight'曾經是一個多功能選項。 – Mottie

+0

是的,你可以在這裏看到:http://jsfiddle.net/9hHx5/ – user1814879

回答

0

這個問題似乎是在滾動條控件代碼中的錯誤:

改變這一行:

var $hdr = $('<table class="' + $tbl.attr('class') + '" cellpadding=0 cellspacing=0><thead>' + $('thead', table[0]).html() + '<thead></table>'); 

這個(這只是這一部分$('thead', $tbl).html(),改變)

var $hdr = $('<table class="' + $tbl.attr('class') + '" cellpadding=0 cellspacing=0><thead>' + $('thead', $tbl).html() + '<thead></table>'); 

它修復了這個問題。

我已經在this updated demo中包含該更正。


我也想建議你試試我的fork of tablesorter,其中包括大量的改進,以及這個更新的滾動窗口小部件(其中仍然有需要修正一些問題)。

+0

非常感謝。..它的作品非常weelllllll – user1814879