0

我有一个 tablesorter 表,目前工作正常,使用 ajax 方法更新表数据。我已经添加了 tablesorter Pager 插件,现在

$(.tablesorter').trigger("update");

更新表格时的功能,不会更新仍显示前一行/页数的寻呼机。

我在用:

    //init tablesorter
    $('#tblCustomers').tablesorter({
            headers: { 0: { sorter: false}},
            sortList: [[5,1]]               
    }).tablesorterPager({container: $("#pager")});
    //search listener
    $('input.search').change(function() {
                 $.post('search.php', { 'keyword' : $(this).val() }, function(data) {
                        $('#tblCustomers tbody').html(data);
                        $('#tblCustomers').trigger('update');
                 }
    });

请指教...

4

3 回答 3

2

丹尼尔克的回答几乎完美无缺,但寻呼机会跳过页面。我用我找到的另一个答案解决了这个问题,这就是我想出的:

function tableUpdated() {
$('#pager *').unbind('click');
$("#table") 
.tablesorter({
    // zebra coloring
    widgets: ['zebra']
}) 
.tablesorterPager({container: $("#pager")}); 
}

希望这会有所帮助,快乐的编码!

于 2013-04-16T19:54:31.913 回答
0
function tableUpdated() {
    $('#tblCustomers').tablesorter({
        headers: { 0: { sorter: false}},
        sortList: [[5,1]]               
    }).tablesorterPager({container: $("#pager"), positionFixed: false});
}   

$(document).ready(function() {
   $('input.search').change(function() {
      $.post('search.php', { 'data': data } , function(data) {
        tableUpdated();
      });
   });  

事实证明,解决方案是将表初始化移动到一个单独的函数中,并在 $.post 的成功部分中调用它

经过数小时阅读谷歌结果后,这是唯一对我有用的东西。

于 2011-05-24T00:45:52.543 回答
0
  1. 确保在更新数据库表后刷新容器
  2. 请注意缓存,我会在 search.php 中添加一个随机查询字符串(例如 search.php?cachebuster=arandomnumberhere),以确保防止页面缓存。

有多种方法可以控制缓存。您可以通过 htaccess、前面提到的随机数等在服务器上设置它。

于 2011-05-23T08:20:40.540 回答