2016-07-11 40 views
0

这是我用this在表格中向上滑动一行。我还创建了一个codepentablesorter删除了一行后,排序留下空隙

$(".tablesorter").tablesorter(); 

$('.remove').on('click', function(){ 
    $(this).closest('tr').children('td').animate({ padding: 0 }).wrapInner('<div/>').children().slideUp(function() { 
    $(this).closest('tr').remove(); 
    }); 
    $(".tablesorter").trigger('update'); 
}); 

目标:

  • 向上滑动该行时,点击删除
  • 正确排序无间隙

现在上滑作品。但是,在向上滑动之后,排序会在行之间留下间隙 - 删除的行显示为间隙(在codepen中不是很明显)。那么如何完全删除该行?或者为什么在排序后再次出现?

其实,如果我直接删除的行不向上滑动,排序完美的作品,但像上滑客户...

+1

你不是应该触发更新删除后,点击之后呢?尝试在删除后将触发器('更新')放入slideUp回调中。 – BenM

回答

2

由于.animate()方法是异步的,继续执行调用后立即.animate()和在实际行从表中删除之前,您正在有效地调用tablesorter上的更新。

在animate方法上使用回调函数并更新那里的tablesorter。

例子:

$('.remove').on('click', function(){ 
    $(this).closest('tr').children('td').animate({ padding: 0 }).wrapInner('<div />').children().slideUp(function() { 
     $(this).closest('tr').remove(); 
     $(".tablesorter").trigger('update'); 
    }); 
});