Deleted Row mistirously appears after going on next/previous page or after changing No. of rows

Deleted Row mistirously appears after going on next/previous page or after changing No. of rows

peterbrapeterbra Posts: 7Questions: 0Answers: 0
edited September 2012 in General
I have strange issue with DataTable. I am using this stuff to delete row and all is working (row is deleted from DB, alerts showing properly), and it removes row from display BUT when I click previous page and come back to the page where row was displayed originally (by page I mean DataTable page number or I increase number of rows per page) - IT IS SHOWING AGAIN...(as it was not actually removed) only after hard-refresh it is removed ? Why is this happening and how to really remove it without actually refreshing the browser?

Here is the code I am using to delete row:

[code]
$(document).ready(function() {
$('#publishers').dataTable( {
"iDisplayLength": 50,
"sPaginationType": "full_numbers",
"bStateSave": true
} );
var oTable = $('#publishers').dataTable();
} );

function DeletePublisher(element, publisherid) {
jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher', function (r) {
if (r) $.post('includes/publishers/delete-publisher.php?publisherid=' + publisherid,

function (data) {
if ($.trim(data) == 'error') {
$.jGrowl('This publisher was already deleted', {
header: 'ERROR'
});
} else {
$(element).parents('tr').remove();
var nTr = $(element).closest('tr');
oTable.fnDeleteRow(nTr, null, true);
oTable.fnDestroy();
oTable.fnDraw();

$.jGrowl('Publisher deleted');
}
});
});
[/code]


and in table i am calling it like:

[code]


Edit
Delete


[/code]


[/code]

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    > oTable.fnDestroy();

    Why destroy the table and then attempt to draw it? I'm actually surprised that isn't throwing a JS error.

    Allan
  • peterbrapeterbra Posts: 7Questions: 0Answers: 0
    Well, it won't work with that or without.... and no errors... row just keep appearing after changing page... so far only browser refresh works :(
  • peterbrapeterbra Posts: 7Questions: 0Answers: 0
    I tried this and this is almost working (it really removes row, but always FIRST one):
    parents('tr').remove(); will remove correct row but this isn't the case....
    any advice how to fix this to actually remove the row where button is ?

    [code]
    function DeletePublisher(element, publisherid) {
    jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher', function (r) {
    if (r) $.post('includes/publishers/delete-publisher.php?publisherid=' + publisherid,
    function(data) {
    if ($.trim(data) == 'error') {
    $.jGrowl('This publisher was already deleted', { header: 'ERROR' });
    $(element).parents('tr').remove();
    } else {
    //$(element).parents('tr').remove();
    var nTr = $(element).closest('tr');
    $('#publishers').dataTable().fnDeleteRow(nTr);

    $('tr').removeClass();
    // Now add class names again
    $('tr:odd').addClass('odd');
    $('tr:even').addClass('even');
    $.jGrowl('Publisher deleted');

    }
    });
    });
    [/code]
This discussion has been closed.