0

我有一个下表。

<table id="myTable" class="tablesorter"> 
<thead> 
<tr> 
    <th>No</th>
    <th>Name</th>     
    <th>Email</th> 
    <th class='time'>Time</th> 
    <th>Price</th> 
</tr> 
</thead> 
<tbody> 
<tr> 
    <td>1</td>
    <td>Smith</td>    
    <td>jsmith@gmail.com</td> 
    <td class='time'>60 mins</td> 
    <td>45</td> 
</tr> 

</tbody> 
</table> 

我正在使用 jquery tablesorter 插件。Onready,tablesorter 运行良好。我可以看到所有列都可以排序。

在我的应用程序中,单击“刷新”按钮后,将动态添加或删除行。这意味着,表格内容将被更改。表修改后,排序不起作用。

这是jsfiddle 演示

下面是调用 tablesorter 的代码。

   $("#myTable").tablesorter({
        headers: { 
            4: { sorter: "integer"}, 
            2: {sorter: false} 
        },
        debug:true,
        textExtraction:function(node){
           var $node = $(node)
           var text = $node.text();  
           if ($node.hasClass('time')) {
                text = text.replace('mins', '');
            };
            return text;            
        }
    });

在给定的演示示例中,添加的行成为第一行并且不用于排序。

4

2 回答 2

3

API 文档的初步查看显示了此演示链接:http ://tablesorter.com/docs/example-empty-table.html

关键是这行代码:

    // let the plugin know that we made a update 
    $("table").trigger("update"); 

如果您将其添加到您的代码中...

   $("#myTable").append(row).trigger("update");   

...它有效

于 2012-12-10T08:25:05.943 回答
1

Either apply THE FIX to Christian Bach's original version or use Mottie's improved v2.x, HERE.

Do not rely on .trigger("update") in the unfixed original version.

于 2012-12-10T08:26:50.293 回答