jQuery Datatable删除行问题

时间:2014-10-07 08:59:12

标签: jquery jquery-datatables

我正在使用jQuery数据表管理公司列表 一切都很好,除了我必须删除一行的部分 对于删除的第一行工作得很好,但是如果我在我的firefox控制台中删除了另一行,它会显示删除的第一行和这一行。

如果删除第三行,则会显示已删除的所有行。

$s('body').on('click', '.del-firm', function(){
    var aPos = oTable.fnGetPosition( $s(this).closest('tr')[0] );
    var firm = $s(this).data('firm');
    $s('#client-firms').block({
        message: $s('.confirm-block'),
        overlayCSS: {
            backgroundColor: '#363636',
            cursor: 'default'
        },
        css : {
            border: '1px solid #D0D0D0',
            background: 'linear-gradient(to bottom, #fcfcfc 0%, #fbfbfb 39%, #eeeeee 84%, #ebebed 100%) repeat scroll 0 0 rgba(0, 0, 0, 0)',
            borderRadius: '3px',
            color: '#707070',
            padding: '5px',
            cursor: 'default'
        }
    });
    $s('#yes').click(function(){

        $s('#client-firms').block({
            message: 'Se proceseaza'
        });
        oTable.fnDeleteRow(aPos);
        $s.ajax({
            type: 'post',
            url: 'index.php?controller=servlet&method=del_firm',
            data: {
                'id': firm
            },
            success: function(data){
                $s('#client-firms').unblock();
            }
        });
        newRow = false;
    });
    $s('#no').click(function(){
        $s('#client-firms').unblock();
        return false;
    });
});

1 个答案:

答案 0 :(得分:2)

我会这样做:

    $s('#client-firms').on('click', '.del-firm', function(){
        $s(this).closest('tr').addClass('selected');
        var firm = $s(this).data('firm');
        var row = $s('#client-firms').find('.selected');


        $s('#client-firms').block({ 
            message: $s('.confirm-block'),
            overlayCSS: { 
                backgroundColor: '#363636',
                cursor: 'default'
            },
            css : {
                border: '1px solid #D0D0D0',
                background: 'linear-gradient(to bottom, #fcfcfc 0%, #fbfbfb 39%, #eeeeee 84%, #ebebed 100%) repeat scroll 0 0 rgba(0, 0, 0, 0)',
                borderRadius: '3px',
                color: '#707070',
                padding: '5px',
                cursor: 'default'
            }

        }); 

        $s('#no').click(function(){
            $s('#client-firms').unblock();
            return false; 
        });

    });

    $s('#yes').on('click' , function(){
        var row = $s('#client-firms').find('.selected');
        var firm = row.find('.del-firm').data('firm');

        $s('#client-firms').block({
             message: 'Se proceseaza'
        });


        $s.ajax({
            type: 'post',
            url: 'index.php?controller=servlet&method=del_firm',
            data: {
                'id': firm
            },
            success: function(){
                $s('#client-firms').unblock();
                oTable.row(row).remove().draw();
            }
        });

        newRow = false;
        oTable.draw();

    });