iDisplayStart with sorting
iDisplayStart with sorting
greattall1
Posts: 7Questions: 0Answers: 0
Hi,
I am doing server-side processing for pagination and sorting on my datagrid. I just enabled the sorting functions on my dataTable (bSort, aaSorting, bSortable, etc.) and I am noticing that iDisplayStart is always 0 when the table is initialized.
I am retaining the values of iDisplayStart and iDisplayLength in cookies so that I can recall them when the user does a browser back. Is there a way I can keep iDisplayStart from being reset to 0 when the table is initialized? All of my pagination and sorting is done server-side so there should be no reason on the UI side for these values to be reset.
I am doing server-side processing for pagination and sorting on my datagrid. I just enabled the sorting functions on my dataTable (bSort, aaSorting, bSortable, etc.) and I am noticing that iDisplayStart is always 0 when the table is initialized.
I am retaining the values of iDisplayStart and iDisplayLength in cookies so that I can recall them when the user does a browser back. Is there a way I can keep iDisplayStart from being reset to 0 when the table is initialized? All of my pagination and sorting is done server-side so there should be no reason on the UI side for these values to be reset.
This discussion has been closed.
Replies
You can pass "iDisplayStart" as an initialisation parameter: http://datatables.net/usage/options#iDisplayStart . Slightly confusing with two iDisplayStart parameters.... :-)
Hope that helps,
Allan
I initially was passing iDisplayStart as an initialization parameter from a value that I was reading out of a cookie. From what I can tell, bSaveState sets the value also when it is true. When I set bSort to true, my value for iDisplayStart is ignored.
Yes this is correct. The assumption was that if you have state saving enabled, then it would override the iDisplayStart initialisation parameter - since it would be typical to want to restore the last state fully.
There are two ways around this for you:
1. Change the code in DataTables - it's just a case of swapping to 'if' blocks around. Find the line "oSettings.iInitDisplayStart = oInit.iDisplayStart;" (near the end of the file) and put that code block below the state saving one, which is currently just after it.
2. Once the table is drawn, set oTable.fnSettings()._iDisplayStart = {whatever}; and redraw the table. Probably a little easier - but not quite as slick :-)
Regards,
Allan
oSettings._iDisplayStart = 0; /* reset display back to page 0 */
This seems incorrect to me - _fnSort is called from the constructor. This means that the displayStart will always be reset to 0 when sorting is enabled, completely ignoring the saved state that we are trying to initialize the grid with (i.e. that the iDisplayStart != 0 because you are coming back to the page via browser back).
The problem is, that you do want to reset iDisplayStart on the event of a new sort, because the result set will restart from the beginning again. Anyways, I will keep looking into this and post the solution I come up with.
if (oSettings.iServerDraw > 1) {
oSettings._iDisplayStart = 0; /* reset display back to page 0 */
}
This works for me cuz I dont get my data until _fnDraw() is called because everything is server-side. Not sure if it works in all cases, tho.
The sort jumps the paging back to the start for usability reasons. It is possible to overrule DataTables in this matter by doing something exactly like you have done :-). It's perhaps an option that I should put into DataTables at some point.
Regards,
Allan
Allan
Changed function _fnFilterComplete in datatables like this....
/* Redraw the table */
if (!oSettings.iStayOnPage == true) {
oSettings._iDisplayStart = 0; /* reset display back to page 0 */
}
Doing the following in my script...
oTable.fnSettings().iStayOnPage = true;
oTable.fnUpdate(tags.join(","), aPos, 9);
oTable.fnSettings().iStayOnPage = false;
...
@allan: maybe it's a good idea to add such functionality to fnUpdate by a extra input parameter...
Allan
Did you finally add the "StayOnPage" feature ?
Thanks in advance for your answer.