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
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]
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]
This discussion has been closed.
Replies
Why destroy the table and then attempt to draw it? I'm actually surprised that isn't throwing a JS error.
Allan
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]