2012-04-24 94 views
3

我使用的是jquery Tablesorter插件,当我删除一行然后去排序列时,删除的行再次出现。从我在这里读到的stackoverflow是我可能需要添加trigger.update和/或trigger.appendcache,但似乎没有工作,你可能会把它放在错误的地方。有任何想法吗?Tablesorter在排序后添加删除行

<script type="text/javascript"> 
$(function() { 
    $(".tablesorter").tablesorter({ 
     headers: { 0: { sorter: false }, 1: { sorter: false }, 2: { sorter: false }, 3: { sorter: false} }, 
     widgets: ['zebra'], 
     widgetZebra: { css: ['alt-even-class', 'alt-odd-class'] } 
    }); 

    $('div#deleteDialog').dialog({ 
     autoOpen: false, 
     width: 400, 
     height: 200, 
     modal: true, 
     position: 'center', 
     resizable: false, 
     buttons: { 
      OK: function() { 
       var delID = $('div#deleteDialog input').val(); 
       $.post('@Url.Action("Delete", "Plate")', { id: delID }, function (data) { 
        if (data === 'delete') { 
         $('tr#' + delID).remove(); 
         resetGrid(); 
        } 
       }); 
       $(this).dialog('close'); 
      }, 
      Cancel: function() { 
       $(this).dialog('close'); 
      } 
     } 
    }); 

    $('table.tablesorter thead input:checkbox').change(function() { 
     $('table.tablesorter tbody input:checkbox').attr('checked', $('table.tablesorter thead input:checkbox').attr('checked')); 
    }); 

    $('#create').click(function() { 
     document.location.href = '@Url.Action("ItemSelect", "Plate")'; 
    }); 

    $('.menucosting_view').click(function() { 
     document.location.href = '@Url.Action("Details", "Plate")' + '/' + $(this).parent().parent().attr('id'); 
    }); 

    $('.menucosting_edit').click(function() { 
     document.location.href = '@Url.Action("Edit", "Plate")' + '/' + $(this).parent().parent().attr('id'); 
    }); 

    $('.menucosting_delete').click(function() { 
     $('div#deleteDialog input').val($(this).parent().parent().attr('id')); 
     $('div#deleteDialog').dialog('open'); 
    }); 
}); 

function resetGrid() { 
    $('.tablesorter tr').removeClass('alt-even-class').removeClass('alt-odd-class'); 
    $('.tablesorter tr:even').addClass('alt-even-class'); 
    $('.tablesorter tr:odd').addClass('alt-odd-class'); 
} 

+0

想象出来 - 放置$('。tablesorter')。trigger('update');在resetGrid()下; – Tmac 2012-04-24 18:23:55

+0

您应该在下面自己回答问题,或者完全删除问题。 – webbiedave 2012-05-25 21:46:10

回答

6

广场$('.tablesorter').trigger('update');resetGrid();下!

+0

感谢Tmac .. 2小时后。寻找解决方案,你的答案对我来说很有用......救了我的一天..谢谢你。竖起大拇指 ! – 2013-10-21 10:26:44

+0

真棒,谢谢! – Icarus 2015-04-08 01:20:45