JqPagination - How to specify the number of records per page?

I recently discussed with jqPagination , which is a jQuery pagination plugin. This is a really neat plugin, and I like how you can enter the page number. However, I have some difficulties because there is little documentation on it. Although this is probably a simple question, I was just curious if there is a way to specify how many posts will be displayed on the page. I am currently using pagination for a single entry per page, and this is controlled by jQuery selectors. However, I would like to indicate the number of numbers.

It might be easier to show some code that I have. I actually used the previous question stack overflow as the basis:

<div id="container"> <div id="div1">Any elements</div> <div id="div2">Any elements</div> <div id="div3">Any elements</div> ... and so on </div> 

And for jQuery:

 //Hide $("#container").children().not('#firstDiv').hide(); $('.pagination').jqPagination( { max_page : $('#container').children().length, paged : function(page) { //hide the other divs $('#container').children().hide(); //show the divs on the specified page $($('#container').children()[page - 1]).show(); 

Thus, in the above code, only one div will be displayed at a time, I would like to indicate how many elements / sections it can show.

Oh, and as a follow-up question, you can specify a specific div to display on a specific page, for example. if the footer only appears on the last page?

Update: completed

With the help of the creator, I was able to figure this out. I post my decision below in case someone can help someone else in the future. I have a user who selects the number of records per page in an XML file (not including the XML selector). If the page has fewer entries than the total, this displays pagination. I am sure there is a more efficient way, but I am satisfied with what I have. Here is the code below:

 /*--------------------------------------------------------------------------- Place this anywhere in your script. Automatically hide pagination. If there are less scenes per page than the total amount, then include pagination. ----------------------------------------------------------------------------*/ $(".pagination").hide(); var recordsPerPage = 5 var totalNumRecords = 20; if (recordsPerPage < totalNumRecords) { pagination(recordsPerPage, totalNumRecords); } //recordsPerPage is the number of items you want to display on each page //totalNumRecords is the total number of items that you have function pagination(recordsPerPage, totalNumRecords){ //Show the pagination controls $(".pagination").show(); //loop through all of the divs and hide them by default. for (var i=1; i <= totalNumRecords; i++) { $("#container").find("#div" + i).hide(); } //then only display the number of divs the user dictated for (var i = 1; i <= recordsPerPage; i++) { $("#container").find("#div" + i).show(); } //maxPages is the maximum amount of pages needed for pagination. (round up) var maxPages = Math.ceil(totalNumRecords/recordsPerPage); $('.pagination').jqPagination({ link_string : '/?page={page_number}', max_page : maxPages, paged : function(page) { //a new page has been requested //loop through all of the divs and hide them all. for (var i=1; i <= totalNumRecords; i++) { $("#container").find("#div" + i).hide(); } //Find the range of the records for the page: var recordsFrom = recordsPerPage * (page-1) + 1; var recordsTo = recordsPerPage * (page); //then display only the records on the specified page for (var i = recordsFrom; i <= recordsTo; i++) { $("#container").find("#div" + i).show(); } //scroll to the top of the page if the page is changed $("html, body").animate({ scrollTop: 0 }, "slow"); } }); } 

Thanks Ben!

+4
source share
1 answer

Do you have a range of div elements that are your pages, and only as many records are displayed inside these elements as you need? This way you can just show / hide each div page with a plugin.

I probably would have done in this situation.

0
source

All Articles