2016-04-10 32 views
0

目前,我正在嘗試使用jQuery表排序器插件對我的表格行進行排序。目前,我的表格數據將每60秒更新一次,所以如果我開始在60秒之前進行排序,它的工作原理是正常的,但在60秒後如果我嘗試對錶格行進行排序得到重複。我能否知道原因以及如何解決此問題。提前致謝。jQuery Table排序器行重複

這是我的jQuery代碼:

$(document).ready(function(){ 
    setTimeout(function(){ 
     if($(".tablesorter").find('tbody:first tr').length > 0){ 
      $(".tablesorter").tablesorter(); 
      $(".tablesorter").trigger('update'); 
      alert("success"); 
     } 
    }, 5000); 
}); 
+0

你的表如何每60秒更新一次?你應該在那裏調用trigger('update')。 – ssilas777

+0

實際上我使用'setTimeout(arguments.callee,60000);'爲我的表更新每60個seonds,它的一個單獨函數 – anonymous5671

+1

$(「。tablesorter」)。trigger('update'),您應該添加此代碼在用新數據更新表之後的該方法中。 – ssilas777

回答

0

而不是使用一個setTimeout更新的tablesorter,更新的tablesorter 任何AJAX功能添加或刪除從表中的內容。例如:

// tablesorter initialized outside of the ajax process 
$("table").tablesorter(); 

$.ajax("load-new-stuff.php") 
    .done(function(data) { 
    // process the data and add it to the table 
    addData(data); 
    }) 
    .fail(function() { 
    $("table tbody").html("<tr><td colspan='5'>Error</td></tr>"); 
    }) 
    .always(function() { 
    $("table").trigger("update"); 
    });