iDisplayStart with bServerSide

iDisplayStart with bServerSide

koalakoala Posts: 1Questions: 0Answers: 0
edited November 2013 in Bug reports
Hi all!

I don't know exactly if it is a bug or not. I've spent several hours and got it worked.
My aim was to save state of my datatable with hash in address bar (it is sometimes iseful, you know)

Finally i wrote this function:
[code]
function setTable() {
if (!just_drawn)
{
var hSettings = $.deparam.fragment();
var cSettings = oTable.fnSettings();
cSettings.iInitDisplayStart = hSettings.offset === undefined ? 0 : parseInt(hSettings.offset);
cSettings._iDisplayStart = hSettings.offset === undefined ? 0 : parseInt(hSettings.offset);
oTable.fnDraw();
}
}
...
$(window).bind('hashchange', setTable);
[/code]
just_drawn is a global var that helps me to prevent loops.

The point is that iInitDisplayStart is not described anywhere, i found it in source code (thanks for non-minified version), but one must use it if his oTable defined with bServerSide = true. It caused by these lines of datatables code, i think:
[code]
/* Check and see if we have an initial draw position from state saving */
if ( 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 );
}
[/code]

All this stuff is looking very confusing, probably there is some way to patch it?

Nevertheless, thank you for really great plugin!

P.S. btw, integration with bbq was also quite tricky (because of loops, mainly) and i still have not realized all of the reasons. I think, it would be very useful to create the plugin for such integration or include it in next version.

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    The settings object in DataTables (fnSettings / oSettings) is considered to be private, and shouldn't generally be manipulated externally. That's why its properties aren't well documented - its not an API.

    Having said that, DataTables 1.10 has a new API method called `page()` which can be used to set the display start point if you need to. I'm still writing the documentation for 1.10 though...

    Also there is actually a plug-in for setting the display start in 1.9 already: http://datatables.net/plug-ins/api#fnDisplayStart

    Allan
This discussion has been closed.