如何对使用ajax添加的表进行排序

时间:2013-01-08 19:06:43

标签: php jquery ajax sorting

我通过ajax调用动态地向页面添加一个表,该表被分页并再次使用ajax调用进行分页。但是当我尝试使用jQuery插件对表进行排序时,它不起作用。

<script>
var targetURL = 'http://localhost/includes/qrmanager.php?start=' + pageno;   

    $('#qrmanager').html('<p><img src="images/ajax-loader.gif" /></p>');        
    $('#qrmanager').load( targetURL ).hide().fadeIn('slow'); //this loads the table within the div

 $("table").tablesort( );
</script>

我有tablesort()的插件,如果我只是通过php回显表而不使用ajax,它就可以工作。

1 个答案:

答案 0 :(得分:3)

您试图在AJAX有机会加载之前对表进行排序。

使用.load方法的成功回调代替:

var targetURL = 'http://localhost/includes/qrmanager.php?start=' + pageno;   
$('#qrmanager').html('<p><img src="images/ajax-loader.gif" /></p>');
$('#qrmanager').load( targetURL, function() {
    $(this).hide().fadeIn('slow'); 
    $("table").tablesort( );
});