Why is a delay need for fnPageChange?
Why is a delay need for fnPageChange?
streetlight
Posts: 26Questions: 0Answers: 0
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?
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?
This discussion has been closed.
Replies
Allan
[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!
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
Allan