Why is a delay need for fnPageChange?

Why is a delay need for fnPageChange?

streetlightstreetlight Posts: 26Questions: 0Answers: 0
edited October 2012 in General
Hey all,

I'm running into a strange issue, and it's happening across a few sites I maintain that use datatables.

Whenever I utilize fnPageChange, it does not work unless there is a setTimeout around it like this;

[code]setTimeout(function() { oTable.fnPageChange(whatPage); }, 100);[/code]

or with an alert before it
[code]alert('starting'); oTable.fnPageChange('last');[/code]

I understand this may be a sequence error of some sort, but I'm just unsure why the same issue would arise across multiple projects.

Here is the delete function I'm working with now:

[code]
function fnDelete(elem){
if (selected.length>0) {
var c;
c = confirm('Are you sure you want to delete the selected ${displayTableName}?');
if (c) {
// Create delete url from editor url...
var deleteURL = (urlstr.substring(0, urlstr.lastIndexOf('/') + 1)) + "delete.do";
deleteRecord(deleteURL,selected[0]);

if ( $('tableViewer tr').length === 0) {
// Reload the Table
oTable.fnPageChange('last');
//Send them back to the last page
}
}
}

}
[/code]

Does anyone know what the issue is?

Replies

  • allanallan Posts: 63,394Questions: 1Answers: 10,450 Site admin
    What does `deleteRecord` do - is it async Ajax?

    Allan
  • streetlightstreetlight Posts: 26Questions: 0Answers: 0
    edited October 2012
    It is -- however, it wasn't always, so when I added it I expected it to work but for some reason it hasn't been. Here's the code below:

    [code]
    function deleteRecord(deleteURL, iid){
    var didDelete = false;
    jQuery.ajax({
    type: "POST",
    url: deleteURL,
    dataType:"html",
    data:"recordID="+iid,
    async:false,
    success:function(response){
    didDelete = true;
    oTable.fnDraw(true);
    selected = [];
    selectedRecord = [];
    enableButtons(selected);
    },
    error:function (xhr, ajaxOptions, thrownError){
    if ((xhr.status >=400) && (xhr.status < 500))
    alert(xhr.responseText);
    else
    alert('error');
    }
    });

    return didDelete;
    }
    [/code]

    Thank you so much for being so active with this product!
  • allanallan Posts: 63,394Questions: 1Answers: 10,450 Site admin
    > async:false,

    So just to confirm - it works with this in does it? Without the async flag, you'd need to do the delete in the Ajax callback - otherwise you might well run into synchronicity issues.

    Allan
  • streetlightstreetlight Posts: 26Questions: 0Answers: 0
    Sorry for not being clear -- the solution does not work. So I should place it in the deleteRecord?
  • allanallan Posts: 63,394Questions: 1Answers: 10,450 Site admin
    Well with the async:false above, there shouldn't be any synchronicity issues - unless you are using server-side processing? Failing that, we'd need a link to the page to see what is going on I think.

    Allan
This discussion has been closed.