jquery - Pagination button dynamically collapse if more than 10 pages , Bootstrap pagination -


im trying build custom pagination control div elements in parent div div_photos. under parent div ive more 500 child divs (which thumbnails) this.

<div id='div_photos'> <div class='tile'><img src='myurl'></div> <div class='tile'><img src='myurl'></div> <div class='tile'><img src='myurl'></div> ......... <div class='tile'><img src='myurl'></div> </div> 

so did pagination control below this

<div class="row"><div class="col-md-2 col-lg-2 col-sm-2">      <h3 class=" page-info" style="margin-top:14px;"></h3>      </div> <div class="col-md-10 col-lg-10 col-sm-10">       <div class="pagination pagination-large pull-right">             <ul class="pager"></ul>       </div> </div> </div> 

here jquery creation of paginator

var bindpaginator = function () {     var listelement = $('#div_photos');      var numitems = listelement.children().size();     var numpages = math.ceil(numitems / perpage);      $('.pager').data("curr", 0);     $('.pager').html('');     var curr = 0;     while (numpages > curr) {         $('<li><a href="javascript:;" class="page_link">' + (curr + 1) + '</a></li>').appendto('.pager');         curr++;     }      $('.pager .page_link:first').addclass('active');      listelement.children().css('display', 'none');     listelement.children().slice(0, perpage).css('display', 'block');      $('.pager li a').click(function () {         var index = $(this).parents('li:first').index();         $('.pager:first li').eq(index).find('a').css({ 'background-color': '#337ab7', 'color': 'white', 'font-weight': 'bold' });         $('.pager:first li').not(':eq(' + index.tostring() + ')').find('a').css({ 'background-color': 'white', 'color': '#337ab7', 'font-weight': 'normal' });         $('.pager:last li').eq(index).find('a').css({ 'background-color': '#337ab7', 'color': 'white', 'font-weight': 'bold' });         $('.pager:last li').not(':eq(' + index.tostring() + ')').find('a').css({ 'background-color': 'white', 'color': '#337ab7', 'font-weight': 'normal' });         var clickedpage = $(this).html().valueof() - 1;         goto(clickedpage, perpage);     });     showpagerinfo(0); }; function previous() {     var gotopage = parseint($('.pager').data("curr")) - 1;     if ($('.active').prev('.page_link').length == true) {         goto(gotopage);     } }  function next() {     gotopage = parseint($('.pager').data("curr")) + 1;     if ($('.active_page').next('.page_link').length == true) {         goto(gotopage);     } }  function goto(page) {      var startat = page * perpage,       endon = startat + perpage;     var listelement = $('#div_photos');     listelement.children().css('display', 'none').slice(startat, endon).css('display', 'block');     $('.pager').attr("curr", page);     showpagerinfo(page);  } function showpagerinfo(page) {  ..... } 

now showing 28 divs per page using global variable perpage. when there lots of thumnails number of pages lot , looks akward. instead of how can show paginator dynamically jquery datatable automatically adjusts based on total pages. page numbers after 10 gets shown ... , final few numbers show , when reaches 10 or 9 hidden numbers show

here how current setup looks enter image description here


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -