2011-05-23 58 views
0

我有一个tablesorter表,它工作正常,使用ajax方法更新表数据。我已经添加了寻呼机的tablesorter插件现在jQuery Tablesorter传呼机插件和Ajax更新

$(.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'); 
       } 
    }); 

建议,请...

+0

我有同样的问题。这可能有所帮助: http://stackoverflow.com/a/9000306/1168836 – Albertyto 2012-01-25 09:32:11

回答

0
  1. 确保您更新的容器更新数据库表
  2. 注意缓存后,我想补充一个带search.php的随机查询字符串(例如search.php?cachebuster = arandomnumberhere),以确保防止页面缓存。

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

+0

>>更新数据库表后确保刷新容器 请解释一下吗? – danielc 2011-05-23 08:43:28

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

经过几个小时的谷歌搜索结果,这是唯一的工作在我的情况。

+0

这不起作用。它除去当前可见页面的所有记录。 – 2012-02-24 22:42:38

2

丹尼尔斯的答案几乎完美,但寻呼机将跳过页面。我解决了这个与我发现的另一个答案,这里是我想出了:

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

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