I have a page which normally displays 10 items per page and shows the page numbers at the bottom of the page as below:
<prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 next>
where each of the above is a page number and each page displays 10 items in turn.
There is a search option on this page which can be used to search the items by 'keywords' or 'categories'. When the search is done say, with a keyword 'sports', it displays the correct number of items but the page numbers at the bottom of the page displays the whole menu rather than showing,
<prev 1 2 next>
if there are under 20 items corresponding to that item search.
I am new to javascript and would like to know how the correct page number menu can be displayed based on the number of items pulled for each 'category' or 'keyword'.
It seems to me like you may be referring to a server-side language, like php, ruby or python. Most pagination isn't done on the front-end, unless you're using ajax. Can you describe what you use for your back-end scripting? ...and how it connects to your javascript?
I am sorry. I must have miread your initial question. I was assuming you wanted to control the actual pagination with javascript. The amount of links displayed should be governed by your php scripting. If you're using a CMS, like wordpress, or if you're using some MVC framework, you're going to have to look for the view helper that controls your pagination. The amount of links displayed should be the amount of pages your application returns. This is the amount of total results divided by the rows per page. The page number is the offset in your database query that tells it where to start. It's the offset + 1 for readability, ie. page 0 is 1 and so on. So, you're going to need to work with whomever writes your back-end scripting and have them change that. This problem cannot be solved using javascript, which is what this particular thread is for. So, in short, your php has to deal with echoing out the correct amount of links. Google the term pagination, should you need to get some more information.
You are right, below is the code that is doing it in php. We use a software called PRADO. The code looks correct to me but displays all the page numbers at the bottom rather than 2 pages for an item count between 10-20.
....then can you find the view helper that creates it or the documentation? It might be just something that 'pager' needs, like an optional parameter or something.
The only thing I can think of is this: when it doesn't get a result set larger than 10, it must default to something else. I mean, if you have 10 results and 10 results per page, you still have 1 page. I am not sure if you have to set this, either way, or not.
I'd suggest trying to set the page count, no matter what. I would think the pager should take care of dealing with showing it or not. If that doesn't work, I am out of suggestions. You may want to hop on the PRADO forum and see if they have any suggestions. Wish I could be of more help. ......but try setting the page count no matter how many results there are....if there's one page...set it to one....
Thanks for your response. If you look at the below code, the line in bold is doing that, either way setting the page count depending on the records returned but this is not working in actuality.
I tried refering to the documentation and did not find anything useful.
Is there a way to write a custom php function that could do this?
Bookmarks