Pagination Bugs
Pagination Bugs
ajaxboy
Posts: 17Questions: 0Answers: 0
The pagination/ ajax pagination is very buggy.
When it prints the numbers at the bottom, the first page might work but then it constantly sends the wrong parameters from the pagination numbers which causes to get the same or wrong data
This is my initial code:
[code]
$(document).ready(function() {
$('#items_list').dataTable( {
"sPaginationType": "full_numbers",
"aaSorting": [[ 0, "desc" ]],
"bProcessing": false,
"bServerSide": true,
"sAjaxSource": "ajax.php?controller=datasource&function=table_page"
} );
} );
[/code]
note that i am using desc order, this might add a little twist
When it prints the numbers at the bottom, the first page might work but then it constantly sends the wrong parameters from the pagination numbers which causes to get the same or wrong data
This is my initial code:
[code]
$(document).ready(function() {
$('#items_list').dataTable( {
"sPaginationType": "full_numbers",
"aaSorting": [[ 0, "desc" ]],
"bProcessing": false,
"bServerSide": true,
"sAjaxSource": "ajax.php?controller=datasource&function=table_page"
} );
} );
[/code]
note that i am using desc order, this might add a little twist
This discussion has been closed.
Replies
iTotalDisplayRecords solves this issue
got it work to a point where all pages work 1, 2, 3, 4, etc... but when clicking the pages backward, like from 4, then 3, then 2, etc.. it doesn't work.. and it keeps adding to 'sEcho' even when going backwards
Its the draw number - http://datatables.net/usage/server-side
Can you link us to your page please so I can see what might be going wrong (although it would be worth reading through the server-side processing documentation linked above to make sure that your script is returning the expected parameters, given that sEcho currently isn't).
Allan
I now realize that you do not pass a page number, and maybe sEcho is supposed to add up..
How I am calculating the pagination is by making use of the page number
$current_offset = $max_count - ($iDisplayLength * ($page_number -1));
The script is returning all the expected parameters, but does not pass the page number, so I was thinking sEcho was some sort of page number..
I just started working on this script recently so it is no where near fully functional.. but you can test it .. and see that initially it works sEcho passes the number of pages, and there is no way back to previous pages
http://99.135.238.187/phpbugs/index.php
please note that the url above will stop working as soon as I change my ip.
On first load of your page I see the following in the JSON:
[code]
"iDisplayStart":"120","iDisplayLength":20,"sEcho":1,"iTotalRecords":36,"iTotalDisplayRecords":36
[/code]
That looks okay - iDisplayStart and iDisplayLength have no meaning in the return from the server (as noted in the documentation), so DataTables will ignore them - but that's fine.
Then I page forward one page and get:
[code]
"iDisplayStart":"10","iDisplayLength":20,"sEcho":"2","iTotalRecords":36,"iTotalDisplayRecords":36
[/code]
This also looks fine (again ignoring the first two parameters shown):
And then page back to the first page:
[code]
"iDisplayStart":"120","iDisplayLength":20,"sEcho":1,"iTotalRecords":36,"iTotalDisplayRecords":36
[/code]
This is going to be ignored because sEcho is a draw count as I mentioned, not a page number From the docs:
> An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.
So that looks like the problem to me.
Allan
As for security matters, I am fully aware.. and right now I am just focusing on getting it working locally.. I have not gotten to even the first stage in security so that is really not a concern right now.. I'll get there when I have a more operational system.. (I even removed some security just to make easier to test, for the time being)
Allan