2013-03-01 30 views
0

我有以下代碼來加載tablesorter插件中的數據。這裏我顯示了pgl中的記錄數,但當點擊50並返回到25時總計數顯示不正確。表排序插件不正確的記錄數

任何想法爲什麼發生這種情況?

<div class="rowsPerPage"> 
<a href="javascript:void(0);" onclick="test1(25);">25</a> 
<a href="javascript:void(0);" onclick="test1(50);">50</a> 
<a href="javascript:void(0);" onclick="test1(toalnoofrecords);">All</a> 
</div> 
<div id="pg"> 
    <div id="pgl"></div> 
    <div id="pgR"></div> 
</div>  


<table id="testtable"> 
    datas comes here 
</table> 

<!---- javascript function --> 
function test1(val) 
{ 
    $(jQuery('#testtable').tablesorterPager({container: $("#pgR"), positionFixed: false,size: value })); 

    } 
+0

你可以分享'test1()'的代碼嗎?另外,'$(jQuery('#testtable')...)'是一種奇怪的格式,你不需要將整個東西包裝在'$()'中。另外,'val'和'value'在你的'test()'函數內部不匹配。 – Mottie 2013-03-01 23:55:38

+0

@Mottie對不起,我把測試(),而不是test1.Please現在看看。 – svk 2013-03-02 01:06:20

回答

1

如果您使用的是原來的tablesorter插件(V2.0.5),然後使用下面的代碼(demo):

jQuery(function($){ 
    $('#testtable') 
    .tablesorter() 
    .tablesorterPager({ 
     container: $("#pgR"), 
     positionFixed: false, 
     size: 10 
    }); 
}); 

function test(val){ 
    $t = jQuery('#testtable'); 
    $t[0].config.size = val; 
    $t.trigger('appendCache'); 
} 
  • 注:原來的tablesorter不會與工作jQuery 1.9+,因爲它使用$.browser.msie

如果用我的forked version of tablesorter,然後用這個代碼(demo):

HTML

<div class="rowsPerPage"> 
    <a href="#">10</a> 
    <a href="#">20</a> 
    <a href="#">All</a> 
</div> 
<div id="pg"> 
    <div id="pgl"></div> 
    <div id="pgR"></div> 
</div> 

的Javascript

jQuery(function($){ 
    $('#testtable') 
    .tablesorter({ 
     theme: 'blue' 
    }) 
    .tablesorterPager({ 
     container: $("#pgR"), 
     size: 10 
    }); 

    $('.rowsPerPage a').click(function(){ 
     var val = $(this).text(); 
     if (/all/i.test(val)) { 
      val = 99999; // pick some huge number 
     } 
     $('#testtable').trigger('pageSize', val); 
     return false; 
    }); 

}); 
  • 注:次是代碼使用unobstrusive javascript,允許您輕鬆添加更多頁面大小,而不包括更多內聯JavaScript。