Server-side processing, pagination, rowGrouping and fnDisplayRow plugin; almost works...

Server-side processing, pagination, rowGrouping and fnDisplayRow plugin; almost works...

Danly_DanDanly_Dan Posts: 7Questions: 0Answers: 0
edited March 2012 in Plug-ins
I am initializing datatable as follows:

[code]
var oTable = "";

$(document).ready(function() {

oTable = $('#products').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bScrollCollapse": true,
"sScrollY": "600px",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/admin/analytics/load-items",
"sServerMethod": "POST",
"iDisplayLength": 100
}).rowGrouping();

});
[/code]

With this I am successfully having pagination work and can go page to page and have it load the proper entries. However, I have a custom button added to rows in order to delete any given one with the following code:

[code]
$( ".del-item" ).live("click", function() {
var row_id = $(this).attr('id');
var rowtr = $(this).closest('tr');
var rerow = rowtr.prev('tr');

$( "#dialog-confirm" ).dialog({
resizable: false,
dialogClass: 'add-dialog',
height:245,
width: 325,
modal: true,
buttons: {
"Delete Item": function() {
$.post("/path/to/delete/script",{'row_id':row_id},
function(data){
//code to do after a successful post
oTable.dataTable().fnDeleteRow(rowtr, null, false);
}, "json");
$( this ).dialog( "close" );

oTable.fnDisplayRow(rerow);
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
[/code]

As soon as the [code]oTable.fnDisplayRow(rerow)[/code] runs the proper location and row is shown, but the page value is set to the previous page. This is where the issue comes into play because with the previous page being highlighted, if I do another delete, the posted iDisplayStart is now a page off and so the loaded rows ends up being that. Each subsequent request then goes back another page until at the first record set.

Am I missing something in my implementation?

Replies

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Hi,

    I've just added a comment to your other thread here: http://datatables.net/forums/discussion/9505 which I think is basically the same problem. Ultimately rather than calling fnDeleteRow I think you should simply call fnDraw() to get the new data from the server - you are sending a delete Ajax request to the server, so you just need to get the new data that the server knows about.

    Regards,
    Allan
This discussion has been closed.