fnDeleteRow is resetting current page
fnDeleteRow is resetting current page
I'm using fnDeleteRow to remove a specific row. The problem is that if the user is in a different page than 1, after the row is removed, the user is back at page 1, altough he/she removed the item in another page, e.g.: 4.
[code]
var datatable_test = $("#datatable_test").dataTable({
"bStateSave": true,
"bLengthChange": true,
"bFilter": true,
"bInfo": true,
"bPaginate": true,
"bAutoWidth": false,
"aaSorting": [],
"aoColumnDefs": [{
"aTargets": [-1],
"bSortable": false,
"bSearchable": false,
"mRender": function(data){
return "delete";
}
}],
"bProcessing": true
});
$(".action_delete").click(function(e){
e.preventDefault();
var row = $(this).closest("tr").get(0);
var id = $(this).attr("id");
$.post("helper.php", { action: "delete", id: id }).done(function(){
$(row).fadeOut("fast", function(){
datatable_test.fnDeleteRow(datatable_test.fnGetPosition(row));
});
});
});
[/code]
The user should remain in page 4 after the item is removed.
[code]
var datatable_test = $("#datatable_test").dataTable({
"bStateSave": true,
"bLengthChange": true,
"bFilter": true,
"bInfo": true,
"bPaginate": true,
"bAutoWidth": false,
"aaSorting": [],
"aoColumnDefs": [{
"aTargets": [-1],
"bSortable": false,
"bSearchable": false,
"mRender": function(data){
return "delete";
}
}],
"bProcessing": true
});
$(".action_delete").click(function(e){
e.preventDefault();
var row = $(this).closest("tr").get(0);
var id = $(this).attr("id");
$.post("helper.php", { action: "delete", id: id }).done(function(){
$(row).fadeOut("fast", function(){
datatable_test.fnDeleteRow(datatable_test.fnGetPosition(row));
});
});
});
[/code]
The user should remain in page 4 after the item is removed.
This discussion has been closed.
Replies
Allan
[code]
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings ) {
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
"iTotalPages": Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
};
}
//when deleting...
var page_number = datatable_test.fnPagingInfo().iPage;
datatable_test.fnDeleteRow(datatable_test.fnGetPosition(row), function(){datatable_test.fnPageChange(page_number);}, false);
[/code]
Allan
http://jsfiddle.net/andufo/s5pVC/3/