fnDeleteRow is resetting current page

fnDeleteRow is resetting current page

asantosasantos Posts: 11Questions: 0Answers: 0
edited February 2014 in General
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.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    There isn't a way in DataTables 1.9 to stay on the current page after a delete. The new API in 1.10 which is going into beta today though will have that ability - the `draw()` function: `table.row( row ).remove().draw( false );` would do it with 1.10.

    Allan
  • asantosasantos Posts: 11Questions: 0Answers: 0
    Hi, I am using 1.10, i kind of resolved this issue by using this implementation

    [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]
  • asantosasantos Posts: 11Questions: 0Answers: 0
    @allan the problem with your recommendation, is that it doesn't automatically update the bInfo information (current records, etc). Is there a way to trigger that info update?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It should do! It should be doing a full draw but keeping the page. Can you link me to a test case showing the problem please.

    Allan
  • asantosasantos Posts: 11Questions: 0Answers: 0
    edited February 2014
    Sure @allan, here is a working link of my example:

    http://jsfiddle.net/andufo/s5pVC/3/
This discussion has been closed.