带有动态添加行的jquery tablesorter的问题

你好,我有动态添加行到jquery tablesorter的问题,

我必须在表的开头添加一行,默认情况下tablesorter工作正常但在添加行之后,表只排序使用前面的行排序我的意思是新行不包括在排序过程中,新行有一些但不是所有字段都空白任何解决方案?

tablesorter网站提供了如何执行此操作的详细信息: 使用Ajax附加表数据 。 代码转载如下:

$(document).ready(function() { $("table").tablesorter(); $("#ajax-append").click(function() { $.get("assets/ajax-content.html", function(html) { // append the "ajax'd" data to the table body $("table tbody").append(html); // let the plugin know that we made a update // updateAll ensures sorting is updated as well $("table").trigger("updateAll"); // set sorting column and direction, this will sort on the first and third column var sorting = [[2, 1], [0, 0]]; // sort on the first column $("table").trigger("sorton", [sorting]); }); return false; }); }); 

您试图取消设置tablesorter并初始化一个新的tablesorter会话?

因为tablesorter不知道你添加了新行,所以为什么不在表上设置一个新的tablesorter。

我能让它工作的唯一方法是重新生成整个表(删除它然后再创建)。

 $(".resultTablePlaceholder").html('').html('...
'); $("#resultTable").tablesorter();

这些线条对我来说非常合适。 分配HTML后,只需触发表的更新function。

 $('#tblID').html(str); $("#tblID").trigger("update"); 

其中#tblID是表ID, str是分配给表的表行的html。