Ajax Reload without jumping to the first page
Ajax Reload without jumping to the first page
MathiasWeisheit
Posts: 7Questions: 0Answers: 0
It's nearly similar to that post:
http://datatables.net/forums/comments.php?DiscussionID=643&page=1
I use also the function fnReloadAjax;
But it is necessary that after realoading the data the page keeps on the same like before. It should not jump to the first page.
How can I achieve this?
http://datatables.net/forums/comments.php?DiscussionID=643&page=1
I use also the function fnReloadAjax;
But it is necessary that after realoading the data the page keeps on the same like before. It should not jump to the first page.
How can I achieve this?
This discussion has been closed.
Replies
What you can do is something like this:
[code]
var iCurrentPage = oTable.fnSettings()._iDisplayStart;
oTable.fnReloadAjax( null, function (o) {
o._iDisplayStart = iCurrentPage;
oTable.fnDraw();
} );
[/code]
I've also made a small update to the fnReloadAjax plug-in to allow for this (it needed a null check): http://datatables.net/plug-ins/api#fnReloadAjax
Let me know how you get on with that :-). I'll have a look at including this into the fnReloadAjax plug-in in future.
Regards,
Allan
var oCurrentSettings = CDL.jqDataTable.fnSettings();
var iCurrentPage = oCurrentSettings._iDisplayStart;
CDL.jqDataTable.fnReloadAjax( null, function (o) {
o._iDisplayStart = iCurrentPage;
CDL.jqDataTable.fnDraw();
});
[/code]
now jquery raises an error e.url is null;
my AjaxReload Function:
[code]
$.fn.dataTableExt.oApi.fnReloadAjax = function(oSettings, sNewSource,
fnCallback) {
if (typeof sNewSource != 'undefined' && sNewSource != '') {
oSettings.sAjaxSource = sNewSource;
}
this.oApi._fnProcessingDisplay(oSettings, true);
var that = this;
oSettings.fnServerData(oSettings.sAjaxSource, null, function(json) {
/* Clear the old information from the table */
that.oApi._fnClearTable(oSettings);
/* Got the data - add it to the table */
for ( var i = 0; i < json.aaData.length; i++) {
that.oApi._fnAddData(oSettings, json.aaData[i]);
}
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
that.fnDraw(that);
that.oApi._fnProcessingDisplay(oSettings, false);
/* Callback user function - for event handlers etc */
if (typeof fnCallback == 'function') {
fnCallback(oSettings);
}
});
};
[/code]
[code]
var oSettings = CDL.jqDataTable.fnSettings();
var iCurrentDisplayLength = oSettings._iDisplayLength;
var iCurrentDisplayStart = oSettings._iDisplayStart;
CDL.jqDataTable.fnReloadAjax();
oSettings._iDisplayLength = iCurrentDisplayLength ;
oSettings._iDisplayStart = iCurrentDisplayStart;
CDL.jqDataTable.fnDraw(oSettings);
//CDL.jqDataTable.oApi._fnDraw(oSettings);
[/code]
[code]
if (typeof sNewSource != 'undefined' && sNewSource != '') {
[/code]
null is not the same as '' (which is an empty string - null is an absence of data), and as such 'null' is being assigned to the DataTables Ajax source parameter - which I would say is the cause for the error you are seeing. If you change the if condition to test for null (or pass in a blank string rather than null) this hopefully it will work as expected :-)
Regards,
Allan
I also tried to set the settings-object directly.
[code]
var oCurrentSettings = CDL.jqDataTable.fnSettings();
var iCurrentPage = oCurrentSettings._iDisplayStart;
CDL.jqDataTable.fnReloadAjax( '', function (o) {
o._iDisplayStart = iCurrentPage;
CDL.jqDataTable.dataTableSettings[0]._iDisplayStart = iCurrentPage;
CDL.jqDataTable.fnDraw();
});
[/code]
[code]
oTable.fnReloadAjax( null, null, true );
[/code]
The new part is the third parameter which when true does a standing redraw. If you copy the new plug-in source, hopefully this will do the job for you!
Allan
It works.
I'll try to test it in the complete application.
Use this "bStateSave": true
The function from allan works!