help with fnDisplayStart()
help with fnDisplayStart()
I'm having trouble getting this routine to reset the start page. I'm using bserverside = false and bstatesave = true, meaning the JSON data gets retrieved once, the user can paginate through it client side and the current page is remembered so if you leave the page and come back you're on the same page. The problem is that in some cases I want to put the user back to page 0. Here's my code so far:
$(document).ready(function () {
var oPaymentsTable = $('#payments').dataTable({
"bJQueryUI": true,
"bServerSide": false,
"sAjaxSource": "myAjaxSource",
"sPaginationType": "full_numbers",
"bStateSave": true
})
var oTable = $('#payments').dataTable();
oTable.fnDisplayStart(0); //this will be a property of the model, but I'm assuming 0 for now
$.fn.dataTableExt.oApi.fnDisplayStart = function ( oSettings, iStart, bRedraw )
{
if ( typeof bRedraw == 'undefined' )
{
bRedraw = true;
}
oSettings._iDisplayStart = iStart;
oSettings.oApi._fnCalculateEnd( oSettings );
alert(iStart); // this is correctly 0
if ( bRedraw )
{
alert('redraw'); // I get to here
oSettings.oApi._fnDraw( oSettings );
}
};
The bStateSave is working fine, and the table goes back to the page they were on. The problem is if I come through fresh from the server and detect that I need to reset the start page, it still shows the page that's saved in the cookie from bStateSaved. The alerts tell me I'm in the plug-in code, and I get to the fnDraw, but I never get back to page 0.
In 1.7.5 I was setting _iDisplayStart directly (without the plug-in) and it was working fine, but since I switched to 1.9.4 I can't get it to reset the page to 0. I feel like I must be doing something out of order or missing a step. Thanks in advance for any help.
-Harriet
$(document).ready(function () {
var oPaymentsTable = $('#payments').dataTable({
"bJQueryUI": true,
"bServerSide": false,
"sAjaxSource": "myAjaxSource",
"sPaginationType": "full_numbers",
"bStateSave": true
})
var oTable = $('#payments').dataTable();
oTable.fnDisplayStart(0); //this will be a property of the model, but I'm assuming 0 for now
$.fn.dataTableExt.oApi.fnDisplayStart = function ( oSettings, iStart, bRedraw )
{
if ( typeof bRedraw == 'undefined' )
{
bRedraw = true;
}
oSettings._iDisplayStart = iStart;
oSettings.oApi._fnCalculateEnd( oSettings );
alert(iStart); // this is correctly 0
if ( bRedraw )
{
alert('redraw'); // I get to here
oSettings.oApi._fnDraw( oSettings );
}
};
The bStateSave is working fine, and the table goes back to the page they were on. The problem is if I come through fresh from the server and detect that I need to reset the start page, it still shows the page that's saved in the cookie from bStateSaved. The alerts tell me I'm in the plug-in code, and I get to the fnDraw, but I never get back to page 0.
In 1.7.5 I was setting _iDisplayStart directly (without the plug-in) and it was working fine, but since I switched to 1.9.4 I can't get it to reset the page to 0. I feel like I must be doing something out of order or missing a step. Thanks in advance for any help.
-Harriet
This discussion has been closed.
Replies
Allan
var oTable = $('#payments').dataTable();
oTable.fnPageChange( 'first' );
alert('past first');
I get the alert so I know it gets there, but the page is still on the one saved to the cookie by bStateSave, not the first page.
"fnInitComplete": function () {
this.fnPageChange( 'first' );
}
So I have to assume my issue all along has been that the table wasn't "ready".
Thanks for your help Allan. - Harriet
Good to hear it works for you now.
Allan