2016-07-11 44 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'); 
    }); 
});