JQuery tablesorter使用ajax和动态thead和tbody部分 [英] JQuery tablesorter using ajax and dynamic thead and tbody sections

查看:189
本文介绍了JQuery tablesorter使用ajax和动态thead和tbody部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jjoery tablesorter插件添加一些表格排序到使用dojo的Rally应用程序,努力解决如何连接tablesorter的更新回调。



<我有html看起来像这样(thead和tbody是分开的,因为它们是动态生成的,即列数预先不知道):

 < table id ='myTable'class ='tablesorter'> 
< thead id ='sort-head'>< / thead>
< tbody id ='sort-body'>< / tbody>
< / table>

tablesorter init在这里

 < script type =text / javascript> 
函数onLoad(){
var appCustom = new ReleaseScopeChange();
appCustom.display(dojo.body());
}
rally.addOnLoad(onLoad);
$(document).ready(function(){$(#myTable)。tablesorter();});
< / script>

代码更新thead / tbody

  dojo.byId(sort-head)。innerHTML = headresults; 
dojo.byId(sort-body)。innerHTML = bodyresults;
$('#myTable')。trigger(update);

现在,排序实际上根本没有设置。如果我添加一个静态表,我可以完美地进行排序,所以我假设它与ajax请求和更新触发器之间的时间相关。



我已经查看了关于这个的很多其他答案,我真的不确定缺少什么。

解决方案

如果你使用原始的tablesorter ,最好只删除并替换整个表而不是更新thead& tbody html分开;然后在新表上重新初始化tablesorter。



或者你可以禁用tablesorter ,然后重新初始化它。



如果你使用我的 fork of tablesorter ,使用 updateAll 方法而不是更新

  dojo.byId(sort-head)。innerHTML = headresults; 
dojo.byId(sort-body)。innerHTML = bodyresults;
$('#myTable')。trigger(updateAll);


I am attempting to add in some table sorting using the jquery tablesorter plugin to a Rally app using dojo, struggling with how to hook up the update callback for the tablesorter.

I have html that looks like this (thead and tbody are separated as they are being dynamically generated i.e. number of columns is not known in advance):

<table id='myTable' class='tablesorter'>
    <thead id='sort-head'></thead>
    <tbody id='sort-body'></tbody>
</table>

tablesorter init is here

<script type="text/javascript">
    function onLoad() {
        var appCustom = new ReleaseScopeChange();
        appCustom.display(dojo.body());
    }
    rally.addOnLoad(onLoad);
    $(document).ready(function(){$("#myTable").tablesorter();});      
</script>

Code updating the thead/tbody

dojo.byId("sort-head").innerHTML = headresults; 
dojo.byId("sort-body").innerHTML = bodyresults; 
$('#myTable').trigger("update");            

Now, the sorting never actually gets set up at all. If I add a static table I can get the sorting working perfectly, so I am assuming its related to timing between the ajax request and the update trigger.

I have looked through a lot of other answers on this and I'm really not sure what is missing.

解决方案

If you are using the original tablesorter, it would be better to just remove, and replace the entire table instead of updating the thead & tbody html separately; then reinitialize tablesorter on the new table.

Or you could disable tablesorter, then reinitialize it.

If you are using my fork of tablesorter, use the updateAll method instead of update.

dojo.byId("sort-head").innerHTML = headresults; 
dojo.byId("sort-body").innerHTML = bodyresults; 
$('#myTable').trigger("updateAll");

这篇关于JQuery tablesorter使用ajax和动态thead和tbody部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆