jquery - jqPagination - How do you specify the number of records per page? -
i've been toying around jqpagination, jquery plugin pagination. it's neat plugin , love how can type in page number. however, i'm having difficulty because there isn't documentation on it. although simple question, curious if there way specify how many records displayed per page. have pagination working 1 record per page, , that's controlled jquery selectors. i'd able specify how many numbers, however.
it might simpler show of code have. used previous stack overflow question basis:
<div id="container"> <div id="div1">any elements</div> <div id="div2">any elements</div> <div id="div3">any elements</div> ... , on </div> and jquery:
//hide $("#container").children().not('#firstdiv').hide(); $('.pagination').jqpagination( { max_page : $('#container').children().length, paged : function(page) { //hide other divs $('#container').children().hide(); //show divs on specified page $($('#container').children()[page - 1]).show(); so code above display 1 div @ time, specify how many elements/divs can show.
oh, , follow question, possible specify div appear on page, e.g. having footer appear on last page?
update: completed
with of creator able figure out. i'm posting solution below in case in else out in future. i'm having user select number of records per page in xml file (didn't include xml selector). if there less records per page there total, it'll display pagination. i'm sure there's more efficient way, i'm happy have. here's code below:
/*--------------------------------------------------------------------------- place anywhere in script. automatically hide pagination. if there less scenes per page total amount, include pagination. ----------------------------------------------------------------------------*/ $(".pagination").hide(); var recordsperpage = 5 var totalnumrecords = 20; if (recordsperpage < totalnumrecords) { pagination(recordsperpage, totalnumrecords); } //recordsperpage number of items want display on each page //totalnumrecords total number of items have function pagination(recordsperpage, totalnumrecords){ //show pagination controls $(".pagination").show(); //loop through of divs , hide them default. (var i=1; <= totalnumrecords; i++) { $("#container").find("#div" + i).hide(); } //then display number of divs user dictated (var = 1; <= recordsperpage; i++) { $("#container").find("#div" + i).show(); } //maxpages maximum amount of pages needed 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 of divs , hide them all. (var i=1; <= totalnumrecords; i++) { $("#container").find("#div" + i).hide(); } //find range of records page: var recordsfrom = recordsperpage * (page-1) + 1; var recordsto = recordsperpage * (page); //then display records on specified page (var = recordsfrom; <= recordsto; i++) { $("#container").find("#div" + i).show(); } //scroll top of page if page changed $("html, body").animate({ scrolltop: 0 }, "slow"); } }); } thanks ben!
could have range of div elements of pages, , within elements display many records desire? way can show / hide each page div using plugin.
that's i'd in situation.
Comments
Post a Comment