4

我正在使用 jquery Tablesorter 插件,当我删除一行然后对列进行排序时,删除的行再次出现。从我在 stackoverflow 上读到的内容来看,我可能需要添加 trigger.update 和/或 trigger.appendcache,但这似乎不起作用,尽管我可能将它放在错误的位置。有任何想法吗?

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

4

1 回答 1

7

放在$('.tablesorter').trigger('update');下面resetGrid();

于 2012-05-26T01:59:43.247 回答