Server Side Processing and iDisplayStart
Server Side Processing and iDisplayStart
![Viras](https://secure.gravatar.com/avatar/6286a6bc429f7923533fe9f31514a3ff/?default=https%3A%2F%2Fvanillicon.com%2F6286a6bc429f7923533fe9f31514a3ff_200.png&rating=g&size=120)
Hi!
I'm using the DataTables plugin with ServerSide Processing. This works perfectly fine, however as soon as I set the 'iDisplayStart' value on table initialization (using the 'iDisplayStart' option), it seems to get out of sync. The Pagination buttons show the correct page, but the GET variable passed to the server side script is always 0.
As soon as I click a pagination button, it works again. This only seems to happen for the first time call when a 'iDisplayStart' is passed to the constructor.
Any advice? I guess this is a bug :).
I'm using the DataTables plugin with ServerSide Processing. This works perfectly fine, however as soon as I set the 'iDisplayStart' value on table initialization (using the 'iDisplayStart' option), it seems to get out of sync. The Pagination buttons show the correct page, but the GET variable passed to the server side script is always 0.
As soon as I click a pagination button, it works again. This only seems to happen for the first time call when a 'iDisplayStart' is passed to the constructor.
Any advice? I guess this is a bug :).
This discussion has been closed.
Replies
[code]
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../examples_support/server_processing.php",
"iDisplayStart": 10
} );
[/code]
on this page: http://datatables.net/examples/data_sources/server_side.html - and it seems to work as expected. Are you using 1.6.2?
Allan
After debugging I found this place in the code which sets oSettings._iDisplayStart to 0. (function _fnFilterComplete)
[code]/* Redraw the table */
oSettings._iDisplayStart = 0;
_fnCalculateEnd( oSettings );
_fnDraw( oSettings );[/code]
If I replace it with this older part of code it works:
[code]if ( typeof oSettings.iInitDisplayStart != 'undefined' && oSettings.iInitDisplayStart != -1 )
{
oSettings._iDisplayStart = oSettings.iInitDisplayStart;
oSettings.iInitDisplayStart = -1;
}
else
{
oSettings._iDisplayStart = 0;
}
_fnCalculateEnd( oSettings );
_fnDraw( oSettings );[/code]
Allan
Sorry for my delayed answer. Unfortunately I can't show you a live example of the datatables in action, as I don't have a place to host it yet.
However here are the relevant parts:
[code]dataTablesObj = $( "#vehiclesList" ).dataTable( {
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bFilter": false,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "index.php?module=list_dataTables",
"fnDrawCallback": function() {
$("a[rel^='prettyPhoto']").prettyPhoto( { theme: 'dark_rounded' } );
},
"aaSorting": [[2,"asc"]],
"iDisplayLength": 10,
"iDisplayStart": 20
} );[/code]
This shows the complete initialisation (actually I'm using dynamic values for iDisplayLength and iDisplayStart but to make sure that the error doesn't come from there, I used static values).
Still the iDisplayStart value passed to the server-side-script is 0, all other values are set correctly.
http://img17.imageshack.us/img17/8199/paginationbuttons.jpg
http://img717.imageshack.us/img717/8995/getoutput.jpg
First one shows the pagination buttons, they display correctly. The second one shows a var_export of the $_GET array with the wrong value set to iDisplayStart!
Here is the fix. Replace the following code in _fnDraw:
[code]
/* If we are dealing with Ajax - do it here */
if ( oSettings.oFeatures.bServerSide &&
!_fnAjaxUpdate( oSettings ) )
{
return;
}
/* Check and see if we have an initial draw position from state saving */
if ( typeof oSettings.iInitDisplayStart != 'undefined' && oSettings.iInitDisplayStart != -1 )
{
oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
0 : oSettings.iInitDisplayStart;
oSettings.iInitDisplayStart = -1;
_fnCalculateEnd( oSettings );
}
[/code]
with:
[code]
/* Check and see if we have an initial draw position from state saving or initilaisation */
if ( typeof oSettings.iInitDisplayStart != 'undefined' && oSettings.iInitDisplayStart != -1 )
{
if ( oSettings.oFeatures.bServerSide )
{
oSettings._iDisplayStart = oSettings.iInitDisplayStart;
}
else
{
oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
0 : oSettings.iInitDisplayStart;
}
oSettings.iInitDisplayStart = -1;
_fnCalculateEnd( oSettings );
}
/* If we are dealing with Ajax - do it here */
if ( oSettings.oFeatures.bServerSide &&
!_fnAjaxUpdate( oSettings ) )
{
return;
}
[/code]
I'll make sure this is in the next release of DataTables.
Regards,
Allan
First, sorry for my English...)))
but this fix(7 post) don`t work for me....I have
[code]
"bServerSide": true,
"sAjaxSource": "my.php",
"fnServerData": fnXml2Json,
"fnRowCallback": fnRow_ch,
[/code]
if i go to second page and click on button wich call oTable.fnDraw then table show me first page...but i need to stay on second...i use datatable 1.6.2...
Try passing 'false' to fnDraw ( oTable.fnDraw( false ) for example). As the documentation says ( http://datatables.net/api#fnDraw ): bool (optional): indicate if the redraw should be complete (i.e. re-sort and re-filter), which has the side effect of resetting the pagination, or just update the display as it is. Default - true.
Regards,
Allan
http://datatables.net/forums/comments.php?DiscussionID=1727&page=1#Item_0
But can be more simple way, than specified there?