在动态修改的表上使用 jQuery tableSorter
我在页面上使用 jQuery tableSorter 插件。
不幸的是,正在排序的表是动态修改的,当我在添加元素后排序时,该元素消失,将表恢复到创建 tableSorter 时的状态。
有什么方法可以强制 tableSorter 重新扫描页面,以便这些新元素正确排序?
I am using the jQuery tableSorter plugin on a page.
Unfortunatley, the table that is being sorted is dynamically modified, and when I sort after adding an element, the element disappears, restoring the table to the state that it was in when the tableSorter was created.
Is there any way that i can force tableSorter to rescan the page so that these new elements are sorted properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信您可以使用以下方法触发更新:
I believe you can trigger an update using something like:
看来你是对的。
就可以了。
请注意,tablesorter API 在某些时候发生了变化,因此这些内容以及事件绑定都发生了变化。 我最大的困惑是试图找出为什么有些功能有效而其他功能无效,这是由于插件版本错误,尽管没有明显的区别。
Seems you are correct.
does the trick.
As a note, the tablesorter API changed at some point, so these things got changed, as well as the event binding. My biggest hangup was trying to figure out why some things worked and others did not, and it was due to having a wrong version of the plugin, despite there being no obvious distinction.
$(table).trigger("update"); 抛出错误
因此,有一个 jquery 函数
.ajaxStop()
其中tablesorter()
被调用。 不要在.ready()
中调用 tablesorter 来完成这项工作
The
$(table).trigger("update");
throws errorSo, there is a jquery function
.ajaxStop()
wheretablesorter()
is called. Do not call tablesorter in.ready()
which did the job
对于像我这样面临动态生成表排序问题的新手,这里是解决方案。
前面给出的答案是正确的,但是你把这个命令放在哪里呢?
将数据附加到表后,您需要立即放置它。
就我而言
For those Newbies like me who are facing issue with sorting dynamic generated table, here is the solution.
The answer previously given are correct, but where do you place this command?
You need to place it as soon as you've appended the data to the table.
Ex in my case