JQuery table sorting; problem with dynamically added rows

99封情书 提交于 2019-12-10 17:24:42

问题


I am using a jquery tablesorter plugin(http://tablesorter.com/docs/) for sorting my tables. This works for rows that created already. But when I add a row dynamically with Jquery clone() method, sorting is not working.

What I should I do to sort rows even if I add a row dynamically?


回答1:


$('.tablesorter').trigger('update'); after you add a row.

Tablesorter only scans through the table once, and after that it sorts on internally stored numeric or text values. It's quite clever, actually, as it makes the act of sorting super quick.




回答2:


The plugin has an example of an ajax update and it looks like you just have to trigger an "update" method on the table after you add your dynamic data.

Look here: http://tablesorter.com/docs/example-ajax.html

Code:

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


来源:https://stackoverflow.com/questions/3722646/jquery-table-sorting-problem-with-dynamically-added-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!