Show limited no. of page links in pagination

I want to display a limited no. of page links, say 5 out of 10 links, and was wondering is there any known or tried and tested method to achieve this.

so lets say user can right now see following links

previous, 1(selected), 2, 3, 4, 5... next

user clicks on, say 4, now he sees

previous... 3, 4(selected), 5, 6, 7...next

now he clicks on 7

previous... 6, 7(selected), 8, 9, 10...next

Now I believe this to be something very common in pagination programming. So is there any known algo to do this. I am feeling too lazy to cookup my own!

Edit:- This needs to be achieved on the server side. I am working on C#, however you can pitch in algo in any language.

Check out jQuery and the pagination plugin...

http://plugins.jquery.com/project/pagination

Design suggestion for pagination with a large number of pages , How to limit the function of paging down to stop at number 10? Eg: pages: 1 2 3 4 5 6 7 8 9 10. function kriesi_pagination($pages� Constructing Pagination Links. Normally, with pagination, your goal isn't to concatenate all of the possible results, but rather, to produce a set of navigation, like this: Let's sketch out a micro-version of what that might entail. From the code above, we already know we can get the number_of_pages in the paginated results from the first call:

The problem with some of the answers, especially with Tyrone's is that it only updates the navigation when the remainder is 0, if you want it to update on every click then the following is much better:

var start,
end,
pagesCutOff = 5, 
ceiling = Math.ceil(pagesCutOff / 2),
floor = Math.floor(pagesCutOff / 2);

if(numPages < pagesCutOff) {
    start = 0;
    end = numPages;
} else if(currentPage >= 1 && currentPage <= ceiling) {
    start = 0;
    end = pagesCutOff;
} else if((currentPage + floor) >= numPages) {
    start = (numPages - pagesCutOff);
    end = numPages;
} else {
    start = (currentPage - ceiling);
    end = (currentPage + floor);
}

Obviously you send through the currentPage and numPages yourself to the function, this will keep the current page centered in the pagination list, the number of buttons shown should be an odd number so that the selected page can be "in the middle" of the list.

You can then do the following loop:

for (var i = start; i < end; i++) {
    //Your code here
}

If you want to add a next and previous button to this then simply do something like:

        if(currentPage !== 1) {
            $('<a href="javascript:void(0);" class="paginate-link" rel="' + (parseInt(currentPage) - 1) + '">&lt; Previous</a>').appendTo(navElement);
        }

Where navElement is a jQuery object of where you want to append the list to like: $('#pagination-nav');

Hope this helps someone!

Cheers

Limited number of paging to 10 "pages: 1 10", Hi, I've seen in several places that the ability to limit the number of page links in the pagination is on the development path, saw this on a� Description # Description. Technically, the function can be used to create paginated link list for any area. The ‘base’ argument is used to reference the url, which will be used to create the paginated links.

Tested this and it works even though it could be a little more graceful. I am using C# here, but the logic for any language should be the same. If you come up with a better solution please post. If you have any questions please post to. I have commented the code to help better explain what is going on.

        //Get the current page we are on
        int start = currentPage;
        int end = currentPage;

        //If the page cannot be devised by 5 enter the loop
        if ((start % 5 != 0) && (end % 5 != 0))
        {
            //Get the next nearest page that is divisible by 5
            while ((end % 5) != 0)
            {
                end++;
            }

            //Get the previous nearest page that is divisible by 5
            while ((start % 5) != 0)
            {
                start--;
            }
        }
        //The page is divisible by 5 so get the next 5 pages in the pagination
        else
        {
            end += 5;
        }
        //We are on the first page
        if (start == 0)
        {
            start++;
            end++;
        }
        //We are on the last page
        if (end == lastpage)
        {
            end = lastpage;
        } 

        //Post your pagination links below
        for (int i = start; i < end; i++)
        {
           //Your code here
        }

Limit the number of page links in the pagination, Pagination, also known as paging, is the process of dividing a document into discrete pages, The number and size of electronic pages in a document are limited by the amount of computer data storage, not by the display Pagination also includes the logic of preparing and displaying the links to the various pages. Bootstrap pagination is a component used when content is divided into separate pages to display the page numbers and enable navigation between them.

The problem with some of the answers, especially with Tyrone's is that it only updates the navigation when the remainder is 0, if you want it to update on every click then the following is much better:

   //Get the current page we are on
    int start = currentPage;
    int end = currentPage;

    //If the page cannot be devised by 5 enter the loop
    if ((start % 5 != 0) && (end % 5 != 0))
    {
        //Get the next nearest page that is divisible by 5
        while ((end % 5) != 0)
        {
            end++;
        }

        //Get the previous nearest page that is divisible by 5
        while ((start % 5) != 0)
        {
            start--;
        }
    }
    //The page is divisible by 5 so get the next 5 pages in the pagination
    else
    {
        end += 5;
    }
    //We are on the first page
    if (start == 0)
    {
        start++;
        end++;
    }
    //We are on the last page
    if (end == lastpage)
    {
        end = lastpage;
    } 

    //Post your pagination links below
    for (int i = start; i < end; i++)
    {
       //Your code here
    }

Pagination, Pagination links that are provided as part of the content of the response. For example, to use the built-in limit/offset pagination, you would do This pagination style accepts a single number page number in the request query parameters. Bootstrap Pagination. In this tutorial you will learn how to create pagination with Bootstrap. Creating Pagination with Bootstrap. Pagination is the process of organizing content by dividing it into separate pages.

You can't do this with just HTML. You'll have to use either PHP or javascript (or some other scripting language) to generate the links.

Pagination, Pagination allows your user to page back and forth through multiple pages of page for a blog or site, WordPress only shows 10 posts per page by default. a list of page numbers so the user can click on any one of the page links rather then� Highlight the current page with an .active class, and use the :hover selector to change the color of each page link when moving the mouse over them: Example .pagination a.active {

Pagination | Theme Developer Handbook, Limit the pagination link amount. Posted 2 years ago this could easily be extended to show any number of pages at any breakpoints. @media� Thus, we show the search engines that each page of pagination, is a part of the “View all” page so to speak. Google claims that. this is the most preferable for them method; users tend to view the entire category on one page at once (although this point is rather controversial and depends on the situation). Nuances

Limit the pagination link amount, Learn how to paginate Collection lists. Optionally, you can change the number of items you want to display per page. This component includes two link blocks: the previous and next buttons. sorting order; Limit the collection to show only 3 items; Copy the collection List; Select slide 2 and paste the list; Set start at to 4. If you only need to display simple "Next" and "Previous" links in your pagination view, you may use the simplePaginate method to perform a more efficient query. This is very useful for large datasets when you do not need to display a link for each page number when rendering your view:

Paginate Collection Lists, Pagination is the technique of spreading that content across multiple pages. create multiple pages (from a single template) that show a limited number of items. The information needed to query for those specific items (i.e. values for limit and Follow this step-by-step tutorial to add links to the previous/next page and the� Designing landing page with pagination controls. The landing page shows the database results with a pagination option. The following HTML has the embedded PHP script to display paginated results. It contains table rows created in a loop on iterating the data array. Below this table, it shows pagination links with previous next navigation.

Comments
  • Any particular programming language?
  • jQuery plugins are the first thing which I look for..I even saw this one..but I was looking for a server side approach. However seems like for now this is the best option available!
  • Thanks, mind marking as accepted if it helped? I'll keep looking for a server side paginator for C#
  • well I am waiting for someone to answer back with server side code!..I will accept your answer if no reply comes within a day or so :)..thanks for the help
  • seems like I am out of luck on finding a server side implementation!
  • thanks for marking as accepted, sorry I couldn't be more helpful :)
  • yes..you are correct..However I was trying to figure out logic for that..php, c#, java anything