Hai i am generating page numbers based on currentpage and lastpage using jquery … Here is my function and as i am newbie i dont know how it can be done…
function generatePages(currentPage, LastPage) {
if (LastPage <= 5) {
var pages = '';
for(var i=1;i<=5;i++)
{
pages += "<a class='page-numbers' href='#'>" + i + "</a>"
}
$("#PagerDiv").append(pages);
}
if (LastPage > 5) {
var pages = '';
for (var i = 1; i <= 5; i++) {
pages += "<a class='page-numbers' href='#'>" + i + "</a>"
}
$("#PagerDiv").append(pages);
}
}
I want the result to be like this
If it is the first page
If it is in the middle,
If it is the last page,
I have the lastPage and currentPage values please help me out getting this…



First of all, you have to find a correct algorithm for what you want to do and the function you posted shows that you don’t have any.
The logic to implement could be:
currentPage - 2tocurrentPage + 2(limited to [1, lastPage])lastPageis not displayed, append “…lastPage“And additionally, you can add that:
currentPageis greater than 1, prepend “prev”currentPageis less thanlastPage, append “next”That’s for the theory. Now, for the implementation, just use jPaginate or another pagination plugin for jQuery instead…